'API函数声明
Option Explicit
Private Declare Function GetMenu Lib "user32"(Byval hwnd As Long) _
As Long '取得窗口的菜单句柄,hwnd是窗口的句柄
Private Declare Function GetSubMenu Lib "user32"(Byval hMenu As _
Long,Byval nPos As Long) As Long '取得子菜单句柄,nPos是菜单的位置
Private Declare Function SetMenuItemBitmaps Lib "user32"(Byval _
hMenu As Long,Byval nPos As Long,Byval wFlags As Long,Byval _
hBitUnchecked As Long,Byval hBitChecked As Long) As Long
'为菜单设置相应的图形
Const MF_BITMAP=&H400&
'用image或picture或imagelist控件装入图形(必须是bmp格式),16*16左右
'建好菜单
Private Sub Form_Load()
Dim hMenu,hSubMenu1,hSubMenu2 As Long
hMenu=GetMenu(me.hwnd)
hSubMenu1=GetSubMenu(hMenu,0) '取得第一项菜单的子菜单句柄
SetMenuItemBitmaps hSubMenu1,0,MF_BITMAP,imagelist1.listimages(1) _
.picture,imagelist1.listimages(1).picture
'为hSubMenu1的第一项设置图形,假设用imagelist控件装入图形
SetMenuItemBitmaps hSubMenu1,1,MF_BITMAP,imagelist1.listimages(2) _
.picture,imagelist1.listimages(2).picture
'设置第二项,同样你还可以设置第xx项。
hSubMenu2=GetSubMenu(hMenu,1) '取得第二项菜单的子菜单句柄
'也可用SetMenuItemBitmaps来设置它的图形,只更改hSubMenu1为hSubMenu2
'即可
End Sub
本文地址:http://com.8s8s.com/it/it6884.htm