My application currently uses a timer to display an animation. I would now like to make the application use a Game loop instead of a timer. The application is displayed using a dialog box. This means that the message processing loop is hidden from me. Where can I put the loop which displays my animation? I tried putting it in WM_INITIALIZE but once the loop starts the dialog is never displayed.
Posted on 2004-07-31 15:12:27 by DeX
Use CreateDialogParam to create the dialog. This function returns immediately after creating it. Be sure to give the dialog the WS_VISIBLE style in the dialog template. Call IsDialogMessage prior to calling DispatchMessage to have Windows handle keys used for navigation in the dialog.
Posted on 2004-07-31 15:29:11 by Sephiroth3
Ok I almost got your suggestion to work.

The main problem now is that the program won't shut down properly. Here is some of my code:

First I use CreateDialogParam to make the dialog. Then I send the window handle returned to my loop procedure called WinMain.

invoke CreateDialogParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL
invoke WinMain,eax

The WinMain procedure looks like this:

WinMain proc hWin:HWND


.while TRUE
invoke PeekMessage,addr msg,NULL,0,0,PM_REMOVE
.if (eax != 0)
; Break if it was the quit messge
mov eax, msg.message
.if eax == WM_QUIT
jmp shutdown

; Translate and Dispatch the message
invoke IsDialogMessage,hWin,addr msg
.if (eax == 0)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg

;Display the animation
invoke GameMain,hWin
;Destroy Objects
invoke ShutDown,hWin

WinMain endp

The Shutdown procedure simply destroys a bunch of objects I have created.

The problem is that I am unable to shutdown the program. The WM_QUIT message never seems to be detected. Any idea why this is?
Posted on 2004-07-31 17:18:11 by DeX
Hey DeX

Try replacing...

mov eax, msg.message
.if eax == WM_QUIT
jmp shutdown


invoke GetMessage, addr msg, NULL, 0, 0
test eax, eax
jz shutdown

and change PM_REMOVE to PM_NOREMOVE.

I tried the same thing without success a while ago and still don't understand why it didn't work, but the above changes should hopefully get the loop working.
If anyone can enlighten us with an answer, it would be appreciated.

Hope this helps

P.S: I assume your using PostQuitMessage to send the WM_QUIT message.
Posted on 2004-07-31 20:58:44 by Maelstrom
No I'm not using PostQuitMessage. Where should I use it?

I will try your suggestions anyway and see if they work.


Ok your suggestions do work :). I invoked PostQuitMessage in response to the WM_CLOSE message and I made those other code changes and now it works fine. But I really don't understand why. How is using GetMessage and PM_NOREMOVE different from the method I used before?

If anyone has any idea please let us know :).
Posted on 2004-08-01 11:00:46 by DeX
The fact is, that it had worked already as soon as you added the call to PostQuitMessage. Nothing mysterious about that :P
Posted on 2004-08-01 18:41:26 by Sephiroth3
I had thought of that already and I tried using PostQuitMessage with my old code and it didn't work....

But now that I look again at my code I see something wrong. I had changed

.if eax == WM_QUIT


.if eax == WM_CLOSE

while experimenting with different methods. Anyway it seems I forgot to change it back to WM_QUIT which is why it didn't work even after adding PostQuitMessage :rolleyes:.

Thanks guys.
Posted on 2004-08-01 19:16:47 by DeX
Looks like I'll have to try and find the code I had problems with, sounds like *I* forgot to use PostQuitMessage :sweat:
Well it was a long time ago :grin:
Posted on 2004-08-03 00:36:06 by Maelstrom