Page 1 of 1

Set Icon on Window (Correctly Sized)

Posted: Sun Jul 15, 2007 3:42 pm
by pdwyer
I spend about an hour on this. Not just to set the icon on the window but stuffing around with the built in loadImage() and SendMessage_() only to find that the 32x32 icon resized badly and looked awful. After hunting around on the forums reading about people resaving their icons so the 32x32 layer is taken out and PB reads the 16x16, and other people who tried resizeimage only to be dissapointed (with a known -to some- bug) I found some bits that eventually worked so I thought I'd put them all together here in a couple of lines.

I'm sure 99.99% of PBer's know this already but the new comers will lose a little hair getting here.

Code: Select all

    Window_Icon.l=LoadImage_(GetModuleHandle_(0),"D:\icons\MyIcon.ico",#IMAGE_ICON,16,16,#LR_LOADFROMFILE)
    SendMessage_(WindowID(#Window_0), #WM_SETICON, 0, Window_Icon)
If you set this to 32, 32 you'll get what I had for the inbuilt loadimage method... yuk :?

Posted: Thu Sep 20, 2007 7:40 am
by fizban
Thanks for the info. I'm a newcomer and I find this very useful. Still, is there a way of setting the window icon without having to load it from a file at runtime? I guess there is no way of setting it at design time (like the main window and executable icon), but maybe loading it from a resource file would be ok...

Posted: Thu Sep 20, 2007 8:02 am
by Mistrel
This is great! Thank you. :)
Thanks for the info. I'm a newcomer and I find this very useful. Still, is there a way of setting the window icon without having to load it from a file at runtime? I guess there is no way of setting it at design time (like the main window and executable icon), but maybe loading it from a resource file would be ok...
I think the simplest method would be to add the icon as a resource of your exe and load the image from there. You could also have it read from an icon in the directory and if none was found default to the exe icon.

Posted: Thu Sep 20, 2007 8:30 am
by Edwin Knoppert
That's because you didn't read the help about WM_SETICON..

You *should* set a big and small icon.
The big icon is shown in the ALT+TAB dialog for example.