Click here to Skip to main content
12,824,787 members (41,138 online)
Click here to Skip to main content
Add your own
alternative version


48 bookmarked
Posted 14 Nov 2002

Adding Images to Menu

, 14 Nov 2002
Rate this:
Please Sign up or sign in to vote.
Adding images to MenuItems


This is a simple program which loads a picture to menu controls. MenuItem controls don't have an Image property to load an image. So the only way to do this is by calling Windows API functions. The following are the API functions used. All functions are from User32.dll.

    public static extern IntPtr GetMenu(IntPtr hwnd);
    public static extern IntPtr GetSubMenu(IntPtr hMenu,int nPos);
    public static extern IntPtr GetMenuItemID(IntPtr hMenu, int nPos);
    public static extern int SetMenuItemBitmaps(IntPtr hMenu, IntPtr nPosition, 
        int wFlags, IntPtr hBitmapUnchecked, IntPtr hBitmapChecked);

The Code

intptrMenu = GetMenu(this.Handle);

First get the pointer to the current form's menu.

intptrSubMenu = GetSubMenu(intptrMenu, 0);

Then get the pointer to the first menu's submenu list.

intptrMenuItemID = GetMenuItemID(intptrSubMenu, 0);

In the above code, 0 is the first MenuItem in the submenu list. Thus get the pointer to the first MenuItem .

intRet = SetMenuItemBitmaps(intptrMenu, intptrMenuItemID, 0 ,intp, intp);

intp is the handle to a bitmap. SetMenuItemBitmaps sets the image from the handle to the MenuItem. So when you run the code, no images are loaded.

Then when you hit the LoadImage button, the images get loaded to the menu items.

Have Fun!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
Deva Anbu Daniel is an Application Developer with 2+ years experience in Java,VB and C#. Currently working in His favorite language is C. He's a major fan of Iron Maiden and Metallica and Jethro Tull.

You may also be interested in...


Comments and Discussions

Generalit have error Pin
wangqiang01515-Apr-07 0:16
memberwangqiang01515-Apr-07 0:16 
Generalcontext menus Pin
gorcq28-Feb-07 20:42
membergorcq28-Feb-07 20:42 
GeneralRe: context menus Pin
gorcq1-Mar-07 20:00
membergorcq1-Mar-07 20:00 
Generala simplified method Pin
Justin Alexander13-Sep-04 6:45
memberJustin Alexander13-Sep-04 6:45 
GeneralTransparence Pin
matrix6666-Aug-04 1:18
membermatrix6666-Aug-04 1:18 
GeneralRe: Transparence Pin
ericsmith1-Apr-05 13:27
memberericsmith1-Apr-05 13:27 
GeneralDr. Gui's answer Pin
sds11-Dec-03 7:46
membersds11-Dec-03 7:46 
GeneralImage size Pin
Watson3921-Jan-03 9:23
memberWatson3921-Jan-03 9:23 
GeneralRe: Image size Pin
Marvin Tsai9-Aug-07 23:56
memberMarvin Tsai9-Aug-07 23:56 
GeneralUse invisible toolbar Pin
Anonymous18-Nov-02 22:09
sussAnonymous18-Nov-02 22:09 
GeneralRe: Use invisible toolbar Pin
Sue McNaughtan19-Nov-02 1:34
memberSue McNaughtan19-Nov-02 1:34 
Questioncolor bitmaps? Pin
Marc Clifton15-Nov-02 16:50
memberMarc Clifton15-Nov-02 16:50 
Generalgreat job Pin
ashley_vg15-Nov-02 15:35
memberashley_vg15-Nov-02 15:35 
GeneralRe: great job Pin
SeeSharp18-Nov-02 22:12
memberSeeSharp18-Nov-02 22:12 
GeneralNative C#, Pin
Jerry Maguire15-Nov-02 3:33
memberJerry Maguire15-Nov-02 3:33 
GeneralRe: Native C#, Pin
mammiebubba15-Nov-02 21:33
membermammiebubba15-Nov-02 21:33 
GeneralRe: Native C#, Pin
Jerry Maguire16-Nov-02 5:44
memberJerry Maguire16-Nov-02 5:44 
GeneralRe: Native C#, Pin
Jamie Nordmeyer18-Nov-02 6:03
memberJamie Nordmeyer18-Nov-02 6:03 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 15 Nov 2002
Article Copyright 2002 by SeeSharp
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid