gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

OffTopic > GCC + Win32 API lib 3.14 = Window + Icon! :?D [solved]

#155878 - silent_code - Sun May 04, 2008 11:47 pm

hi,

can anyone give me a hint how to make the window icon show up when using the win32 api (3.14) with gcc (3.5)? i have tried almost everything and it won't show up!

i did it the ms vs style, that works with vs (it's quite well documented), but it won't work with gcc (i know it's not compiler related ;^D ).

what can i do? has anyone a working example? any URLs?

thanks in advance!


Last edited by silent_code on Tue May 06, 2008 12:21 am; edited 2 times in total

#155890 - kusma - Mon May 05, 2008 9:58 am

Uhm, can't you just fill out the hIcon-member of your WNDCLASS-structure (or hIcon and hIconSm if you're using WNDCLASSEX) with a handle to a valid icon (loaded with LoadIcon or LoadImage api functions)?

#155896 - silent_code - Mon May 05, 2008 11:18 am

thanks, but i already tried that!

it will always give me that little "window" icon, although the correct icon is displayed in the task bar! X^|
i tried it all...
Code:
//   windowClassEx.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
//   windowClassEx.hIcon         = LoadIcon(NULL, MAKEINTRESOURCE(IDR_ICON));
//   windowClassEx.hIcon         = (HICON__*)LoadImage(hInstance, MAKEINTRESOURCE(IDR_ICON), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
//   windowClassEx.hIcon         = LoadIcon(hInstance, m_ClassName);
Code:
//   windowClassEx.hIconSm      = LoadIcon(NULL, IDI_APPLICATION);
//   windowClassEx.hIconSm      = LoadIcon(NULL, MAKEINTRESOURCE(IDR_ICON));
//   windowClassEx.hIconSm      = (HICON__*)LoadImage(hInstance, MAKEINTRESOURCE(IDR_ICON), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);

.rc:
Code:
//IDR_ICON   ICON MOVEABLE PURE LOADONCALL DISCARDABLE   "icon.ico"
128 ICON DISCARDABLE "icon.ico"

.h:
Code:
#define IDR_ICON 128

that makes me a sad panda. :^C

ps: OS is XP32SP2

#155907 - kusma - Mon May 05, 2008 2:47 pm

Check that windowClassEx.hIcon and windowClassEx.hIconSm isn't NULL. I tried at home with my mingw-install right after posting, and it worked just fine. The only difference from what I can see here, was that I loaded the icon from file, not resource (just by using the LR_LOADFROMFILE-flag), as I didn't want to find out how to include resources under mingw ;)

#155910 - silent_code - Mon May 05, 2008 4:12 pm

including resources is easy. write a .rc file, compile it with windres and link it.

well, i'll try loading the damn thing from file, but i really don't want to ship a seperate .ico file when the icon is *obviously* in the .exe. i though i could get around this somehow. :^(

anyway, thanks for the tip. :^D

#155914 - kusma - Mon May 05, 2008 4:43 pm

silent_code wrote:
including resources is easy. write a .rc file, compile it with windres and link it.

I'll give it a go when I get home.

silent_code wrote:
well, i'll try loading the damn thing from file, but i really don't want to ship a seperate .ico file when the icon is *obviously* in the .exe.

Of course, my suggestion was to check that it's non-null, not to put it in a separate file. There's a whole lot of things that can go wrong with the icons, I went through some of the same shit recently ;).

#155922 - kusma - Mon May 05, 2008 7:55 pm

just tried, and everything works just fine here.

Here's my source code:
test.cpp:
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   WNDCLASSEX wcex;
   wcex.cbSize        = sizeof(WNDCLASSEX);
   wcex.style         = CS_HREDRAW | CS_VREDRAW;
   wcex.lpfnWndProc   = DefWindowProc;
   wcex.cbClsExtra    = 0;
   wcex.cbWndExtra    = 0;
   wcex.hInstance     = hInstance;
   wcex.hIcon         = (HICON)LoadImage(wcex.hInstance, MAKEINTRESOURCE(128), IMAGE_ICON, GetSystemMetrics(SM_CXICON),   GetSystemMetrics(SM_CXICON),   0);
   wcex.hIconSm       = (HICON)LoadImage(wcex.hInstance, MAKEINTRESOURCE(128), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON), 0);
   wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wcex.hbrBackground = (HBRUSH)COLOR_WINDOW;
   wcex.lpszMenuName  = NULL;
   wcex.lpszClassName = "something";
   RegisterClassEx(&wcex);
   
   HWND hWnd = CreateWindow("something", "Icon test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   
   MSG msg;
   while (GetMessage(&msg, NULL, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
   return (int) msg.wParam;
}


test.rc:
Code:
128 ICON DISCARDABLE "test.ico"


compiled like this:
Code:
windres.exe test.rc test.o
g++ test.cpp test.o && ./a.exe

#155936 - silent_code - Mon May 05, 2008 11:11 pm

oh, kusma, dear kusma, what would i do without you? if there were a third toystory movie, i'd most likely watch it, but...

thanks, i'll check it out asap! :^)

EDIT:

that did it!!!!

i'm going to behave like a man an say: THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU, THANK YOU!!!!

(does that count as ascii art?)

no really, thanks! :^)

btw: nice minimal win32 program :^D
thanks, again. ;^)

