Archived

This topic is now archived and is closed to further replies.

bretto

Missing Messages

Recommended Posts

I''m trying create my own base code for OpenGL so I don''t have to use Nehes. I''ve made an OpenGL window class which creates an OpenGL window depending on the parameters given to it. It is based roughly on NeHes base code but placed within a Class. There is one main problem with the code. Any messages from the created window will not be sent to the WINPROC function. That means it does not resize or close. The only time the WM_DESTROY or WM_CLOSE message is given is when the program is aborted by pressing ctrl-alt-del. When any of these two messages are given the cOGL.killwindow() function is called, unloading the window. For some reason this function gets called thousands of times and causes and stack overflow error, which I have fixed by only letting the function run if the window hasn''t already been destroyed, but I don''t understand why the WM_DESTROY or CLOSE messages were sent so many times. Has it something to do with ctrl-alt-del , endtask? I was wondering if someone could have a look at my code and see if there are any errors that I overlooked. I think it may have something to do with the window being created in my OGL object while the WndProc is not in an object. If I do place WndProc in the same object I get errors that I don''t know how to fix. I would be happy to send someone all the code if they want to take a closer look, it''s just to big to post all of it here. Thanks Brett S. half of the CreateGLWindow function that creates the window From OGL.cpp:
  
bool COGL::CreateGLWindow(glSettings Settings, HINSTANCE hInstance)
{
	
	WNDCLASSEX	wc;			// Windows class structure

	RECT		WindowRect;	// The Windows Rect

	DWORD		dwExStyle;	// Window Extended Style

	DWORD		dwStyle;	// Window Style

	
	///////////////////////////////////////////////////

	// Setup Window

	///////////////////////////////////////////////////

	
	// Setup Window Class

	m_hInstance			= hInstance;
	wc.cbSize			= sizeof(WNDCLASSEX);
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc		= WndProc;
	wc.cbClsExtra		= 0;
	wc.cbWndExtra		= 0;
	wc.hInstance		= m_hInstance;
	wc.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground	= NULL;
	wc.lpszMenuName		= NULL;
	wc.lpszClassName	= "OpenGL";
	wc.hIconSm			= LoadIcon(NULL, IDI_APPLICATION);

	// Register Class

	if (!RegisterClassEx(&wc))
	{
		MessageBox(0, "Failed to register the window class", "Error" , MB_OK | MB_ICONERROR);
		return false;
	}
	
	// If Fullscreen mode see if it can be initaited

	if (Settings.bFullScreen)
		if (!ChangeResolution(Settings))
		{
			MessageBox(0, "Can''t switch resolution. Using Windowed Mode", "Error", MB_OK | MB_ICONERROR);
			// Failed

			Settings.bFullScreen = false;
		}
	
	// Setup for Fullscreen or Windowed mode

	if (Settings.bFullScreen)
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style

		dwStyle=WS_POPUP;										// Windows Style

		ShowCursor(FALSE);										// Hide Mouse Pointer

	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style

		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style

	}
	
	// Setup Windows RECT

	WindowRect.left =	(long) 0;
	WindowRect.right =	(long) Settings.wWindowWidth;
	WindowRect.top =	(long) 0;
	WindowRect.bottom = (long) Settings.wWindowHeight;
	
	// Adjust the Windows RECT Depending on Full or windowed mode

	AdjustWindowRectEx(&WindowRect, dwExStyle, FALSE, dwStyle);
	
	// Create Window

	m_hWnd = CreateWindowEx(
							dwExStyle,
							"OpenGL",
							"glWindow",
							dwStyle |
							WS_CLIPCHILDREN |
							WS_CLIPSIBLINGS,
							0, 0,
							WindowRect.right-WindowRect.left,
							WindowRect.bottom-WindowRect.top,
							NULL,
							NULL,
							m_hInstance,
							NULL);

	if (!m_hWnd)
	{
		MessageBox(0, "Window creation error", "Error", MB_OK | MB_ICONERROR);
		
		// If full screen reset

		if (Settings.bFullScreen)
		{
			ChangeDisplaySettings(NULL,0);
			ShowCursor(TRUE);
		}
		return FALSE;
	}
// Set up pixel get redering context etc

.
.
.
.
.
  
  
The WndProc from main.ccp:

LRESULT CALLBACK WndProc(HWND	hWnd,
						 UINT	message,
						 WPARAM	wParam,
						 LPARAM	lParam)
{
	////////////////////////////////////////////////////////////////////////

	// Window procedure

	////////////////////////////////////////////////////////////////////////


	switch (message)
	{
		case WM_DESTROY:
		case WM_CLOSE:
			ShowCursor(TRUE);							// Show mouse

			cOGL.KillGLWindow(GlobalSettings);			// Shutdown OpenGL

			PostQuitMessage(0);							// Quit the program

			break;
		
		case WM_SYSCOMMAND:						// Intercept System Commands

			switch (wParam)						// Check System Calls

			{
				case SC_SCREENSAVE:				// Screensaver Trying To Start?

				case SC_MONITORPOWER:			// Monitor Trying To Enter Powersave?

				return 0;						// Prevent From Happening

			}
			break;							
		
		case WM_SIZE:
			// Notify COGL of the new window size

			GlobalSettings.wWindowHeight = HIWORD(lParam);
			GlobalSettings.wWindowWidth = LOWORD(lParam);
			cOGL.Resize(GlobalSettings);
			break;

		default:
			return (DefWindowProc(hWnd, message, wParam, lParam));
	}
	return (0);
}
  

Share this post


Link to post
Share on other sites
        
case WM_DESTROY:
case WM_CLOSE:
ShowCursor(TRUE); // Show mouse

cOGL.KillGLWindow(GlobalSettings); // Shutdown OpenGL

PostQuitMessage(0); // Quit the program

break;


try changing that to:

      
case WM_CLOSE:
//decide wether you want to close the window

DestroyWindow(hWnd);
break;
case WM_DESTROY:
ShowCursor(TRUE); // Show mouse

cOGL.KillGLWindow(GlobalSettings); // Shutdown OpenGL

PostQuitMessage(0); // Quit the program

break;


could you show us the code for KillGLWindow()?

If you are calling DestroyWindow() there, you'll be looping between the WM_DESTROY and the KillGLWindow() part.

You don't normally need to intercept WM_CLOSE or call DestroyWindow() yourself, only if you want to show a messagebox before closing or something. The DefWindowProc() calls DestroyWindow() automatically in WM_CLOSE, so you might aswell leave the WM_CLOSE part out, and don't call DestroyWindow().


Edited by - kvh on June 8, 2001 7:29:03 AM

Share this post


Link to post
Share on other sites
thanks the code worked wonderfuly and stop the KillWindow function being called thousands of times.

But i still can't get the window to resize or exit when either the x button is pressed or Alt-f4 is pressed. The buttons do move when pressed, and the double arrow apears when placed on the window's border but the message does not turn up in the winproc.

Edited by - bretto on June 8, 2001 7:54:22 AM

Share this post


Link to post
Share on other sites