Search code examples
c++menuradio-buttonmenuitem

How do I create a Radio Menu Item in c++?


I just started C++ and I searched online for ways to create a radio menu item, but I'm quite confused.

Preferrable an example would help clear things up.

So, I want to be able to create a simple radio menu item like this: https://i.sstatic.net/IIU95.png

but, I'm stuck on how to create a radio menu item. So far I have this:

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    int wmId, wmEvent;
    HRESULT hr;
    POINTER_INFO pointerInfo = {};

    HMENU hmenu = GetMenu(hWnd);
    HMENU hChangeMenu = CreateMenu();
    HMENU hGesture = CreateMenu();     
    HMENU hPointer = CreateMenu();       


    UNREFERENCED_PARAMETER(hr);

    if(changeAPI)
    {
        AppendMenu(hmenu, MF_POPUP, (UINT_PTR)hChangeMenu, L"API");


        **// I want this to be a radio menu item, all I know is the MF_POPUP**
        AppendMenu(hChangeMenu, MF_POPUP, (UINT_PTR)hGesture, L"Gesture");
        AppendMenu(hChangeMenu, MF_POPUP, (UINT_PTR)hPointer, L"Pointer"); 
        AppendMenu(hChangeMenu, MF_POPUP, (UINT_PTR)hTouch, L"Touch");


        changeAPI = false;

    }
    //....other stuff....

Solution

  • The "radio" logical behavior of the menu items must be provided by your code. After you have created the menu items use ModifyMenu to add/remove a check mark or bitmap to the appropriate items.