EDIT2: wooooh, this is soooo cooool! <hopps like a bunny - in a *square*> (is that even healthy?)

for solving this quest, i would give you 50000 xp and 500 gil if i had any of it! ... and a mighty rat-flail on top of it! ;^D

#155939 - kusma - Mon May 05, 2008 11:48 pm

You're welcome, I'm glad it helped :)
Just out of curiosity, what was really wrong?

#155940 - silent_code - Tue May 06, 2008 12:03 am

i'm about to find out. come what may come, i will have to rewrite the whole window handling subsystem.
i just needed a proof of concept. you code compiled and ran right away, so i have an example that i will use later. i really don't have a clue what was wrong there. as i said, the whole window handlig is bogus.
honestly, i have thought of some really "spacey" ways to get that damn icon loaded... good i ask here in the forum, instead of wasting time (again). ;^)

as soon as i find out what was wrong, i'll post it here. :^D

it's 1:00 am, i think i'll be going to sleep... damn, i wanted to record that video for yellowstar... the whole damn thing (multisampling not working because of - guess what?- wndwHndl'g - in one project the setup works, in another it doesn't [not the same code, just the setup. it works in yet another proof of concept]) cost me so much time today. :^C

@ yellowstar: sorry!

#155942 - silent_code - Tue May 06, 2008 12:20 am

NOTE: this post is intentionally seterate. (is that even propper english?)

just tested it in my code base and guess what? it works!
you actually had a typo in (taking x-metrics for y-metrics). ;^D

well, looks like the only real difference is that i used an (HICON__*) cast and LR_DEFAULTCOLOR as the last parameter (instead of 0)...

now, the crazy thing is, that i uncommented the old line, that is simmilar to yours and GUESS WHAT? it worked, too!

Code:
windowClassEx.hIcon         = (HICON__*)LoadImage(hInstance, MAKEINTRESOURCE(IDR_ICON), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);


THIS IS CRAZY!!!! TOTALLY NUTS!!!! what the heck?

in the life cycle of the code base, i went from win32 3.10 (or even older, can't remember) to 3.14, but it NEVER worked! never ever! as i said, i just uncommented a line that DID NOT work, but this time it worked! ????

console programming is SOOOO (<---------------->) much easier.

if kusma or anybody else has nothing to add, this thread can be closed (just wait a day, please. thank you.)

#155944 - kusma - Tue May 06, 2008 12:32 am

silent_code wrote:
you actually had a typo in (taking x-metrics for y-metrics). ;^D

Ah! Thanks a lot, I didn't catch that one. It's taken from my current boilerplate-code, and it's nice to get that corrected so I don't have to back-patch lots of small things later ;)

#155947 - silent_code - Tue May 06, 2008 12:46 am

you're welcome. one hand washes the other, right? ;^D
make also sure you use that define for the last parameter. :^)

#156132 - tepples - Wed May 07, 2008 2:06 am

silent_code wrote:
EDIT2: wooooh, this is soooo cooool! <hopps like a bunny - in a *square*> (is that even healthy?)

It depends on exactly how you're hopping. Some methods are harder on joints than others. Could you videotape yourself, bring the video into the computer, and then put it on a video sharing site so that all the I Am Not A Doctors can give you suggestions?

Quote:
for solving this quest, i would give you 50000 xp and 500 gil if i had any of it! ... and a mighty rat-flail on top of it! ;^D

Do you play Animal Crossing: Wild World? I've heard that some people take bells instead of gil.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#156177 - silent_code - Wed May 07, 2008 12:56 pm

hahahaha. :^D

no, i wasn't really hopping like a bunny. it was very close to what i felt like, though.

well, i don't play AC, haven't ever, but i play resident evil (offline on my ngc)... bullets anyone? or paper mario... or viewtiful joe or... metroid (samus doesn't even *have* bullest... i bet she could spare and energy tank, though. )

#156765 - silent_code - Tue May 13, 2008 8:56 pm

so, it looks like it's working now... without further changes. i just wonder what the heck happened? i haven't touched a line of code (even with "(HICON__*)")! damn.

what the heck? does anyone have an idea what might have caused that? as i said before, i didn't change anything (code, .rc, .ico, nothing!)

but i'm glad it finally works in all of my projects! ;^)
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.