WinapiZone.net




Extensions > ImageMenu > Instructions

Instructions

  1. Download the ImageMenu source file from the download page and extract the two files in your project directory.
  2. 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.
  3. 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, ...);
    //Remember to call it before calling DestroyMenu!
    ImageButton_Remove(popupMenu);

    Destroymenu(popupMenu);

  4. 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:
      //This function can set both menu's title and background properties
      BOOL ImageMenu_SetMenuProps(MENUPROPS *mp);
      //This function can set the menu's title properties
      BOOL ImageMenu_SetMenuTitleProps(HMENU menuHandle, LPTSTR title, BOOL isVerticalTitle, COLORREF textColor);
      //This function can set the menu's title background properties
      BOOL ImageMenu_SetMenuTitleBkProps(HMENU menuHandle, COLORREF firstColor, COLORREF secondColor, BOOL isGradient, BOOLisVerticalGradient);
      Examples:
      //Vertical title, default background (that is, background isn't set)
      MENUPROPS mp;
      mp.flags = MPF_TITLE|MPF_VERTICALTITLE;
      mp.menuHandle = popupMenu;
      mp.menuTitle = _T("Edit");
      ImageMenu_SetMenuProps(&mp);

      //Vertical title, vertical gradient background)
      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