[C++11 - win32] - about WM_MENUCOMMAND message

if:

wParam: The zero-based index of the item selected.
lParam: A handle to the menu for the item selected.

the GetMenuItemInfo() needs a handle, position, true(because it's the position), and a adress to a MENUITEMINFO variable structure.

1
2
3
4
5
6
7
8
9
10
11
case WM_MENUCOMMAND:
                {
                    BOOL fResult = FALSE;
                    MENUITEMINFO menuInfo = { 0 };

                    menuInfo.cbSize = sizeof(MENUITEMINFO);
                    menuInfo.fMask=MIIM_STRING;

                    GetMenuItemInfo((HMENU)lParam,(UINT) wParam, true, &menuInfo );//true means by position
                    if (menuInfo.dwItemData==NULL)
                        MessageBox(NULL,"erro", "test",MB_OK);

why the menuInfo.dwItemData is NULL?
add MIIM_DATA to menuInfo.fMask.
thanks for all. you have right. but i was doing more errors too:
1
2
3
4
5
6
7
8
9
10
case WM_MENUCOMMAND:
                {
                    MENUITEMINFO menuInfo;
                    menuInfo.cbSize = sizeof(MENUITEMINFO);
                    menuInfo.fMask=MIIM_DATA;
                    GetMenuItemInfo((HMENU)lParam,(UINT) wParam, true, &menuInfo );//true means by position
                    Menu *mMenu = (Menu *) menuInfo.dwItemData;
                    mMenu->MenuClick();
                }
                break;

now works like i need. thanks.
i need ask 1 confusion that i have:
1 - when we change the menu properties(string, bitmap), what menu handle we use?
2 - when we add a new item to menu, what menu handle we use?

don't be confused/bad with my questions... i'm asking these, because i'm confused. and sometimes i get wrong results because of that :(
Topic archived. No new replies allowed.