Sign in to follow this  
Slaru

Help with my WndProc

Recommended Posts

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

// Main message loop
while (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??

Share this post


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

Share this post


Link to post
Share on other sites
As Nuget5555 suggested, try putting your code in code blocks as follows

[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.

Share this post


Link to post
Share on other sites
What happens if you remove these lines:

case WM_WINDOWPOSCHANGING:
return 0;


and let Windows handle the message?

Are you calling SetWindowPos() anywhere?

What does your CreateWindowEx() function look like?

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
My CreateWindowEx function is this:

m_hWnd = CreateWindowEx(dwExStyle,
szWindowClass,
szTitle,
WS_CLIPSIBLINGS | // Required Window Style for OpenGL
WS_CLIPCHILDREN | // Required Window Style for OpenGL
dwStyle,
CW_USEDEFAULT,
CW_USEDEFAULT,
((WinRect.right) - (WinRect.left)),
((WinRect.bottom) - (WinRect.top)),
NULL,
NULL,
m_hInst,
NULL);


I knew that I wouldn't ever enter my rendering part of the loop already, I was just telling you guys. The only time I am changing my position, z-order, or size would be on creation of the window. When I remove the messagebox and dont debug, the window still closes. If i don't process the message, the same thing happens still.

When I am debugging, I have found that the message is called a few times, and after the window is created and displayed, and then the last time it processes it, I jump into the dissasembly and find it always closes the window when it reaches a command 'leave'. If that is of any help, I don't know. My guess is that means leave the function??

Share this post


Link to post
Share on other sites
Well,
I am the biggest moron ever (again). I never actually entered my messageloop. I had something like this in main():

main()
{
CreateWindow();

// MessageLoop(); <-- should have added this. doh!

return 0;
}


Thanks for the help though

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