• Win32 菜单添加复选标记和单选标记


    在菜单中添加复选标记用CheckMenuItem函数

    CheckMenuItem函数原型:

    DWORD
    WINAPI
    CheckMenuItem(
        _In_ HMENU hMenu,    //菜单句柄
        _In_ UINT uIDCheckItem,  //菜单ID
        _In_ UINT uCheck);    //复选标记MF_CHECKED(添加复选标记)和MF_UNCHECKED(取消复选标记)

    实例:

    LRESULT MyWnd::OnCommand(DWORD dwID, DWORD dwEnter, HWND hCtrlWnd)
    {
        HMENU hMenu = GetMenu(m_hWnd);  //获得窗口菜单句柄
        HMENU hItem = GetSubMenu(hMenu, 1);//获得第二个子菜单项的句柄
    
        switch (dwID)
        {
       case ID_TOOBAR_MENU:
        {
            //判断是否有复选标记,如果有就取消复选标记,没有就添加复选标记
            if (CheckMenuItem(hItem, ID_TOOBAR_MENU, MF_CHECKED)&MF_CHECKED)
                CheckMenuItem(hItem, ID_TOOBAR_MENU, MF_UNCHECKED);
    
            break;
        }
        case ID_STAT_MENU:
        {
        
            if (CheckMenuItem(hItem, ID_STAT_MENU, MF_CHECKED)&MF_CHECKED)
                CheckMenuItem(hItem, ID_STAT_MENU, MF_UNCHECKED);
    
            break;
        }
            
        case ID_MENU_MENU:
        {
            if (CheckMenuItem(hItem, ID_MENU_MENU, MF_CHECKED)&MF_CHECKED)
                CheckMenuItem(hItem, ID_MENU_MENU, MF_UNCHECKED);
           
            break;
        }
    
        }
        return 0;
    }

    在菜单中添加单选标记用CheckMenuRadioItem函数

    CheckMenuRadioItem函数原型:

    BOOL
    WINAPI
    CheckMenuRadioItem(
        _In_ HMENU hmenu,  //菜单句柄
        _In_ UINT first,  //第一个菜单项ID
        _In_ UINT last,   //最后一个菜单项ID
        _In_ UINT check,  //要标记的菜单项ID
        _In_ UINT flags);  //单选标记MF_BYCOMMAND

    实例:

    //菜单ID号要是连续的Id号

    #define ID_TOOBAR_MENU 40027
    #define ID_STAT_MENU 40028
    #define ID_MENU_MENU 40029




    LRESULT MyWnd::OnCommand(DWORD dwID, DWORD dwEnter, HWND hCtrlWnd) { HMENU hMenu
    = GetMenu(m_hWnd); HMENU hItem = GetSubMenu(hMenu, 1); switch (dwID) { case ID_TOOBAR_MENU: { CheckMenuRadioItem(hItem, ID_TOOBAR_MENU, ID_MENU_MENU, ID_TOOBAR_MENU, MF_BYCOMMAND); break; } case ID_STAT_MENU: { CheckMenuRadioItem(hItem, ID_TOOBAR_MENU, ID_MENU_MENU, ID_STAT_MENU, MF_BYCOMMAND); break; } case ID_MENU_MENU: { CheckMenuRadioItem(hItem, ID_TOOBAR_MENU, ID_MENU_MENU, ID_MENU_MENU, MF_BYCOMMAND); break; } } return 0; }

    效果图:

    签名:GreenLeaf1976
  • 相关阅读:
    iOS 倒计时及获取本时区时间
    文字上的删除线
    ios 预览文件-QLPreviewController用法
    iOS delegate、notification、KVO的区别
    mvc 详解
    app切图暂时没有iOS8的,后续继续添加
    背影图
    字体渐变
    ios for 循环 创建 九宫格
    Spherical Harmonics Lighting
  • 原文地址:https://www.cnblogs.com/greenleaf1976/p/14925110.html
Copyright © 2020-2023  润新知