【问题标题】:Positioning of a menu item image (hbmpItem of a MENUITEMINFO) in a context menu在上下文菜单中定位菜单项图像(MENUITEMINFO 的 hbmpItem)
【发布时间】:2017-05-03 12:47:56
【问题描述】:

我正在将一个菜单项插入到主题文本控件的 Outlook 上下文菜单中。 Here you can find a previous question I had on doing this.

我遇到的问题是菜单项的图像在 Outlook 2010 中的位置很奇怪。在 Outlook 2007 中,它的位置不同。似乎菜单项在 Outlook 2010 中保留了选中图像的位置。

这显示了我的菜单项在下面的代码中的外观。请注意图像左侧的大空间。

这显示了当我将 MIIM_CHECKMARKS 标志添加到 fMask 并将位图添加到 hbmpUnchecked 指针时的外观。

            Dim bmp As Drawing.Bitmap = My.Resources.olContextMenuIcon
            bmp.MakeTransparent(bmp.GetPixel(10, 10))

            hbitmap = bmp.GetHbitmap

            Dim mii As New NativeMethodsEX.MENUITEMINFO
            With mii
                .cbSize = Marshal.SizeOf(mii)
                .fMask = NativeMethodsEX.MIIM.MIIM_BITMAP Or NativeMethodsEX.MIIM.MIIM_STRING Or NativeMethodsEX.MIIM.MIIM_FTYPE Or NativeMethodsEX.MIIM.MIIM_STATE Or NativeMethodsEX.MIIM.MIIM_ID
                .wID = WM_APP
                .fType = NativeMethodsEX.MFT.MFT_STRING
                .dwTypeData = String.Concat("Wrong Position")
                .fState = NativeMethodsEX.MFS.MFS_ENABLED
                .hbmpItem = hbitmap
            End With

            If ShowTop Then
                NativeMethodsEX.InsertMenuItem(aHwnd, 0, True, mii)
                NativeMethodsEX.InsertMenu(aHwnd, 1, NativeMethodsEX.MFT.MFT_BYPOSITION Or NativeMethodsEX.MFT.MFT_SEPARATOR, Nothing, Nothing)
            Else
                Dim menuItemCount As Integer = NativeMethodsEX.GetMenuItemCount(aHwnd)
                NativeMethodsEX.InsertMenu(aHwnd, menuItemCount, NativeMethodsEX.MFT.MFT_BYPOSITION Or NativeMethodsEX.MFT.MFT_SEPARATOR, Nothing, Nothing)
                NativeMethodsEX.InsertMenuItem(aHwnd, menuItemCount + 1, True, mii)
            End If

            NativeMethodsEX.DrawMenuBar(subjectRegionHwnd)

那么如何告诉菜单项不要为选中/取消选中图像保留空间?

【问题讨论】:

  • 您无法控制如何添加其他菜单项,它们肯定是问题的根源。我怀疑您需要通过 not 使用 hbmpItem 和 ab/use hbmpUnchecked 来显示位图。可能会奏效。
  • 是的,我同意这是一种解决方法。然而,我已经解决了这个问题,并将写一个解决问题的方法。

标签: vb.net winapi pinvoke outlook-addin


【解决方案1】:

我对这个问题有两个答案。

我在上面指出该问题存在于 Outlook 2010 的菜单中,但不存在于 Outlook 2007 中。事实并非如此。这些办公版本当然是在不同的计算机上,这是导致问题的原因是 Windows 中的显示设置。上面的菜单是在性能选项 > 视觉效果关闭(Win 7)中设置“在 Windows 和按钮上使用视觉样式”时得到的。如果启用此设置,则菜单的外观和行为会大不相同。

但是如果用户禁用了这个设置,你该如何处理(不确定这是否与 Win10 相关)。

You need to set the menu style through the use of the Menuinfo 特别是您需要设置标志 MNS_NOCHECK。然后空间消失了,因为菜单不再需要复选标记。

此解决方案 can also be seen here 在另一个 stackoverflow 答案中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 2016-02-14
    • 2013-12-27
    • 2017-05-13
    • 1970-01-01
    相关资源
    最近更新 更多