SAMPLE: Owner-Draw Menu Item Width Includes a Check Mark WidthLast reviewed: February 15, 1996Article ID: Q71061 |
The information in this article applies to:
SUMMARYWhen 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(). The Microsoft Software Library contains an example, MENUBMP, of owner-draw menus with bitmaps where each item is only as large as the bitmap. Download MENUBMP.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
MORE INFORMATIONThe 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 reference words: 3.00 3.10 softlib MENUBMP.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |