填加image控键,在属性中插入图片后写入如下代码: Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _ ByVal nPos As Long) As LongPrivate Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, _ ByVal nPos As Long) As LongPrivate 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 LongConst MF_bitmap = &H4&---------------------------------------------------------------------- Private Sub MDIForm_Load() Dim i As Integer Dim menu1 As Long Dim menuID As Long menu1 = GetMenu(Me.hwnd) For i = 1 To 3 '插入了3幅图片 menuID = GetMenuItemID(GetSubMenu(menu1, 0), i - 1) SetMenuItemBitmaps menu1, menuID, MF_bitmap, ImageList1.ListImages(i).Picture, _ ImageList1.ListImages(i).Picture NextEnd Sub 成功执行,有问题问我!
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _
ByVal nPos As Long) As LongPrivate Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, _
ByVal nPos As Long) As LongPrivate 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 LongConst MF_bitmap = &H4&----------------------------------------------------------------------
Private Sub MDIForm_Load() Dim i As Integer
Dim menu1 As Long
Dim menuID As Long
menu1 = GetMenu(Me.hwnd)
For i = 1 To 3 '插入了3幅图片
menuID = GetMenuItemID(GetSubMenu(menu1, 0), i - 1)
SetMenuItemBitmaps menu1, menuID, MF_bitmap, ImageList1.ListImages(i).Picture, _
ImageList1.ListImages(i).Picture
NextEnd Sub
成功执行,有问题问我!
遇到难题的时候就直接去查API就可以了,99.9%的难题都是通过API解决的
Dim RetVal As Long
hMenu = GetMenu(Me.hwnd)
hSubMenu = GetSubMenu(hMenu, 0) '第一栏
RetVal = SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, ImageList2.ListImages(1).Picture, ImageList2.ListImages(1).Picture)
RetVal = SetMenuItemBitmaps(hSubMenu, 1, MF_BYPOSITION, ImageList2.ListImages(2).Picture, ImageList2.ListImages(2).Picture)
RetVal = SetMenuItemBitmaps(hSubMenu, 2, MF_BYPOSITION, ImageList2.ListImages(3).Picture, ImageList2.ListImages(3).Picture)
这样为什么只有第一个有图标,我加了3个的