如何加粗上下文菜单项?

时间:2012-05-18 23:30:33

标签: c++ c windows

我想将托盘图标的上下文菜单中的第一项设为粗体。应该很容易但我在任何地方都找不到答案。有人可以指点我正确的方向吗?这是我用来呈现项目的代码:

void MenuItemWin::CreateNative(
    LPMENUITEMINFO itemInfo, HMENU nativeParentMenu, bool registerNative)
{
    ZeroMemory(itemInfo, sizeof(MENUITEMINFO)); 
    itemInfo->cbSize = sizeof(MENUITEMINFO);
    itemInfo->wID = ++UIWin::nextItemId;
    itemInfo->dwItemData = (ULONG_PTR) this;
    itemInfo->fMask = MIIM_ID | MIIM_FTYPE | MIIM_DATA;

    HMENU nativeSubmenu = 0;
    if (this->IsSeparator())
    {
        itemInfo->fType = MFT_SEPARATOR;
    }
    else
    {
        itemInfo->fMask = itemInfo->fMask | MIIM_STRING | MIIM_SUBMENU | MIIM_STATE;
        itemInfo->fType = MFT_STRING;
        itemInfo->fState = this->IsEnabled() ? MFS_ENABLED : MFS_DISABLED;
        itemInfo->dwTypeData = (LPWSTR) this->wideOldLabel.c_str();

        AutoPtr<MenuWin> wsubmenu = this->submenu.cast<MenuWin>();
        if (!wsubmenu.isNull())
            nativeSubmenu = wsubmenu->CreateNative(registerNative);

        itemInfo->hSubMenu = nativeSubmenu;

        if (this->IsCheck())
        {
            itemInfo->fState |= this->GetState() ? MFS_CHECKED : MFS_UNCHECKED;
        }
        else if (!this->iconPath.empty())
        {
            HBITMAP bitmap = UIWin::LoadImageAsBitmap(iconPath,
                GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
            if (bitmap)
            {
                itemInfo->fMask = itemInfo->fMask | MIIM_BITMAP;
                itemInfo->hbmpItem = bitmap;
            }
            else
            {
                std::string error = Win32Utils::QuickFormatMessage(GetLastError());
                Logger::Get("UI.MenuItem")->Error("Could not load icon (%s): %s",
                    iconPath.c_str(), error.c_str());
            }
        }
    }

    if (registerNative)
    {
        NativeItemBits* bits = new NativeItemBits;
        bits->id = itemInfo->wID;
        bits->parentMenu = nativeParentMenu;
        bits->submenu = nativeSubmenu;
        this->nativeItems.push_back(bits);
    }
}

0 个答案:

没有答案