Window not behaving correctly

Started by
2 comments, last by Harmony 22 years, 7 months ago
Hi guys, I recently moded my basic shell (creates an OpenGL window) so it is contained inside a class. However, now that I''ve done that (and it compiles error free) the window is not behaving properly. If I launch in Windowed mode I can not move the window around the desktop, or close it by pressing the widgets etc. The only way I can kill it is by binding a key to send a PostQuitMessage(0). Doing this successfully kills the window. The other problem it has started experiencing is that if I change modes (F1 toggles between windowed and fullscreen) the window crashes back to the desktop with no error messages (this occurs either switching from Windowed to fullscreen and vice versa. The same code when not in a class worked perfectly. I can even have an openGL scene running inside the window and it works fine. Just the actual window is not behaving itself. Help please help! The code is available on request if anyone wants a look. Thanks Ryan
-------------------------Cheers,Ry
Advertisement
I''d have to see the code to give you specific help, but it sounds like you''re not setting up a Windows message handler (WndProc function) correctly. The usual result from that is Window-oddness such as you describe, because the program ignores Windows events (such as move, resize, etc).

You have to be careful with WndProc functions in classes because of the way C++ method tables work...All methods in a class take an assumed first parameter (of ''this''), which screws up old C style callbacks like WndProc. Beware!
Ok... More Info...

Orginially I had the WinProc function external to the Class. One colleague suggested that this external WinProc might be the problem (as in the WinProc doesn''t know what window it is handling and ignores the messages)... I rewrote the general WinProc to determine what window was being effected and to then pass the message to a Full WinProc internal to the class.

I also moded my window to create a "this" pointer to itself and store it in the window userdata when the window is created....

The two WinProc functions follow (if you need more code I''ll post a link to the full source... thanks):

// WndProc --------------------------------------------------

LRESULT CALLBACK WndProc(
HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CMyClass *myClass = (CMyClass *)GetWindowLong(hWnd, GWL_USERDATA);
if (!myClass)
return DefWindowProc(hWnd, msg, wParam, lParam);
else
return myClass -> WinProc(msg, wParam, lParam);
}

// ----------------------------------------------------------


// CWillowGL::WinProc ---------------------------------------

LRESULT CALLBACK CWillowGL::WinProc(
UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
case WM_DESTROY:
{
willowGLLog.Output(" QUIT RECEIVED"); PostQuitMessage(0);
return 0;
}

case WM_ACTIVATE:
{
willowGLLog.Output(" ACTIVATE RECEIVED"); if (!HIWORD(wParam))
myClass.active = true;
else
myClass.active = false;
return 0;
}

case WM_SYSCOMMAND:
{
willowGLLog.Output(" SYSCOMMAND RECEIVED");
switch(wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
default:
return 0;
}
break;
}

case WM_SIZE:
{
willowGLLog.Output(" SIZE RECEIVED");
ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));
return 0;
}

case WM_KEYDOWN: {
willowGLLog.Output(" KEYDOWN RECEIVED");
keys[wParam] = true;
return 0;
}

case WM_KEYUP: {
willowGLLog.Output(" KEYUP RECEIVED");
keys[wParam] = false;
return 0;
}

default:
break;
}

return DefWindowProc(hWnd, msg, wParam, lParam);
}

// ----------------------------------------------------------


Thanks,
Ryan
-------------------------Cheers,Ry
I knew it would be simple! grrrrr....

Well I''ve worked it out. Thanks for your help.

My syscommand meesage handler was discarding all such messages, rather than just screensaver and monitor sleep messages.



Well thanks the maker that frustrating little episode is over...

Cheers,
Ryan
-------------------------Cheers,Ry

This topic is closed to new replies.

Advertisement