当前位置: 开源爱好者 » 编程教程 » VB教程 » 正文

VB为菜单添加图标

VB为菜单添加图标,制作一个图标式菜单,这样更显示专业,而且图标菜单可以为菜单添加提示,更人性化一点:

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 GetMenuItemID 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
Const MF_bitmap = &H4&
Private Sub Command1_Click() '为菜单添加图标
  Dim i As Integer
  Dim menu1 As Long
  Dim menuID As Long
  menu1 = GetMenu(Me.hwnd)  
  For i = 1 To 3
    menuID = GetMenuItemID(GetSubMenu(menu1, 0), i - 1)
    SetMenuItemBitmaps menu1, menuID, MF_bitmap, ImageList1.ListImages(i).Picture, _
         ImageList1.ListImages(i).Picture
  Next
  PopupMenu menu, 0, X, Y '弹出式菜单
End Sub

CopyRight 2015© 开源爱好者 All Rights Reserved 豫ICP备16030607号 隐私声明 网站地图