Setting icon @ runtime...
Blitz3D Forums/Blitz3D Programming/Setting icon @ runtime...
| ||
I'm just getting into userlibs so please forgive my ignorance on the subject. :) I want to set the icon on my window to my own - instead of the generic Windows window icon. I already have an icon that shows up on the exe file, etc., set through Protean, but I still get the generic one on my window. I'm sure this can be done through user32.dll but I can't decipher the MSDN Windows API reference well enough to figure out how to do it. Can someone please G1mm3 d4 C0d3z? :) Any help appreciated. M |
| ||
Well, after much frustration and self-teaching I managed to do this. Thought I'd share if anyone's interested. I used CallDLL and a custom DLL. I'm sure there's a way to make it a userlib and I plan to...but, for now, this works. [edit]Even better - now you can set the small icon (taskbar and UL corner of window) and the large icon (task switcher). You can call either, but SetIconLg does both. The icon has to be called "icon.ico" and placed in the exe directory - couldn't figure how to pass in the name with a bank...prob just being stupid.[/edit] seticon.h // Includes #include "windows.h" // SetIconSm extern "C"{ _declspec(dllexport) int _cdecl SetIconSm( int const *in,int in_size,int *out,int out_sz ); } // SetIconLg extern "C"{ _declspec(dllexport) int _cdecl SetIconLg( int const *in,int in_size,int *out,int out_sz ); } seticon.cpp // Set current window/taskbar icon int SetIconSm( int const *in,int in_size,int *out,int out_sz ) { HWND CurWin = GetActiveWindow(); HANDLE CurIcon = LoadImage(0, "icon.ico", IMAGE_ICON, SM_CXICON, SM_CYICON, LR_LOADFROMFILE); LRESULT result = SendMessage(CurWin, WM_SETICON, ICON_SMALL, (LPARAM)CurIcon); return(1); } // Set current taskswitcher icon int SetIconLg( int const *in,int in_size,int *out,int out_sz ) { HWND CurWin = GetActiveWindow(); HANDLE CurIcon = LoadImage(0, "icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE); LRESULT result = SendMessage(CurWin, WM_SETICON, ICON_BIG, (LPARAM)CurIcon); return(1); } BBfile: AppTitle("Test Window") CallDLL("seticon", "SetIconLg") WaitKey() End() BTW, this is based on the source from the DLL demo on BC.com. Now, to convert it to a generic userlib. M |
| ||
cheers! |
| ||
or you could just do it freom a program after compiling |
| ||
Actually, you can't...if you mean using ResHack or similar. Blitz doesn't include an icon for the window/taskbar in the executable, do you can't modify it. That's why you have to load and set it at runtime. M |
| ||
My IDE will add its own icon for you when you compile, its in BETA version, but it does compile |
| ||
Yeah. I know you can set the icon for the EXE file itself - i.e. as it appears in Windows Explorer or on the Desktop. Protean, which I use, does this as well. When you run the program, though, the icon in the UL corner of the window and on the taskbar and on the task switcher (alt-tab) is the default window icon - is it not? This is the icon I'm talking about. ResHack, most IDEs, etc. can set the EXE icon, but not the runtime icon - as far as I know. Please correct me if I'm wrong though. M |
| ||
O I see what you mean and I agree it would be useful if you could do it another way |
| ||
G1mm3 d4 C0d3z Are you referring to the incident I think you're referring to? :D |