回复 5 楼 bczgvip
代码如下,请版主指点一下,谢谢。
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
Const MF_BYPOSITION = &H400&
Private Sub Form_Load()
' --- 自定义图标-开始
Dim mHandle As Long, lRet As Long, sHandle As Long, sHandle2 As Long
' 取得菜单的句柄并赋值给mHandle
mHandle = GetMenu(hwnd)
' 取得mHandle句柄所指菜单的第一个出式菜单的句柄并赋值给sHandle
sHandle = GetSubMenu(mHandle, 0)
' 将弹出式菜单的第一个弹出式菜单(0/2/4/6/8)加上图片, 跳过1/3/5/7, 因为是分隔线
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Image1.Picture, Image1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Image2.Picture, Image2.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, Image3.Picture, Image3.Picture)
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, Image4.Picture, Image4.Picture)
lRet = SetMenuItemBitmaps(sHandle, 8, MF_BYPOSITION, Image5.Picture, Image5.Picture)
' 取得mHandle句柄所指菜单的第二个弹出式菜单的句柄并赋值给sHandle
sHandle = GetSubMenu(mHandle, 1)
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, ImageA.Picture, ImageA.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, ImageB.Picture, ImageB.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, ImageC.Picture, ImageC.Picture)
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, ImageD.Picture, ImageD.Picture)
lRet = SetMenuItemBitmaps(sHandle, 8, MF_BYPOSITION, ImageE.Picture, ImageE.Picture)
' 取得mHandle句柄所指菜单的第三个弹出式菜单的句柄并赋值给sHandle
sHandle = GetSubMenu(mHandle, 2)
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Pic1.Picture, Pic1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Pic2.Picture, Pic2.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, Pic3.Picture, Pic3.Picture)
lRet = SetMenuItemBitmaps(sHandle, 6, MF_BYPOSITION, Pic4.Picture, Pic4.Picture)
lRet = SetMenuItemBitmaps(sHandle, 8, MF_BYPOSITION, Pic5.Picture, Pic5.Picture)
sHandle = GetSubMenu(mHandle, 3) '以下两个是定义托盘的两个按钮图标---未起作用
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Pic1.Picture, Pic1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Pic2.Picture, Pic2.Picture)
sHandle = GetSubMenu(mHandle, 4) '以下两个是定义窗体鼠标右键的三个按钮图标---未起作用
lRet = SetMenuItemBitmaps(sHandle, 0, MF_BYPOSITION, Pic1.Picture, Pic1.Picture)
lRet = SetMenuItemBitmaps(sHandle, 2, MF_BYPOSITION, Pic2.Picture, Pic2.Picture)
lRet = SetMenuItemBitmaps(sHandle, 4, MF_BYPOSITION, Pic3.Picture, Pic3.Picture)
' --- 自定义图标-结束
End Sub
[
本帖最后由 opelwang 于 2014-6-28 23:18 编辑 ]