March 3, 2021
Hot Topics:

Adding Bitmaps to Menus

  • By John Percival
  • Send Email »
  • More Articles »

This tip explains how to add bitmap pictures to menu items.


Add the following code to the_ declarations section of_ a module:

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&

    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

Declare Function GetMenuItemCount Lib_
     "user32" _
(ByVal hMenu As Long) As Long

Declare Function GetMenuItemInfo Lib_
     "user32" _
Alias "GetMenuItemInfoA"_
     (ByVal hMenu As Long, _
ByVal un As Long, ByVal b As Boolean, _
lpMenuItemInfo As MENUITEMINFO) As Boolean

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


  • Add one form to the project.
  • Add a picturebox (Autosize = True)_ with a bitmap (not an icon!!!),_ max. 13X13
  • Add a commandbutton with following code:
Private Sub Command1_Click()

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

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

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

' Add the bitmap

SetMenuItemBitmaps hMenu&, hID&,_
Picture1.Picture, _
' You can add two bitmaps to a menuentry
' One for the checked and one for the unchecked
' state.

End Sub
  • Run the Project and click the button.

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date