Advertisement

Having a bit of trouble with Menus in VC++

Started by April 22, 2000 08:09 PM
11 comments, last by Fredric 24 years, 7 months ago
quote: I moved WM_DESTROY above the switch(LOWORD(wParam) and was able to make it so that the application would still be running after a menuitem was executed!


Hmm.. this shouldn´t happen, something must be wromg with your switch statement, because the code should work no matter where the WM_DESTROY is:

Try this:

// In WndProc

switch(message)
{
case WM_CREATE:
// Do stuf
return 0;

case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_MY_MENU_ITEM:
// Do stuf
return 0;

case IDM_MY_MENU_ITEM:
MessageBox(hwnd, "MenuItem", "", MB_OK);
return 0;
}
break; // Important

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

return DefWindowProc(hwnd, message, wParam, lParam);
// End of Wndproc





Alright, when I ended the
switch(LOWORD(wParam), I put a break; right after it's closing brace which happened to be right before case WM_DESTROY: ... that's kinda weird... why would the program execute WM_DESTROY when know close message has actually been sent?

GO LEAFS GO!

Edited by - Fredric on 4/24/00 8:40:11 AM
3D Math- The type of mathematics that'll put hair on your chest!
Advertisement
quote: that''s kinda weird... why would the program execute WM_DESTROY when no close message has actually been sent?


This happens because the compiler lets the code fall through until a return/break statement is incountered.

This is a good thing, because it makes it possible for one
message handler (case statement), to handle more than one message.

Unfortunatly I can´t give you any simple examples why this is good.
But trust me, it´s a very cool feature!

This topic is closed to new replies.

Advertisement