菜单项图像(MENUITEMINFO的hbmpItem)在上下文菜单中的位置 [英] Positioning of a menu item image (hbmpItem of a MENUITEMINFO) in a context menu

查看:172
本文介绍了菜单项图像(MENUITEMINFO的hbmpItem)在上下文菜单中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将菜单项插入主题文本控件的Outlook上下文菜单中. 在这里您可以找到上一个问题曾经这样做.

I am inserting a menu item into an Outlook Context menu for a subject text control. Here you can find a previous question I had on doing this.

我遇到的问题是,菜单项的图像在Outlook 2010中的位置异常.在Outlook 2007中,其位置不同.似乎菜单项在Outlook 2010中保持了选中图像的位置.

The issue I have is that the image of the menu item is positioned strangely in Outlook 2010. In Outlook 2007 it is positioned differently. It seems that the menu item is holding the position for the checked image free in Outlook 2010.

这显示了下面的代码如何显示我的菜单项.请注意图像左侧的大空间.

This shows how my menu item looks with the below code. Notice the large space to the left of the image.

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

This shows how it looks when i add the MIIM_CHECKMARKS flag to fMask and a bitmap to the hbmpUnchecked pointer.

            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)

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

So how can I tell the menu item not to reserve the space for the check / uncheck image?

推荐答案

对于这个问题,我有两个答案.

I have two answers to this problem.

我在上面指出,此问题存在于Outlook 2010的菜单中,但不存在于Outlook2007.这不是事实.这些Office版本当然在不同的计算机上,并且是Windows中的显示设置是造成此问题的原因.当关闭了性能选项">视觉效果"(Win 7)中的使用Windows上的视觉样式和按钮"设置时,将获得上面的菜单.如果启用此设置,则菜单的外观尤其会以非常不同的方式起作用.

I indicated above that the issue existed on an menu in Outlook 2010 but not in Outlook 2007. This is not true. These office versions are of course on different computers and it was a display setting in windows that was the cause of the problem. The above menu is what you get when you have the setting "Use Visual Styles on Windows and buttons" in Performance Options > Visual Effects turned off (Win 7). If you enable this setting then the menus look and especially act very differently.

但是,如果用户禁用此设置该怎么办呢(不确定是否与Win10有关).

But what if a user disables this setting how can you deal with it (Not sure if this is relevant for Win10).

您需要设置通过使用Menuinfo 来设置菜单样式,特别是您需要设置标志MNS_NOCHECK.然后,该空间消失了,因为菜单不再需要复选标记.

You need to set the menu style through the use of the Menuinfo in particular you need to set the flag MNS_NOCHECK. Then the space is gone as the menu no longer is expecting the check marks.

此解决方案在另一个stackoverflow答案中也可以在此处看到.

这篇关于菜单项图像(MENUITEMINFO的hbmpItem)在上下文菜单中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