This is a simple question. I've decided in my program to keep a Initialize and a CleanUp proc that are called before and after the message loop, respectively. Now, normally, I would keep a lot of this stuff in the WM_CREATE and WM_DESTROY of the app window, but I like this other approach better.

I don't see anything wrong with it, but I never see examples like this so I have to wonder why not?


start: mov esi,offset start
and esi,0FFFF0000h
mov hInstance,esi
invoke GetCommandLine
mov CommandLine,eax

*** call Initialize
;allocate compatible DCs, open an ini file, allocate some memory
invoke CreateWindowEx,NULL,
addr szFrameClassName,
addr szFrameTitle,
mov Parent.hwnd,eax

xor eax,eax
invoke GetMessage, ADDR msg, eax, eax, eax
WM_messageloop: invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
xor eax,eax
invoke GetMessage, ADDR msg, eax, eax, eax
test eax,eax
jnz WM_messageloop
push eax
*** call CleanUp
;Release Memory DCs created in initialize,
'close out files, dealloc mem. Preserve eax for exitprocess
pop eax
invoke ExitProcess,eax

Posted on 2002-06-14 23:03:29 by chorus
chorus, imho the reason is to keep the window like an object onto itself - packing as much as you can into the WinProc. I hear this makes changes down the road easier, but I've used the same method you do above on small proggies with one window. :)
Posted on 2002-06-14 23:33:54 by bitRAKE

neat code:alright: I'm doing something similar right now.

I think I'll borrow some of what you are doing.

Posted on 2002-06-14 23:57:16 by ThoughtCriminal
bitRAKE, thanks for the info. Just wanted to make sure it was cool to do. Although my app isn't a single window, I just find it organizes things a little easier when I do it this way. Besides, there are a lot of things that aren't really specific to the app window so much as the app (like loading an ini file or something).

ThoughtCriminal, thanks :) Other than what the thread was about, it's a pretty standard message loop...

Bye all
Posted on 2002-06-15 00:23:00 by chorus
Thing like ini file loading and other "global" things should definitely
not go into WM_CREATE, but be done before the message-loop.
Init/Destroy that are specific to a window should go into the wndproc.
Posted on 2002-06-15 03:06:24 by f0dder