Hi all, I''m using VB but I''m hoping C/C++/Windows coders will be the ones to help me out here. I''m writing a game engine using DirectX and VB. I decided to write the windows code and message loop myself (instead of using VB Forms). I used some of the Windows API functions I''d learned while using C++ (I''m still a newbie in C++). And guess what, it all worked
Here''s the code for my message loop:
Private Sub iWindows_MessageLoop(DoProcessing As iMessageLoop)
Dim Message As MSG
Do While GetMessage(Message, 0, 0, 0)
DispatchMessage Message
DoProcessing.DoProcessing
Loop
End Sub
The only problem was, that the GetMessage function waits for a message to be put in the queue. It''s not a good idea in a demanding program such as a 3D game to spend most of your processing time waiting for a windows message. So I rewrote the function to be more aggressive, with PeekEvents like this:
Private Sub iWindows_MessageLoop(DoProcessing As iMessageLoop)
Dim Message As MSG
Do
If PeekMessage(Message, 0, 0, 0, PM_REMOVE) Then
If (Message.Message = WM_QUIT) Then
Exit Do
Else
DispatchMessage Message
End If
End If
DoProcessing.DoProcessing
Loop
End Sub
Which also worked, and was alot more efficient! I was really happy... until I switched the focus to another window
At which point it seemed to freeze up my whole computer to the point where I could do nothing but reboot it. I tried it again, just to see if it was a fluke, but it wasn''t. This is bad because I''ve only seen Windows XP crash once in 8 months I''ve had it
So... what am I doing wrong? I know that adding DoEvents will get rid of the problem, but doesn''t that defy the purpose of using PeekEvents? Any help will be much appreciated. Thanks