When I exit my program it disappears but it stays in the ctrl-alt-delete menu so if I try and re-build it I can't. Does anyone know whats wrong?
Printable View
When I exit my program it disappears but it stays in the ctrl-alt-delete menu so if I try and re-build it I can't. Does anyone know whats wrong?
what are you using to close it?
Code:LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
how are you closing it? The title bar? A button?
the "X" at the top of the window
exit(0) will work. :)
You shouldn't use exit like that. It's very bad (like using End in VB) because certain things don't get cleared up.
What's in your message loop? Your window procedure looks fine to me.
yeah, it's probably the mesage loop
i suppose it's something like that:
but WM_QUIT (which makes GetMessage return 0, thus leaving the loop) is not directed to any window, so GetMessage(hwnd) won't catch it. Use GetMessage(&msg, NULL, 0, 0) instead.PHP Code:while(GetMessage(&msg, hwnd, 0, 0) // hwnd is the main window
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
I once had that problem and the symptoms were exactly the same, so I suppose that's the problem you have.
All the buzzt
CornedBee
Bad CornedBee ;) It should be:Code:while(GetMessage(&msg, hwnd, 0, 0) // hwnd is the main window
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
You need to cater for a -1 return value as well, which is converted to a bool true.Code:while(GetMessage(&msg, NULL /* or hwnd if ya want */, 0, 0) > 0) {
Translate...
Dispatch...
}
for some reason my loop looks the same as yours but I replaced it and it works. thanks alot!
that's cool parksie, I always wondered how to catch the possible -1 return without a damn complicated loop. I never thought about this easy way. Thanks
Oh, and Preston, I don't think you need to handle the WM_CLOSE message. I think DefWindowProc calls DestroyWindow by default. At least my programs seem to work flawless(correct english?) with it, but I'm not sure.
All the buzzt
CornedBee