afx_msg void OnMeasureItem
(LPMEASUREITEMSTRUCT lpMeasureItemStruct );
lpMeasureItemStruct
Specifies a long pointer to a MEASUREITEMSTRUCT data structure that contains the dimensions of the owner-draw control.
Called for the owner of an owner-draw button, combo box, list box, or menu item when the control is created. When the owner receives the call, the owner should fill in the MEASUREITEMSTRUCT data structure pointed to by lpMeasureItemStruct and return; this informs Windows of the dimensions of the control and allows Windows to process user interaction with the control correctly.
If a list box or combo box is created with the LBS_OWNERDRAWVARIABLE or CBS_OWNERDRAWVARIABLE style, this function is called for the owner for each item in the control; otherwise, this function is called once.
Windows calls OnMeasureItem for the owner of combo boxes and list boxes created with the OWNERDRAWFIXED style before sending the WM_INITDIALOG message. As a result, when the owner receives this call, Windows has not yet determined the height and width of the font used in the control; function calls and calculations requiring these values should occur in the main function of the application or library.
a MEASUREITEMSTRUCT data structure has the following form:
typedef struct tagMEASUREITEMSTRUCT {
WORD CtlType;
WORD CtlID;
WORD itemID;
WORD itemWidth;
WORD itemHeight;
DWORD itemData
CtlType
Is the control type. The values for control types are as follows:
Value | Meaning |
ODT_BUTTON | Owner-draw button. |
ODT_COMBOBOX | Owner-draw combo box. |
ODT_LISTBOX | Owner-draw list box. |
ODT_MENU | Owner-draw menu. |
CtlID
Is the control ID for a combo box, list box, or button. This member is not used for a menu.
itemID
Is the menu-item ID for a menu or the list box item ID for a variable-height combo box or list box. This member is not used for a fixed-height combo box or list box, or for a button.
itemWidth
Specifies the width of a menu item. The owner of the owner-draw menu item must fill this member before returning from the message.
itemHeight
Specifies the height of an individual item in a list box or a menu. Before returning from the message, the owner of the owner-draw combo box, list box, or menu item must fill out this member. The maximum height of a list box item is 255.
itemData
For a combo box or list box, this member contains the value that was passed to the list box by one of the following:
CComboBox::AddString CComboBox::InsertString ListBox::AddString ListBox::InsertString
For a menu, this member contains the value that was passed to the menu by one of the following:
CMenu::AppendMenu CMenu::InsertMenu CMenu::ModifyMenu
Failure to fill out the proper members in the MEASUREITEMSTRUCT structure will cause improper operation of the control.
This message-handler member function calls the Default member function. Override this member function in your derived class to handle the WM_MEASUREITEM message.
WM_INITDIALOG, CWnd::Default, WM_MEASUREITEM