I am using Windows XP 32-bit, VC++ 2008 with OpenGL and the Windows API.

When I run my program, it seems to work fine, but whenever I click anywhere on the title bar of the window, the program exits. I have no idea where to start to look for the source of this so I cannot post source code at the moment. What could be the cause of this ?

Recommended Answers

All 9 Replies

Look for any handlers you have in your app relative to non-client area such as WM_NCLBUTTONDOWN or UP.

I don't have any of those, do you mean the events I handle in WndProc ?
I have these handled:
WM_ACTIVATE
WM_SYSCOMMAND
WM_CLOSE
WM_KEYDOWN
WM_CHAR
WM_KEYUP
WM_SIZE

It could be the what happens in WM_SIZE mabey?

This is what I have there:

glViewport (0, 0, LOWORD(lParam), HIWORD(lParam));

	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();

	gluPerspective (45.0f, (float)LOWORD(lParam)/(float)HIWORD(lParam), 0.1f, 100.0f);

	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();

I'm not familiar with OpenGL, but I agree with taking a closer look at WM_SIZE as clicking in the non-client area and moving the mouse does trigger WM_SIZE. Most debuggers will allow you to trap an event based on the contents of register or memory, so catch the entry to WM_SIZE and see if it is triggered and single step to follow its path.

Okay, I looked in my message handler, and when I click on the titlebar, the message '32' is sent to my program, this means WM_SETCURSOR. This is the only message that it sends me before it closes. My handler doesn't handle this so it gets passed to DefWindowProc. What does WM_SETCURSOR mean? I might try and make it handle that message and see what happens.

EDIT: I made it handle that message, and the same thing happens.

Sounds like one of these incidious errors and without seeing your entire code, I'm confounded to finding a solution

I will attach my code, as it is quite large.

I looked and it seems that I overlooked a part of my code. When I click on anywhere in the title bar (not the exit button) it seems that the WM_CLOSE message is being sent to my program for some reason.

>> it seems that the WM_CLOSE message is being sent to my program for some reason.

Your WM_SYSCOMMAND handling needs fixing. As of now, any WM_SYSCOMMAND with wParam not equal to SC_SCREENSAVE or SC_MONITORPOWER falls through to the next case, ending up in a PostQuitMessage (0); call.

Thank you for your help guys. It was the WM_SYSCOMMAND that mitrmkar pointed out that was the problem. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.