Jump to content
  • Advertisement
Sign in to follow this  
raccoonone

Close button not responding.

This topic is 4565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been writting a game and the client is a windows application. However sometimes when I click the close button (the X in the upper right) the game doesn't close it's self. Going to the system menu and selecting close always works. Additionally, if you move the window around and then click the close button it closes. Does anyone know what's wrong? I'm thinking it must have something to do with the parent window not having focus, but I'm still learning windows programming and haven't been able to track it down.

Share this post


Link to post
Share on other sites
Advertisement
Here's the proc for my parent window


LRESULT CALLBACK CDungeoneerWindow::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch(iMessage)
{
/* Close window */
case WM_CLOSE:
PostQuitMessage(0);
return true;
break;

case WM_COMMAND:
//Check for child window messages
switch(LOWORD(wParam))
{
case DEF_hSendButton:
GameEngine->vWindowsMessage(DEF_hSendButton);
break;
case DEF_hLoginButton:
GameEngine->vWindowsMessage(DEF_hLoginButton);
break;
case DEF_hRegisterButton:
GameEngine->vWindowsMessage(DEF_hRegisterButton);
break;
}
switch(HIWORD(wParam))
{
case EN_UPDATE:
switch(LOWORD(wParam))
{
case DEF_hChatEdit:
//Get text from the chat edit box
GameEngine->vWindowsMessage(DEF_hChatEdit);
break;
case DEF_hUserNameEditBox:
GameEngine->vWindowsMessage(DEF_hUserNameEditBox);
break;
}
}
return true;
break;

//Connect timer message?
case WM_TIMER:
if(wParam == TIMERID_CONNECT_COMPLETE)
{
// Check if the message is telling us our connection is complete
if(WAIT_OBJECT_0 == WaitForSingleObject( g_hConnectCompleteEvent, 0 ))
{
if( FAILED( g_hrConnectComplete ) )
{
//failed to connect to server, exit program
GameEngine->vConnected(false);
}
else
{
//connection was successful
GameEngine->vConnected(true);
}
KillTimer(m_hWnd, TIMERID_CONNECT_COMPLETE );
}
}
return true;
break;
/* Not handled - let Windows handle */
default:
return DefWindowProc(hWnd, iMessage, wParam, lParam);;
break;
}
return false;
}

Share this post


Link to post
Share on other sites
Hey Procyon I had the same problem so i decided not to put my msg proc in a class I put it in the main file where I had WinMain and it all worked perfect.

Good Luck ^_^

Share this post


Link to post
Share on other sites
This answer will undoubtedly be incomplete, since I cannot find a previous post of mine on the subject, nor can I test your code at the moment, but the documentation states that you must return 0 (FALSE) if you handle WM_COMMAND messages.

You may also want to reorganize your Window Procedure, since you have redundancies such as returns followed by breaks and a return false that will never be reached (the last one).


jfl.

Share this post


Link to post
Share on other sites
cNoob I tried your suggestion, but it didn't help.

I went through my WinProc and fixed up the code, like you suggested jflanglois, but that doesn't seem to have helped either. Here's how the code looks now


LRESULT CALLBACK CDungeoneerWindow::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
switch(iMessage)
{
/* Close window */
case WM_CLOSE:
PostQuitMessage(0);
return 0;

case WM_COMMAND:
//Check for child window messages
switch(LOWORD(wParam))
{
case DEF_hSendButton:
GameEngine->vWindowsMessage(DEF_hSendButton);
break;
case DEF_hLoginButton:
GameEngine->vWindowsMessage(DEF_hLoginButton);
break;
case DEF_hRegisterButton:
GameEngine->vWindowsMessage(DEF_hRegisterButton);
break;
}
switch(HIWORD(wParam))
{
case EN_UPDATE:
switch(LOWORD(wParam))
{
case DEF_hChatEdit:
//Get text from the chat edit box
GameEngine->vWindowsMessage(DEF_hChatEdit);
break;
case DEF_hUserNameEditBox:
GameEngine->vWindowsMessage(DEF_hUserNameEditBox);
break;
}
}
return 0;

//Connect timer message?
case WM_TIMER:
if(wParam == TIMERID_CONNECT_COMPLETE)
{
// Check if the message is telling us our connection is complete
if(WAIT_OBJECT_0 == WaitForSingleObject( g_hConnectCompleteEvent, 0 ))
{
if( FAILED( g_hrConnectComplete ) )
{
//failed to connect to server, exit program
GameEngine->vConnected(false);
}
else
{
//connection was successful
GameEngine->vConnected(true);
}
KillTimer(hWnd, TIMERID_CONNECT_COMPLETE );
}
}
return 0;
/* Not handled - let Windows handle */
default:
return DefWindowProc(hWnd, iMessage, wParam, lParam);;
}
}

Share this post


Link to post
Share on other sites
Again, this is a shot in the dark since I cannot test it, but try returning DefWindowProc(...) instead of 0 in your WM_COMMAND case.

Share this post


Link to post
Share on other sites
Quote:
Original post by jflanglois
Again, this is a shot in the dark since I cannot test it, but try returning DefWindowProc(...) instead of 0 in your WM_COMMAND case.


I checked the MSDN documentation and it says that 0 is the correct return value, if you've handled the message.

Share this post


Link to post
Share on other sites
you dont need to handle it in your message proc just when the user clicks the button use te SendMessage function, im a bit rusty but i believe it would go something like this, SendMessage(HWND, WM_QUIT, 0, 0);

dont quote me opn the arguments
*HWND is were your window handle goes (hwnd)*

so instead of taking care of this in the message proc just make your own onclick or notify message and on that occurance send the WM_QUIT message

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!