Click here to Skip to main content
11,925,896 members (59,872 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked

Using Icons in the Menus VB!

, 15 Apr 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
Add icons in the menus of your applications developed in VB 6.0
Sample Image - VBMenuIcon.jpg


Here I am again, with other programming trick. VB doesn't provide any support for icons in the menus (VB 6 and previous). Then, to accomplish such a task, it is necessary to run over to call native API of Windows.


Some programmers say that is unnecessary. But it is common for the users to use the toolbar in most of the cases. It is interesting that they can associate the menu options to the entrances in the toolbar.

For an application to be easy to use, it should be the most friendliest possible and not demand complex reasoning of the user.

The people use computers to activate your tasks and to win time.

The Road of the Stones

The best way to accomplish this task would be with a visual atmosphere where you could choose in the list of available menus, the item of wanted menu and in others (parallel), the wanted icon (that is made by other tools).

However, I will teach the less friendly, however functional way of making it.


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&

Code Piece

Private Sub SetMenuIcon()
On Error Resume Next
Dim hMenu As Long
Dim hSubMenu As Long
Dim Ret As Long
'Get main menu ID
hMenu = GetMenu(hwnd)
'Get sub menu 0 (File items)
hSubMenu = GetSubMenu(hMenu, 0)
'set bitmap to menu item, by ordinal
Ret = SetMenuItemBitmaps(hSubMenu, 0, MF_BYPOSITION, iNew.Picture, iNew.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 1, MF_BYPOSITION, iOpen.Picture, iOpen.Picture)
Ret = SetMenuItemBitmaps(hSubMenu, 2, MF_BYPOSITION, iSave.Picture, iSave.Picture)
'Skip the separator (it's 3)
Ret = SetMenuItemBitmaps(hSubMenu, 4, MF_BYPOSITION, iSave.Picture, iSave.Picture)
'Skip the separator (it's 5)
Ret = SetMenuItemBitmaps(hSubMenu, 6, MF_BYPOSITION, iExit.Picture, iExit.Picture)
' The rest of the code was removed to maintain clear.  
' See in the file 'ZIP the complete and functional example.
End Sub

The icon may be 14x15 pixels.

If you have some doubt or suggestions, send me an email.

Contact Details

ICQ# 89506722
Phone: +55 (64) 612-6030
Fax: +55 (64) 612-6010


  • 15th April, 2004: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Brazil Brazil
- MS VB6
- C/C++/C#
- VBScript
- JScript
- Clipper
- Cobol
- Natural
- Pascal
- TCL/Tk
- Python
Willian Silva Rodrigues
--- --- --- ---
BBM PIN: 238d4349

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
almendietamor9-Jan-15 8:13
memberalmendietamor9-Jan-15 8:13 
GeneralNice! Pin
brco695-Jul-14 12:01
memberbrco695-Jul-14 12:01 
GeneralMy vote of 5 Pin
Member 954013923-Oct-12 12:32
memberMember 954013923-Oct-12 12:32 
Questionhow to add copy button Pin
HARDEEP_SAINI30-Mar-12 21:06
memberHARDEEP_SAINI30-Mar-12 21:06 
Generalthanks Pin
cyd_vane26-Jun-07 3:11
membercyd_vane26-Jun-07 3:11 
GeneralNot going to work Pin
Alkali_Guy16-Aug-06 22:24
memberAlkali_Guy16-Aug-06 22:24 
GeneralImages not fit on menu... Pin
A_Vietnamese29-Jun-04 13:48
memberA_Vietnamese29-Jun-04 13:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 16 Apr 2004
Article Copyright 2004 by WillianBR
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid