图标在PopUp菜单VB6中消失

时间:2014-09-12 22:09:43

标签: api menu vb6 popup icons

在将主要(第一个)PopUp菜单项Visible属性设置为False后,PopUp菜单中的图标消失了,但是当Visible属性切换回Enable时它们会返回,为什么?

Option Explicit

Private Const MF_BITMAP = &H4&
Private Const MF_BYPOSITION  As Long = &H400& '&H404&

Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long

Public Sub SetPopUpMenuIcons(objFRM As Form)
 On Error Resume Next

 Dim lgRet As Long
 Dim lgMnu As Long
 Dim lgSubMnu As Long

 lgMnu = GetMenu(objFRM.hwnd)

 lgSubMnu = GetSubMenu(lgMnu, 0)

 With objFRM
  lgRet = SetMenuItemBitmaps(lgSubMnu, 0, MF_BYPOSITION, .imgMnu(0).Picture, 0)
  lgRet = SetMenuItemBitmaps(lgSubMnu, 1, MF_BYPOSITION, .imgMnu(1).Picture, 0)
  lgRet = SetMenuItemBitmaps(lgSubMnu, 2, MF_BYPOSITION, .imgMnu(2).Picture, 0)
  lgRet = SetMenuItemBitmaps(lgSubMnu, 3, MF_BYPOSITION, .imgMnu(3).Picture, 0)
  lgRet = SetMenuItemBitmaps(lgSubMnu, 4, MF_BYPOSITION, .imgMnu(4).Picture, 0)
 End With

 Exit Sub
End Sub

1 个答案:

答案 0 :(得分:0)

我相信VB6 PopupMenu方法实际上创建了一个新的弹出菜单(通过调用CreatePopupMenu)然后使用隐藏的菜单项作为模板通过InsertMenu或AppendMenu创建项目,但不使用位图标志和处理它没有#&# 39;知道你背后加了。

您可能必须自己完成所有工作,为每个项调用CreatePopupMenu然后调用InsertMenuItem而不是InsertMenu / AppendMenu(为了同时拥有位图和文本),并使用子类来获取选择"事件"如果有的话,等等。

换句话说,做任何你想做的事情可能没有琐碎的方法。 VB6菜单管道似乎基于旧的16位Windows(Win 3.x)逻辑和API调用。

太糟糕了我们从来没有真正的VB7!在插上支持.Net之前,微软已经积累了大量此类功能增强功能。

可能有第三方菜单控件可以使这更容易。