General discussion

Locked

Pictures in Menu bar

By isvanand ·
Hi All,
How would u add a Picture/Icons to your menus in a Visual basic Application


Vijay.

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Pictures in Menu bar

by juanja In reply to Pictures in Menu bar

Add a module, and put the following code inside:

Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare FunctionGetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public 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_BITMAP = &H4&

Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

Public Const MIIM_ID = &H2
Public Const MIIM_TYPE = &H10
Public Const MFT_STRING = &H0&


Then, in the form you have the menu, put the following code in the event you want (you will probably prefer form_load )

'Get the menuhandle of your app
hMenu& = GetMenu(Form1.hwnd)

'Get the handle of the first submenu
hSubMenu& = GetSubMenu(hMenu&, 0)

'Get the menuId of the first entry
hID& = GetMenuItemID(hSubMenu&, 0)'Add the bitmap
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
Picture1.Picture, _
Picture1.Picture

You can add two bitmaps to a menuentry, one for the checked and one for the unchecked
state.

Hope that helps!

Collapse -

Pictures in Menu bar

by juanja In reply to Pictures in Menu bar

I posted this question twice, because in the first one I forgot to mention the PICTURE1 picture box.

(just in case you find it to be a problem...)

Collapse -

Pictures in Menu bar

by isvanand In reply to Pictures in Menu bar

The question was auto-closed by TechRepublic

Collapse -

Pictures in Menu bar

by juanja In reply to Pictures in Menu bar

Add a module, and put the following code inside:

Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public Declare FunctionGetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Public 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_BITMAP = &H4&

Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

Public Const MIIM_ID = &H2
Public Const MIIM_TYPE = &H10
Public Const MFT_STRING = &H0&


Then, in the form you have the menu, add a picture box named picture1 (default) with Autosize = true, set the picture property to a bitmap, put the following code in the event you want (you will probably prefer form_load )

'Get the menuhandle of your app
hMenu& = GetMenu(Form1.hwnd)

'Get the handle of the first submenu
hSubMenu& = GetSubMenu(hMenu&, 0)

'Get the menuId of the first entry
hID& = GetMenuItemID(hSubMenu&, 0)

'Add the bitmap
SetMenuItemBitmaps hMenu&, hID&, MF_BITMAP, _
Picture1.Picture, _
Picture1.Picture

You can add two bitmaps to a menuentry, one for the checked and one for the unchecked
state.

Hope that helps!

Collapse -

Pictures in Menu bar

by isvanand In reply to Pictures in Menu bar

The question was auto-closed by TechRepublic

Collapse -

Pictures in Menu bar

by isvanand In reply to Pictures in Menu bar

This question was auto closed due to inactivity

Back to Web Development Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums