| The following sample code assumes a form created with at least one top-level menu item that has two sub-items. It also assumes two pictureboxes have been created at design time, with AutoRedraw=True and bitmaps loaded into the Picture properties: Private Declare Function ModifyMenuPic Lib "user32" Alias "ModifyMenuA" _ (ByVal hmenu As Long, ByVal nPosition As Long, _ ByVal wFlags As Long, ByVal wIDNewItem As Long, _ ByVal lpString As Long) As Long 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 Const MF_BITMAP = 4 Const MF_BYCOMMAND = 0 Const MF_BYPOSITION = &H400& Sub Form_Load() Dim hmenu&, hSubmenu&, menuid&, result As Long ' Note the "&" characters Me.Show ' make me visible so all is initialized properly hmenu = GetMenu(Form1.hwnd) ' get handle to form menu hSubmenu = GetSubMenu(hmenu, 0) ' get handle to first submenu menuid = GetMenuItemID(hSubmenu, 0) ' get ID of first submenu item result = ModifyMenuPic(hSubmenu, menuid, MF_BYCOMMAND Or MF_BITMAP, _ menuid, Picture1.Picture) ' change first submenu item to bitmap menuid = GetMenuItemID(hSubmenu, 1) ' get second item ID result = ModifyMenuPic(hSubmenu, menuid, MF_BYCOMMAND Or MF_BITMAP, _ menuid, Picture2.Picture) ' change to bitmap End Sub |
Replacing Menu Caption with a Bitmap |
Express News India | Freelance ecommerce web development India