I guess this is a two parter. I have been slowly going through my code and optimizing here
and there just for fun and came up with this for the main message loop. Since I have not
seen another here with quite this style I thought I would post it.

Note: the first time through the msg structure wont contain any valid handles so Windows
ignores it without error in TranslateMessage and DispatchMessage. As there is only one
jump to consider, it should out perform other looping mechanisms. :alright:

local msg :MSG
invoke CreateWindowEx, 0, ...

invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
invoke GetMessage, addr msg, NULL, 0, 0
dec eax
jns MsgLoop

mov eax, msg.wParam

Second part is rather odd. While shuffling around some code in the main proc (looks like this).

invoke GetModuleHandle, NULL
mov hInstance, eax
mov wc.hInstance, eax
invoke LoadIcon, hInstance, idRESOURCE_APPLICATION_ICON
mov hIcon, eax
mov wc.hIcon, eax

I accidentally moved LoadIcon *before* GetModuleHandle like so:

invoke LoadIcon, hInstance, idRESOURCE_APPLICATION_ICON
mov hIcon, eax
mov wc.hIcon, eax
invoke GetModuleHandle, NULL
mov hInstance, eax
mov wc.hInstance, eax

I initialize hInstance in the data section to be zero. Funny thing is, is that the call
worked just not as expected. I have idRESOURCE_APPLICATION_ICON set at 1000
and when hInstance is 0, I get a new icon (exit application icon). Looks like an
open door with an arrow pointing to it. So I found a new icon rather by accident.

Question is, is where is this icon being loaded from? And, if it is a known resource,
are there other "freebie" resources I could use as well?
Posted on 2002-07-21 21:24:52 by Graebel
This door wouldn't happen to be blue, would it?

You're probably loading resources off one of the OS dll components. Anyone wanna guess which one loads first (hinstance=0)?
Posted on 2002-07-21 22:28:14 by Ernie
Actually ya, its a red arrow pointing to an open sky blue door.
Hmm its interesting that its being allowed at all imo. I was
mainly just curious. Its too bad it cant be counted on always
being there. Free resources are cool.

At least on my 98 box, its worked on 4 compiles and 3 reboots.
So whatever it is, on this machine its always loaded first.
Posted on 2002-07-21 22:43:25 by Graebel
1) personally, I use this for my message loop:

invoke CreateWindowEx,NULL,...
mov hSomeWindow,eax
jmp @@Start
@@MessageLoop: invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
@@Start: xor eax,eax
invoke GetMessage,addr msg,eax,eax,eax
test eax,eax
jnz @@MessageLoop
invoke ExitProcess,eax

couple of reasons:
--test eax,eax doesn't destroy eax. This is handy cause I can pass it straight to ExitProcess instead of using msg.wParam (which is going to be zero anyways, cause I never call PostQuitMessage with anything but zero)
--I don't use a WinMain proc, so there's no ret instruction
--the xor eax,eax means I can push a bunch registers for a little cheaper than pushing constants (saves me 1 byte) :)
--I guess the jmp @@Start can really be left out, but hey, I just saved myself a byte, so I can afford it :D

2) The LoadIcon API still works with hInstance == NULL. MSDN says it'll just load a "standard" icon. I'm not sure where these are coming from, but the LoadIcon API comes from user32.dll so that'd be my first guess. However, none of the values listed at MSDN match the icon you describe, so it's quite possible it isn't a guarantee that that icon will be on all machines and all platforms.

Posted on 2002-07-23 14:38:14 by chorus