I am trying to make a simple application using OpenGL and WinAPI. I’ve got a dialog form where the scene - together with some windows controls (edit box, button and a check box) - is displayed. Everything seems fine but after my dialog loses focus (i.e, it hides under other window), the windows controls are not redrawed when the dialog gets its focus back again.
You can take a look and see what I mean : priv.ckp.pl/aero/window.png
I guess that the problem should be solved somewhere around WM_PAINT message. For the time being, here is what I do after getting WM_PAINT message :
case WM_PAINT: // should be called continuously
Render(); // just render GL scene (that’s where SwapBuffers() is called)
return TRUE;
I’d be thankful if you could help me with this one!
It’s a modal dialog box which is created with a call to DialogBox() just at the beggining of my WinMain().
Actually, I don’t render GUI at all. Once windows controls are created, I don’t do anything with them. It works ok until the window hides behind some other windows and becomes visible again.
To be honest, my problem disappears when I add calls to BeginPaint()/EndPaint() within WM_PAINT. Unfortunately when I do so, WM_PAINT is no longer being send to the event handler and my GL scene ‘freezes’. I don’t know where to put a call to Render() function.
A modal dialog blocks your code, it is single threaded, you get no app cycles or rendering while the dialog is running and you need to kill it after use, that’s why it’s called modal.
Basically while the dialog is in use your app is out to lunch, when you’re done with it you return to your app and the dialog is gone.
I think I got this the right way around, it’s been a while :-).
P.S. modal dialogs are bad news IMHO, best to use modeless but you need to handle the IPC (just a few shared variables but most windows books make a BIG deal out of what is actually pretty trivial code).
OK, I went for a modeless dialog. Everything works sweet except one thing… Look at the following code (main message loop).
MSG msg; // Message to the event handler
BOOL bRet; // Returned value
while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(g_WindowHandle) OR !IsDialogMessage(g_WindowHandle, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render(); // Render the scene
}
}
It seems that Render() is called very very seldom. In fact, the more actions I do (for example - moving my mouse) the more frequently Render() is called.