PDA

View Full Version : OpenGL + Windows controls



Orzech
01-04-2006, 07:38 AM
Hello!

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! :)

dorbie
01-04-2006, 09:37 AM
You say dialog, but it doesn't look like a standard dialog.

Is the GUI drawn in your render callback or is it a windows modeless dialog?

This is probably a simple drawing error if you render the GUI.

If it's a modeless dialog then you probably need to handle the dialog's events correctly, realize it's a separarte thread.

Orzech
01-04-2006, 10:43 AM
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. :p 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.

Maybe I should simply try a modeless dialog?

Thank you

01-04-2006, 10:51 AM
When you get the focus back try calling:
Invalidate();
UpdateWindow();

Orzech
01-04-2006, 11:14 AM
I came up with the following solution. I've made a modeless dialog so I can have a control on a message loop.

</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(g_WindowHandle)

Orzech
01-04-2006, 11:24 AM
Heh.

I came up with the following solution. I've made a modeless dialog so I can have a control on a message loop.

</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(g_WindowHandle)

Orzech
01-04-2006, 11:27 AM
:F

Sorry for the mess. Something has screwed up.

I came up with the following solution. I've made a modeless dialog so I can have a control on a message loop.

</font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> while (g_WindowHandle && (bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(g_WindowHandle)

01-04-2006, 11:47 AM
Don't use the double-pipe OR operator in the code block ;)

There should be a warning somewhere on this site :D

Cheers.

dorbie
01-04-2006, 12:59 PM
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).

Orzech
01-04-2006, 02:02 PM
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 &amp;&amp; (bRet = GetMessage(&amp;msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(g_WindowHandle) OR !IsDialogMessage(g_WindowHandle, &amp;msg))
{
TranslateMessage(&amp;msg);
DispatchMessage(&amp;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.

Do you have an idea what's goind on? ;)

Thank you