简体   繁体   English

MFC上下文菜单的项目高度不正确

[英]MFC context menu has incorrect height of items

In my MFC app I create an context menu: 在我的MFC应用程序中,我创建一个上下文菜单:

CString strName;
strName.LoadString(IDS_EDIT_MENU);
GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);

This menu is described in a resource file as usual: 通常在资源文件中描述此菜单:

IDR_POPUP_EDIT MENU
BEGIN
POPUP "Edit"
BEGIN
MENUITEM "Cu&t\tCtrl+X",                ID_EDIT_CUT
MENUITEM "Copy\tCtrl+C",                ID_EDIT_COPY
MENUITEM "&Paste\tCtrl+V",              ID_EDIT_PASTE
END
END

Once in the code I show this menu in a right button handler: 一旦在代码中,我就在右键按钮处理程序中显示此菜单:

theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);

It has icons 16x16 and it is shown good. 它具有图标16x16,并且显示良好。 But then I added a floating toolbar, which has icons 32x32. 但是随后我添加了一个浮动工具栏,该工具栏具有图标32x32。

if (!m_notesToolbar.CreateEx(this,
    TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,
    CRect(1, 1, 1, 1), ID_NOTES_TOOLBAR) ||
    !m_notesToolbar.LoadToolBar(IDR_NOTES_TOOLBAR))
{
    TRACE0("Failed to create toolbar\n");
    return -1;
}

m_notesToolbar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_notesToolbar);

So, now the context menu also has height of items 32 pixels. 因此,现在上下文菜单的项目高度也为32像素。 Why? 为什么? And how can I have these GUI objects of different heights? 以及如何具有这些不同高度的GUI对象?

身高好

身高差

Doing this requires an ownerdraw menu. 这样做需要一个ownerdraw菜单。 Than you can set a menu item height. 比您可以设置菜单项的高度。

For owner draw menus here is a good sample (its old but should work). 对于所有者绘制菜单,这里是一个很好的示例 (它虽然年代久远,但应该可以使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM