【发布时间】: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