Solved

Menu item with graphic?

Posted on 1998-03-29
1
372 Views
Last Modified: 2008-02-01
I am using Borland C++ Builder v3.0 (standard edition).  I would like to have bitmap images next to my menu items.  For example look at your internet browser's menu bar click on File, well I would like to have a small image next to the exit command in my program.  I know this is possible, I have seen it in Bug Collector Pro (www.nesbitts.com).

thanks
0
Comment
Question by:stevenc317
1 Comment
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 50 total points
ID: 1183926
Take a look at ModifyMenu, that will do the work. You can get the menu handle by GetMenu, and modify it with ModifyMenu with the CF_BITMAP flag


 
The ModifyMenu function changes an existing menu item. This function is used to specify the content, appearance, and behavior of the menu item.
Windows 95 only: The ModifyMenu function has been superseded by the SetMenuItemInfo function. You can still use ModifyMenu, however, if you do not need any of the extended features of SetMenuItemInfo.
BOOL ModifyMenu(
 

    HMENU hMnu,      // handle of menu
    UINT uPosition,      // menu item to modify
    UINT uFlags,      // menu item flags
    UINT uIDNewItem,      // menu item identifier or pop-up menu handle
    LPCTSTR lpNewItem      // menu item content
   );      
Parameters
hMnu
Identifies the menu to be changed.
uPosition
Specifies the menu item to be changed, as determined by the uFlags parameter.
uFlags
Specifies flags that control the interpretation of the uPosition parameter and the content, appearance, and behavior of the menu item. This parameter must be a combination of one of the following required values and at least one of the values listed in the following Remarks section.
 
Value      Meaning

MF_BYCOMMAND      Indicates that the uPosition parameter gives the identifier of the menu item. The MF_BYCOMMAND flag is the default if neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified.
MF_BYPOSITION      Indicates that the uPosition parameter gives the zero-based relative position of the menu item.
uIDNewItem
Specifies either the identifier of the modified menu item or, if uFlags is set to the MF_POPUP flag, the handle of the pop-up menu.
lpNewItem
Points to the content of the changed menu item. The interpretation of this parameter depends on whether the uFlags parameter includes the MF_BITMAP, MF_OWNERDRAW, or MF_STRING flag.
 
Value      Meaning

MF_BITMAP      Contains a bitmap handle.
MF_OWNERDRAW      Contains a 32-bit value supplied by an application that is used to maintain additional data related to the menu item. The value is in the itemData member of the structure pointed to by the lparam parameter of the WM_MEASUREITEM or WM_DRAWITEM messages sent when the menu item is created or its appearance is updated.
MF_STRING      Contains a pointer to a null-terminated string (the default).
Return Values
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
If ModifyMenu replaces a menu item that activates a pop-up menu, the function destroys the old pop-up menu and frees the memory used by it.
The application must call the DrawMenuBar function whenever a menu changes, whether or not the menu is in a displayed window. To change the attributes of existing menu items, it is much faster to use the CheckMenuItem and EnableMenuItem functions.
The following list describes the flags that may be set in the uFlags parameter:
 
Value      Meaning

MF_BITMAP      Uses a bitmap as the menu item. The lpNewItem parameter contains the handle of the bitmap.
MF_BYCOMMAND      Indicates that the uPosition parameter specifies the identifier of the menu item (the default).
MF_BYPOSITION      Indicates that the uPosition parameter specifies the zero-based relative position of the new menu item.
MF_CHECKED      Places a check mark next to the item. If your application provides check mark bitmaps (see the SetMenuItemBitmaps function), this flag displays a checked bitmap next to the menu item.
MF_DISABLED      Disables the menu item so that it cannot be selected, but this flag does not gray it.
MF_ENABLED      Enables the menu item so that it can be selected and restores it from its grayed state.
MF_GRAYED      Disables the menu item and grays it so that it cannot be selected.
MF_MENUBARBREAK      Functions the same as the MF_MENUBREAK flag, except for pop-up menus where the new column is separated from the old column by a vertical line.
MF_MENUBREAK      Places the item on a new line (for menu bars) or in a new column (for pop-up menus) without separating columns.
MF_OWNERDRAW      Specifies that the item is an owner-drawn item. Before the menu is displayed for the first time, the window that owns the menu receives a WM_MEASUREITEM message to retrieve the width and height of the menu item. The WM_DRAWITEM message is then sent to the window procedure of the owner window whenever the appearance of the menu item must be updated.
MF_POPUP      Specifies that the menu item is a pop-up item; that is, selecting it activates a pop-up menu. The uIDNewItem parameter specifies the handle of the pop-up menu. This flag is used to add a pop-up item to a menu bar or to a pop-up menu.
MF_SEPARATOR      Draws a horizontal dividing line. This flag is used only in a pop-up menu. The dividing line cannot be grayed, disabled, or highlighted. The lpNewItem and uIDNewItem parameters are ignored.
MF_STRING      Specifies that the menu item is a text string; the lpNewItem parameter points to the string.
MF_UNCHECKED      Does not place a check mark next to the item (the default). If your application supplies check mark bitmaps (see the SetMenuItemBitmaps function), this flag displays an unchecked bitmap next to the menu item.
The following list shows groups of flags that cannot be used together:
7      MF_BYCOMMAND and MF_BYPOSITION
7      MF_DISABLED, MF_ENABLED, and MF_GRAYED
7      MF_BITMAP, MF_STRING, MF_OWNERDRAW, and MF_SEPARATOR
7      MF_MENUBARBREAK and MF_MENUBREAK
7      MF_CHECKED and MF_UNCHECKED
 
See Also
AppendMenu, CheckMenuItem, DrawMenuBar, EnableMenuItem, SetMenuItemBitmaps, SetMenuItemInfo, WM_DRAWITEM, WM_MEASUREITEM

 

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now