Pictures in Menu bar
Hi All,
How would u add a Picture/Icons to your menus in a Visual basic Application
Vijay.
Web Development
Hi All,
How would u add a Picture/Icons to your menus in a Visual basic Application
Vijay.
by juanja
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!
by juanja
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!
by isvanand
by isvanand
This discussion is closed to new replies.
Sort by Trending