Sign in to follow this  
lincsimp

Message loop probs

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this