Help with my WndProc
Hello,
I am rewriting my first game for OpenGL. I am trying to wrap the windows stuff in a class. I have solved the problem of the WNDPROC in a class (thanks to these forums). Now in my WndProc, after my window is created and displayed, I receive WM_WINDOWPOSCHANGING messages one after another and it doesn't stop untill my window seemingly magically dissapears. If anyone knows what is happening, please help. I will post any code requested.
Slaru
How do you react on that message? What doues your WndProc look like? You don't give us very much information to help.
My WndProc
BYTE iKeyPress;
switch (message)
{
case WM_ACTIVATE:
if (!HIWORD(wParam)) {
this->m_WinActive = true;
} else {
this->m_WinActive = false;
}
return 0;
case WM_SYSCOMMAND:
switch (wParam)
{
case SC_MONITORPOWER:
case SC_SCREENSAVE:
return 0;
case SC_CLOSE:
this->WinGLKill();
return 0;
case SC_MAXIMIZE:
if (!this->WinGLResize()) {
this->WinGLKill();
}
return 0;
}
break;
case WM_KEYDOWN:
if (wParam > 0 && wParam < 256) {
iKeyPress = (BYTE)wParam;
this->m_Keys[iKeyPress] = true;
}
return 0;
case WM_KEYUP:
if (wParam > 0 && wParam < 256) {
iKeyPress = (BYTE)wParam;
this->m_Keys[iKeyPress] = false;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_WINDOWPOSCHANGING:
return 0;
}
// Send all other messages off to the default WNDPROC
return DefWindowProc(hWnd, message, wParam, lParam);
How do I put that in code window??
BYTE iKeyPress;
switch (message)
{
case WM_ACTIVATE:
if (!HIWORD(wParam)) {
this->m_WinActive = true;
} else {
this->m_WinActive = false;
}
return 0;
case WM_SYSCOMMAND:
switch (wParam)
{
case SC_MONITORPOWER:
case SC_SCREENSAVE:
return 0;
case SC_CLOSE:
this->WinGLKill();
return 0;
case SC_MAXIMIZE:
if (!this->WinGLResize()) {
this->WinGLKill();
}
return 0;
}
break;
case WM_KEYDOWN:
if (wParam > 0 && wParam < 256) {
iKeyPress = (BYTE)wParam;
this->m_Keys[iKeyPress] = true;
}
return 0;
case WM_KEYUP:
if (wParam > 0 && wParam < 256) {
iKeyPress = (BYTE)wParam;
this->m_Keys[iKeyPress] = false;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_WINDOWPOSCHANGING:
return 0;
}
// Send all other messages off to the default WNDPROC
return DefWindowProc(hWnd, message, wParam, lParam);
How do I put that in code window??
Earlier when i was debugging to find out why my window closed almost immediately after creation, I found that that was the message that seemed to be the problem. I then had a messagebox pop up whenever it happened. I am very lost on this. I checked MSDN docs on the message and I couldn't figure out why I would be getting that message.
// Main message loopwhile (msg.message != WM_QUIT){ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { if (m_Keys[VK_ESCAPE]) { WinGLKill(); } if (m_WinActive) { // Find elapsed time since last frame if ((CurTime = SysTimer->ElapsedTime()) == -1.0f) { MessageBox(0, "Could not get the current time", "ERROR", MB_ICONERROR); break; } TimeElap = CurTime - LastTime; // Update and draw scene Renderer->Render(TimeElap); SwapBuffers(m_hDC); LastTime = CurTime; TotalFrames++; } }}
Edit: The
brackets don't seem to work??
After a little more debugging, it looks like I never reach the part of my message loop for rendering. I receive many messages and then the window just closes. Never does it enter
} else { if (m_Keys[VK_ESCAPE]) { WinGLKill(); } if (m_WinActive) { // Find elapsed time since last frame if ((CurTime = SysTimer->ElapsedTime()) == -1.0f) { MessageBox(0, "Could not get the current time", "ERROR", MB_ICONERROR); break; } TimeElap = CurTime - LastTime; // Update and draw scene Renderer->Render(TimeElap); SwapBuffers(m_hDC); LastTime = CurTime; TotalFrames++; }}
As Nuget5555 suggested, try putting your code in code blocks as follows
[source]
cout << "Hello World" << endl;
[/source]
appears as
Just much easier to read and diagnose your problem, than a long text string.
[source]
cout << "Hello World" << endl;
[/source]
appears as
cout << "Hello World" << endl;
Just much easier to read and diagnose your problem, than a long text string.
What happens if you remove these lines:
and let Windows handle the message?
Are you calling SetWindowPos() anywhere?
What does your CreateWindowEx() function look like?
case WM_WINDOWPOSCHANGING:return 0;
and let Windows handle the message?
Are you calling SetWindowPos() anywhere?
What does your CreateWindowEx() function look like?
As for not entering that else statement, that's because you're message queue is never empty. If you trully are getting constant WM_WINDOWPOSCHANGING messages, you should never enter that else statement. As other people stated, try looking where you change the position of the window, or the z order, or the size. It might not necessarily be in your wndproc.
(IE, putting a breakpoint on that message will cause this message to be placed in an infinite loop, and putting a messagebox there will also cause this, since you're changing the z order).
(IE, putting a breakpoint on that message will cause this message to be placed in an infinite loop, and putting a messagebox there will also cause this, since you're changing the z order).
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement