PDA

Click to See Complete Forum and Search --> : VB Snippet - Bitmap in Menus


James Stanich
Feb 20th, 2003, 01:41 PM
Add a picturebox with a 16x16 bitmap



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 hMenu As Long, hSubMenu As Long

' GET HWND OF MENU

hMenu = GetMenu(Me.hwnd)

' ENSURE EXISTANCE OF MENU

If hMenu = 0 Then

MsgBox "This form doesn't have a menu!"

Exit Sub

End If

' FIND 1ST SUB-MENU

hSubMenu = GetSubMenu(hMenu, 0)

' ENSURE EXISTANCE OF SUB - MENU

If hSubMenu = 0 Then

MsgBox "This form doesn't have a submenu!"

Exit Sub

End If

' SET THE MENU BITMAP

SetMenuItemBitmaps hSubMenu, 0, MF_BYPOSITION, _
Picture1.Picture, Picture1.Picture

End Sub

csar
Jan 6th, 2004, 02:38 AM
The size is smaller than 16x16..(I guess it equal checkbox size?!?) Have another way to put picture into menu bar?

Madboy
Jan 13th, 2004, 10:00 AM
You could use a XP Style Menu found at vbSmart (http://www.mvps.org/the_nerd/VBSmartMirror/index.htm) :)