OpenGL + Windows controls

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

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.

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. :stuck_out_tongue: 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

When you get the focus back try calling:
Invalidate();
UpdateWindow();

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)

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)

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

Don’t use the double-pipe OR operator in the code block :wink:

There should be a warning somewhere on this site :smiley:

Cheers.

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.

Do you have an idea what’s goind on? :wink:

Thank you