Enable/Disable Menu Item (in C++)

Nov 20, 2013 at 5:53pm
The advice from the C/C++ Forum was to try this one, so here we go:

This topic seems to have cropped up regularly over a decade or more. I have ploughed through the exchanges in all the forums, yet I still cannot make it work. The following is a tiny Code::Blocks program, written to isolate the
problem:
// resource.h
#define IDR_MYMENU	101
#define ID_FILE     	102
#define ID_DISABLE	103
#define ID_ENABLE       104
#define ID_MESSAGE	105
#define ID_EXIT		106
// resource.rc
#include <windows.h>
#include "resource.h"
IDR_MYMENU MENU
{
    POPUP "File"
    {
        MENUITEM "M1 Disable M3",	ID_DISABLE
        MENUITEM "M2 Enable M3",        ID_ENABLE
        MENUITEM "M3 MesageBox",	ID_MESSAGE
        MENUITEM "M4 Exit",	        ID_EXIT

    }
}
// main.cpp
... minimal code down to case ID_DISABLE within case WM_COMMAND, and then ...
HMENU hmenu = GetMenu(hwnd);
EnableMenuItem(hmenu, ID_MESSAGE, MF_GRAYED );

case ID_ENABLE is similar to case ID_DISABLE above, and neither works. case ID_MESSAGE and case ID_EXIT both works as expected.

I have tinkered with EnableMenuItem(), as various posts have suggested, but without success. Can anybody help?

Peter
Topic archived. No new replies allowed.