MenuBmp.exe Contains Owner-Draw Menus with Bitmaps
ID: Q71061
|
The information in this article applies to:
-
Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1
-
Microsoft Windows 2000
SUMMARY
When an application creates an owner-draw menu item with the MF_OWNERDRAW
style, the application receives a WM_MEASUREITEM message for that item. The
application is required to fill the MEASUREITEMSTRUCT pointed to by the
lParam of this message.
The itemWidth field of the MEASUREITEMSTRUCT is normally filled with the
actual width of the item. However, when Windows displays that menu item,
the width is increased by the width of a check mark; that is, Windows
automatically expands the item to leave space for a check mark.
To make the menu item only as wide as the actual item, fill the itemWidth
field with the width of the item, minus the width of a check mark, as
returned by GetMenuCheckMarkDimensions().
MenuBmp.exe is a sample that contains an example of owner-draw menus with
bitmaps where each item is only as large as the bitmap.
MORE INFORMATION
The following files are available for download from the Microsoft
Download Center. Click the file names below to download the files:
MenuBmp.exe
For more information about how to download files from the Microsoft
Download Center, please visit the Download Center at the following Web
address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.
The following code fragment demonstrates processing a WM_MEASUREITEM
message that results in a menu item only as wide as the actual item. In
this case, the menu is being made with bitmaps. The handle to the bitmap is
stored as part of the item data.
// Local variables.
LPMEASUREITEMSTRUCT lpItem;
HBITMAP hBitmap;
BITMAP bm;
WORD cxCheck;
...
case WM_MEASUREITEM:
// lParam is a pointer to the structure.
lpItem = (LPMEASUREITEMSTRUCT)lParam;
// A bitmap handle was stored in the item data.
hBitmap = LOWORD(lpItem->itemData);
/*
* The width of a check mark is automatically added to
* menu items so we need to subtract it to make the
* menu the minimum size.
*/
cxCheck = LOWORD(GetMenuCheckMarkDimensions());
// Get the bitmap dimensions
GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm);
// Set the width to the width of the bitmap - cxCheck
lpItem->itemWidth = bm.bmWidth - cxCheck;
// Add one to the bitmap height for some spacing.
lpItem->itemHeight = bm.bmHeight + 1;
break;
...
Additional query words:
Keywords : kbcode kbfile kbsample kbMenu kbWinOS2000 kbGrpUser kbWinOS310 kbWinOS300
Version : WINDOWS:3.0,3.1
Platform : WINDOWS
Issue type :