Instructions
- Download the ImageMenu source file from the download page and extract the two files in your project directory.
- Include the ImageMenu.h and ImageMenu.cpp files to your project. Then, add #include "ImageMenu.h" to the source file/s where you want touse ImageMenus.
- The menu can be defined from the resource file (.rc) or at runtime (works in both cases) and doesn't need to be modified before being transformed into an ImageMenu. If the menu is a main menu (the one you can set with SetMenu()), you have to call ImageMenu_Create() function and pass the handle to the window that owns the menu and then call ImageMenu_CreatePopup() with the same parameters as the previous function.
Main menu example:
HMENU mainMenu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDM_MAINMENU));
ImageButton_Create(mainHwnd, mainMenu);
Popup menu example:
HMENU popupMenu = CreatePopupMenu();
AppendMenu(popupMenu, ...);
ImageButton_CreatePopup(mainHwnd, popupMenu);
TrackPopupMenu(popupMenu, ...);
ImageButton_Remove(popupMenu);
Destroymenu(popupMenu);
- Now you can personalize your menu, using the functions listed in the documentation.
- To set images to items, there's only one function that handle all the cases: ImageMenu_SetItemImage(...). This function can load images from file, from resources or from handle. Examples:
IMITEM imi;
imi.mask = IMIF_LOADFROMRES|IMIF_ICON;
imi.hInst = GetModuleHandle(NULL);
imi.itemID = IDPMC_CUT;
imi.imageStr = MAKEINTRESOURCE(IDI_CUT);
ImageMenu_SetItemImage(&imi);
imi.mask = IMIF_LOADFROMFILE|IMIF_BITMAP;
imi.itemID = IDPMC_COPY;
imi.imageStr = "copy.bmp";
ImageMenu_SetItemImage(&imi);
- To change the current menu style, you can call ImageMenu_SetStyle(...):
void ImageMenu_SetStyle(int newMenuStyle);
Example:
ImageMenu_SetStyle(OFFICE2003);
The styles are listed in a enum in the ImageMenu.h file. You can modify this enum, but this list should correspond to
the members of the styleProps array.
- To set a menu title you can call three function. The first one can do what the other two can do separately:
BOOL ImageMenu_SetMenuProps(MENUPROPS *mp);
BOOL ImageMenu_SetMenuTitleProps(HMENU menuHandle, LPTSTR title, BOOL isVerticalTitle, COLORREF textColor);
BOOL ImageMenu_SetMenuTitleBkProps(HMENU menuHandle, COLORREF firstColor, COLORREF secondColor, BOOL isGradient, BOOLisVerticalGradient);
Examples:
MENUPROPS mp;
mp.flags = MPF_TITLE|MPF_VERTICALTITLE;
mp.menuHandle = popupMenu;
mp.menuTitle = _T("Edit");
ImageMenu_SetMenuProps(&mp);
ImageMenu_SetMenuTitleProps(titleMenu, _T("Styles"), TRUE);
ImageMenu_SetMenuTitleBkProps(titleMenu, RGB(255,237,213), RGB(255,186,94), TRUE, TRUE);
This page was last modified
40 months, 4 days and 20 hours ago