CodeItBetter Programming Another VB Programming Blog

How to add Bitmaps to Menu

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'Forms - How to add Bitmaps to Menu

Option Explicit
 
'Add a Command Button And two Picture Boxes to your form.
'Set Picture Boxes AutoSize property to True. Add pictures to the Picture Boxes.
'When the menu will be enabled, the picture in Picture1 will be displayed.
'When the menu will be disabled, the picture in Picture2 will be displayed.
'The pictures should not be bigger than 13x13.
'Add menu to your form, Add a sub menu to the menu and name it MyMenu.
'When you run this program, click on the button to enable\disable menu.

Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
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
Public Const MF_BITMAP = &H4&
 
Private Sub Command1_Click()
    MyMenu.Enabled = Not MyMenu.Enabled
End Sub
 
Private Sub Form_Load()
    'Replace 'Form1' with the name of your form
    hMenu& = GetMenu(Form1.hWnd)
    'Replace '0' with the menu position. '0' means the first menu from left.
    'If it was the second from left, you should been place there '1'.
    hSubMenu& = GetSubMenu(hMenu&, 0)
    'Replace '0' with the sub menu position. '0' means the upper sub menu.
    'If it was the second from top, you should been place there '1'.
    hID& = GetMenuItemID(hSubMenu&, 0)
    SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, Picture1.Picture, Picture2.Picture
End Sub
Filed under: Forms Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.