🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

my window application stays in memory

Started by
4 comments, last by da_cobra 22 years, 8 months ago
Whenever I close my window application the window dissapears but the program stays in memory so I will have something to do with my message handling but I can''t figure it out LRESULT CALLBACK MsgHandler( HWND hwnd, // This is the handle of the window that sent the message // currently being precessed. UINT msg, // The message identifier WPARAM wparam, // The exact use of the these parameters depends on which LPARAM lparam) // message is being sent, but they are used to further { switch(msg) { case WM_CREATE: // window created { return 0 ; } break ; case WM_COMMAND: // menu command { switch(LOWORD(wparam)) { case ID_APP_EXIT: { PostMessage(hwnd, WM_CLOSE, 0, 0) ; } } } break ; case WM_CLOSE: // User presses close-button or ALT-F4 { // perfect spot to do cleanup checks DestroyWindow(hwnd) ; // Destroys our child-windows (sends out WM_DESTROY) PostMessage(hwnd, WM_DESTROY, 0, 0) ; } // and then our main window break ; case WM_DESTROY: // exit program { PostQuitMessage(NULL) ; // exit program return 0 ; } break ; } return(DefWindowProc(hwnd, msg, wparam, lparam)) ; // Default message handler } any help would be apreciated
Advertisement
How does your message loop look? If you''re using GetMessage, remember to check the return value. When GetMessage returns FALSE the app should exit. If you''re using PeekMessage check the ''message'' member of MSG. If it equals WM_QUIT, then the app should exit.

This probably has nothing to do with your problem, but anyway:

In your WM_CLOSE handler the window is destroyed thrice. First by calling DestroyWindow, then by posting the WM_DESTROY message, and since you break and let DefWindowProc handle the message it will try to destroy the window as well (since that is the default action). This might not matter, I don''t know. It is a bit messy though. You should either just call DestroyWindow and then return, or simply ignore the WM_CLOSE message and let it be handled by DefWindowProc (which then calls DestroyWindow for you).
this is my message loop

MSG msg ;
while (true)
{
if (PeekMessage(&msg, // Pointer to a variable of the type MSG
NULL, // Handle of the window, whose queue you want to check
0, // 1ste message
0, // Last message
PM_REMOVE)) // What to do after reading the message (else PM_NOREMOVE)
{
TranslateMessage(&msg) ; // Translation of message
DispatchMessage(&msg) ; // Invoke your message handler & and sends it the
// appropriate information from the MSG structure
} // end of if
} // end of while


Edited by - da_cobra on October 27, 2001 2:25:53 PM
I have a solution!
One thing you forgot is to check if the msg sent was a WM_QUIT message, or something like that. Anyway you can just add the following code to your loop.

while(TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
// Is There A Message Waiting?
{
if (msg.message==WM_QUIT)
// Have We Received A Quit Message?
{
break;
// If So break
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
} // end

There probably are other ways, but this way works best for me.
hey thanx alot will try it tonight
and will reply again

Edited by - da_cobra on October 30, 2001 6:22:10 AM
yep
that was my fault

thanx alot !!!!!!!!!!!!

This topic is closed to new replies.

Advertisement