I'm creating a drawing application that renders OpenGL when it gets a WM_SCROLL or WM_MOUSEMOVE. The thing is that there are a lot of mouse moves and I only need it to render a maximum of 60 frames per second. So I created a bool in my engine class called CanRender. so in my render() proc I do: if(!CanRender) { return; } CanRender = false;
Basically it prevents it from rendering more than 60 FPS.
I create the timer in WM_CREATE.
when I get a WM_TIMER I set CanRender to true.
I made it beep so I know the timer开发者_如何学运维 is running. As soon as I start scroling or moving the mouse, the beeping stops and I no longer see rendering. Why would it stop my timer? Also when I minimize the timer starts again then remaximize, it stops again.
Thanks
Message Pump:
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
creation:
case WM_CREATE:
//Set Window Title
SetWindowText(hWnd,engineGL.current.caption.c_str());
SetTimer(hWnd, // handle to main window
120, // timer identifier
17, // 60 fps interval
(TIMERPROC) NULL); // no timer callback
Why making it so complicated?
Drawing in windows application is usually done only in WM_PAINT message and triggered by RedrawWindow function. You can call RedrawWindow within WM_SCROLL and WM_MOUSEMOVE. Multiple calls to RedrawWindow (WM_PAINT messages) will be collapsed if your application can't keep up with drawing.
Also if you set OpenGL to synchronize with your monitors vertical retrace you will not exceed certain refresh rate.
As to your question... I guess there're many WM_SCROLL and WM_MOUSEMOVE messages. And those cannot be collapsed. So if you do your drawing inside them (which takes time), you block your message queue and WM_TIMER messages cannot be handled. Thus, you don't hear beeps.
精彩评论