Short cut menu

I am trying to create context menu for win32 application using
1
2
3
4
5
6
7
8
case WM_RBUTTONDOWN:
{
    HMENU hPopupMenu = CreatePopupMenu();
    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_CLOSE, _T("Exit");
    InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, ID_EXIT, _T("Play");
    SetForegroundWindow(hWnd);
    TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, 0, 0, 0, hWnd, NULL);
}

This is working fine.But along with this i want submenu for "Play" that is Play-> start & end.Which system function call i have to use for that?
It's a bit more complicated because you have to at first you must create the submenu with CreatePopupMenu() and add items to it, then fill MENUITEMINFO structure and then add submenu to the main menu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        case WM_RBUTTONDOWN:
        {
            HMENU hPopupMenu = CreatePopupMenu();
            HMENU hSubMenu=CreatePopupMenu();  // Create submenu
            
            // Add items to submenu
            InsertMenu(hSubMenu, 0, MF_BYPOSITION | MF_STRING,ID_IDX, _T("Start"));
            InsertMenu(hSubMenu, 0, MF_BYPOSITION | MF_STRING, ID_IDY, _T("Stop"));
            
            // Add items to hPopupMenu (ones without submenu)
            InsertMenu(hPopupMenu, 0, MF_BYPOSITION | MF_STRING, 1245, _T("Exit"));

            // fill MENUITEMINFO structure
            MENUITEMINFO mi = { 0};
            mi.cbSize=sizeof(MENUITEMINFO );
            mi.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
            mi.wID = ID_Z;
            mi.hSubMenu=hSubMenu;
            mi.dwTypeData=_T("Play");
            
            // insert menu item with submenu to hPopupMenu
            InsertMenuItem ( hPopupMenu, 0, false, &mi );

            SetForegroundWindow(hwndDlg);
            TrackPopupMenu(hPopupMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, 0, 0, 0, hwndDlg, NULL);
        }


Last edited on
Thank you.I got the output correctly
Topic archived. No new replies allowed.