Message loop probs

Started by
4 comments, last by Endurion 19 years ago
Hi Well basically I've got a small opengl demo from nehe to render to a .NET control. I've got rid of this:

	if (!(hWnd=CreateWindowEx(dwExStyle,"OpenGL",title,dwStyle |WS_CLIPSIBLINGS |WS_CLIPCHILDREN,0, 0,	WindowRect.right-WindowRect.left,	WindowRect.bottom-WindowRect.top,NULL,NULL,hInstance,NULL)))		


and replaced it with this: hWnd = (HWND)hwnd_of_control and with a couple of other mods it all works fine except that no messages get to the programme. I'm pretty new to c++, so whats going wrong?

if (!CreateGLWindow("NeHe's Textures, Lighting & Keyboard Tutorial",640,480,16,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	while(!done)									// Loop That Runs While done=FALSE
	{
      MessageBox(NULL,"this message box never shows.","ERROR",MB_OK | MB_ICONINFORMATION);

		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if ((active && !DrawGLScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;							// ESC or DrawGLScene Signalled A Quit
			}
else
{
...
}


If anyones interested here it is: http://matix.co.uk/OpenGL.zip Thanks a lot
Advertisement
Well, since you provide your own HWND there is NO connection to the supplied WindowProc anymore.

In that case you could get away with subclassing that window: Use SetWindowLong with GWL_WNDPROC and set your WindowProc to the HWND. This will route the messages to your windowproc. If you want to pass on the message you have to call CallWindowProc with the old wndproc value that SetWindowLong returned.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks a lot!
So at the top of winmain i put:

LONG oldval = SetWindowlong(hWnd, GWL_WNDPROC, ??);

What do I put for dwNewLong?
How can I set WndProc to the hWnd?

Cheers
Insert your WindowProc there (be sure it's the right type) and cast it to WNDPROC.

Looks like this:

WNDPROC pOldWndProc = SetWindowLong( hWnd, GWL_WNDPROC, (WNDPROC)WindowProc );

It'll probably issue some warning about data size truncation if you have 64-bit-awareness enabled. This can't be helped with that function. You can ignore that warning safely here.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks, Ok I put this in WinMain:

LONG pOldWndProc = SetWindowLong( hWnd, GWL_WNDPROC, (LONG)WndProc );

It still seems though that no messages are being recieved. What should I do?

Thanks again
Hmm, could you put the updates project up? I'll take a look then.

How do you check for incoming messages? Logging? Setting a breakpoint?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement