WinapiZone.net




Extensions > ImageMenu > Docs

Documentation

Click the function links to see the prototype, the function parameters, the return values and the remarks. Click it again to hide it.

Menu creation


ImageMenu_Create
Sets the ownerdraw flags for main menus. Compare with ImageMenu_CreatePopup(..).
Prototype BOOL ImageMenu_Create(HWND hwnd, HMENU menuHandle, BOOL isMenuBar = TRUE);
Parameters
hwnd
[IN] Handle to the window that owns this menu. Do not set this parameter to NULL.
menuHandle
[IN] Handle to the menu to modify.
isMenuBar
[IN] TRUE by default. Must be TRUE if the menu is a main menu (= the first row of items are from the main menu bar)
Return values
TRUE
Menu has been modified.
FALSE
An error has occurred.
Remarks It's not needed, but it's not harmful, to call ImageMenu_Remove(...) with a main menu when you close your application. In fact, ImageMenu will take care of it automatically.
ImageMenu_CreatePopup
Sets the ownerdraw flags for popup menus. Compare with ImageMenu_Create(..).
Prototype BOOL ImageMenu_CreatePopup(HWND hwnd, HMENU menuHandle);
Parameters
hwnd
[IN] Handle to the window that owns this menu. Do not set this parameter to NULL.
menuHandle
[IN] Handle to the menu to modify.
Return values
TRUE
Menu has been modified.
FALSE
An error has occurred.
Remarks If you create and destroy a popup menu more than once, you need to call ImageMenu_Remove(...) before DestroyMenu(..). If you do not, you may experience unexpected behavior.

ImageMenu_Remove
Remove a menu from the vector.
Prototype void ImageMenu_Remove(HMENU menuHandle);
Parameters
menuHandle
[IN] Handle to the menu to be removed
Return values No return values
Remarks Always use this function before DestroyMenu.
ImageMenu_AddItem
Add a menu item in a menu.
Prototype BOOL ImageMenu_AddItem(HMENU itemMenu, HMENU itemSubMenu, HWND itemParentWnd, int itemPos, BOOL isMenuBarItem);
Parameters
itemMenu
[IN] Handle to the menu that contains this new menuitem
itemSubMenu
[IN] Handle to the menuitem's submenu (NULL if it doesn't exists)
itemParentWnd
[IN] Handle to itemMenu's parent window
itemPos
[IN] Menu item position
isMenuBarItem
[IN] TRUE if the new menuitem is a menubar item
Return values
TRUE
Menuitem has been added
FALSE
An error has occurred.
Remarks None

Images


IMITEMIMAGE structure
Struct used with ImageMenu_SetItemImage(...).
Prototype typedef struct tagIMITEMIMAGE
{
    tagIMITEMIMAGE() : mask(0), itemID(0), imageStr(NULL), hInst(NULL), normalIcon(NULL), normalBitmap(NULL) { }
    
    UINT mask;
    UINT itemID;
    LPTSTR imageStr;
    HINSTANCE hInst;
    HICON normalIcon;
    HBITMAP normalBitmap;
} IMITEMIMAGE;
Members
mask
[IN] Can be one or more of the following values:
  • IMIMF_LOADFROMRES: load images from resources.
  • IMIMF_LOADFROMFILE: load images from a file.
  • IMIMF_ICON: the image is an icon.
  • IMIMF_BITMAP: the image is a bitmap.
  • IMIMF_NOIMAGE: remove any image.
The possible combinations are:
  • IMIMF_LOADFROMRES|IMIMF_ICON: load an icon from resources. Valid members: hInst and imageStr.
  • IMIMF_LOADFROMRES|IMIMF_BITMAP: load a bitmap from resources. Valid members: hInst e imageStr.
  • IMIMF_LOADFROMFILE|IMIMF_ICON: load an icon from a file. Valid members: imageStr.
  • IMIMF_LOADFROMFILE|IMIMF_BITMAP: load a bitmap from a file. Valid members: imageStr.
  • IMIMF_ICON: you must pass a handle to an icon (HICON). Valid members: normalIcon.
  • IMIMF_BITMAP: you must pass a handle to a bitmap (HBITMAP). Valid members: normalBitmap.
itemID
[IN] ID of the menu item to modify.
imageStr
[IN] Is a valid member only when flags contains IMIMF_LOADFROMRES or IMIMF_LOADFROMFILE. Can be:
  • the string version of the ID (you can obtain it with the MAKEINTRESOURCE(..) macro) if flags contains IMI_LOADFROMRES
  • the path to the image file if flags contains IMIMF_LOADFROMFILE
hInst
[IN] Handle to the instance where the specified (imageStr) resource is. hInst is valid only when flags contains IMIMF_LOADFROMRES and one between IMIMF_ICON and IMIMF_BITMAP.
normalIcon
[IN] Handle to an icon. normalIcon is valid only when flags contains only IMIMF_ICON.
normalBitmap
[IN] Handle to a bitmap. normalBitmap is valid only when flags contains only IMIMF_BITMAP.
Remarks This structure has a constructor, so you don't need to initialize it with ZeroMemory or memset.
ImageMenu_SetItemImage
Sets images to item.
Prototype BOOL ImageMenu_SetItemImage(IMITEMIMAGE* imi);
Parameters
imi
[IN] Pointer to a IMITEMIMAGE structure that contains the new properties of the menu.
Return values
TRUE
The image has been set to the item.
FALSE
An error has occurred.
Remarks None

Styles


ImageMenu_SetStyle
Sets the new menu style.
Prototype void ImageMenu_SetStyle(int newMenuStyle);
Parameters
newMenuStyle
[IN] The new stile of the menus. The list of these styles is inside the ImageMenu.h file. Base styles are:
  • BASIC: default windows colors
  • GRAY: vertical gray gradient style
  • OFFICE: office old menu style
  • OFFICE2003: office 2003 menu style
  • OFFICE2007: office 2003 menu style
Return values No return values.
Remarks The complete list of the styles is stored in an enum in the ImageMenu.h file.

Menu titles


IMMENUPROPS structure
Struct used with ImageMenu_SetMenuProps(...).
Prototype typedef struct tagIMMENUPROPS
{
    tagIMMENUPROPS() : menuHandle(NULL), flags(0), menuTitle(_T("")), textColor(RGB(255,255,255)), firstColor(0), secondColor(0) { }
    
    HMENU menuHandle;
    DWORD flags;
    tstring menuTitle;
    COLORREF textColor;
    COLORREF firstColor;
    COLORREF secondColor;
    
    BOOL IsGradient() { return flags&MPF_HORZGRADIENT||flags&MPF_VERTGRADIENT;}
    BOOL IsVertGradient() { return flags&MPF_VERTGRADIENT; }
    BOOL IsVertTitle() { return flags&MPF_VERTICALTITLE; }
    BOOL IsCustomBkColor() { return !IsGradient() && flags&MPF_CUSTOMBKCOLOR; }
} IMMENUPROPS;
Members
menuHandle
[IN] Handle to the menu to be modified.
flags
[IN] Can be one of the following values:
  • IMPF_TITLE: menuTitle and textColor are valid members and can be filled.
  • IMPF_VERTICALTITLE: the title is drawn vertically.
  • IMPF_BKGND: firstColor and secondColor are valid members and can be filled.
  • IMPF_CUSTOMBKCOLOR: firstColor is a valid member, secondColor shouldn't be filled.
  • IMPF_HORZGRADIENT: the background of the title is a horizontal gradient with the colors defined by firstColor and secondColor.
  • IMPF_VERTGRADIENT: the background of the title is a vertical gradient with the colors defined by firstColor and secondColor.
These values can't be mixed:
  • IMPF_CUSTOMBKCOLOR and IMPF_HORZGRADIENT/IMPF_VERTGRADIENT.
  • IMPF_HORZGRADIENT and IMPF_VERTGRADIENT.
menuTitle
[IN] Menu title.
textColor
[IN] Title color. You can obtain this value with the RGB() macro.
firstColor
[IN] Title background color, or first gradient color.
secondColor
[IN] Second gradient color. It's a valid member only if flags has MPF_HORZGRADIENT or MPF_VERTGRADIENT values.
Remarks This structure has a constructor, so you don't need to initialize it with ZeroMemory or memset.

ImageMenu_SetMenuProps
Set menu's title and background properties.
Prototype void ImageMenu_SetMenuProps(IMMENUPROPS *mp);
Parameters
mp
[IN] Pointer to a IMMENUPROPS structure that contains all the properties of the title and its background.
Return values No return values.
Remarks None
ImageMenu_SetMenuTitleProps
Set only the menu's title properties.
Prototype void ImageMenu_SetMenuTitleProps(HMENU menuHandle, LPTSTR title, BOOL isVerticalTitle, COLORREF textColor);
Parameters
menuHandle
[IN] Handle to the menu to be modified.
title
[IN] Menu title.
isVerticalTitle
[IN] Set this parameter to TRUE if you want a vertical title, FALSE if you want the title to be on top of your menu.
textColor
[IN] Menu title color (default value: white)
Return values No return values.
Remarks None
ImageMenu_SetMenuTitleBkProps
Set only the menu's title background properties.
Prototype void ImageMenu_SetMenuTitleBkProps(HMENU menuHandle, COLORREF firstColor, COLORREF secondColor, BOOL isGradient, BOOL isVerticalGradient);
Parameters
menuHandle
[IN] Handle to the menu to be modified.
firstColor
[IN] Title background color, or first gradient color. You can obtain this value with the RGB() macro.
secondColor
[IN] Second gradient color, valid only when isGradient is TRUE.
isGradient
[IN] TRUE if you want a gradient, FALSE if you want only a color as background. If it's TRUE, secondColor can be filled.
isVerticalGradient
[IN] Valid only when isGradient is TRUE. Set it to TRUE if you want a vertical gradient, or FALSE if you want a horizontal gradient.
Return values No return values.
Remarks None
This page was last modified 32 months, 2 weeks, 6 days and 2 hours ago