Wm_command

This is a discussion on Wm_command within the Windows Programming forums, part of the Platform Specific Boards category; I have made a small program with a menu. In my winproc I thought it would be a good idea ...

  1. #1
    Registered User morbuz's Avatar
    Join Date
    Aug 2001
    Posts
    35

    Unhappy Wm_command

    I have made a small program with a menu.
    In my winproc I thought it would be a good idea to call a function when an menu-option is selected, like this:
    Code:
    switch(LOWORD(wParam))
        {
        case MENU_FILE_ID_NEW:
            {
    	menuFileNew();
            }break;
    ...
    The function looks like this for the moment:
    Code:
    void menuFileNew()
    {
        MessageBox(NULL, "You selected NEW...", "Your choice", MB_OK);
    }
    The problem is that after the function is executed, the program exits... is there something I have missed?
    [Signature here. (Remove this!)]

  2. #2
    BubbleMan
    Guest

    Post Try this..

    void menuFileNew()
    {
    MessageBox(NULL, "You selected NEW...", "Your choice", MB_OK);
    }


    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case MENU_FILE_ID_NEW:
    menuFileNew();
    break;
    }
    break;

  3. #3
    Registered User morbuz's Avatar
    Join Date
    Aug 2001
    Posts
    35
    Nope... didn't work...
    The Program still exits
    [Signature here. (Remove this!)]

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    attatch your code and we will have a look for you.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User morbuz's Avatar
    Join Date
    Aug 2001
    Posts
    35
    Ok, here...
    Attached Files Attached Files
    [Signature here. (Remove this!)]

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Your missing a break

    Code:
    case WM_COMMAND:
    		{
    		switch(LOWORD(wParam))
    				{
    				
    	case MENU_HELP_ID_ABOUT:
    		menuHelpAbout();
    		break;
    	}break; // THIS ONE
    }
    Sorry if this is messy, but I'm in a rush at the moment

    Later

  7. #7
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Code:
    case WM_COMMAND:
    {
    	switch(LOWORD(wParam))
    	{
    (...)
    	}
    }
    case WM_CLOSE:
    {
    	PostQuitMessage(0);
    	return(0);
    }
    So the switch statement exits, and it falls through to the next one - which, coincidentally, closes the program.

    Then again, had you used a debugger, you would know this already.

    You don't need braces around the contents of a case, either.
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21