CWnd::OnDrawItem

Syntax

afx_msg void OnDrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );

Parameters

lpDrawItemStruct

Specifies a long pointer to a DRAWITEMSTRUCT data structure that contains information about the item to be drawn and the type of drawing required.

Remarks

Called for the owner of an owner-draw button control, combo-box control, list-box control, or menu when a visual aspect of the control or menu has changed.

The itemAction member of the DRAWITEMSTRUCT structure defines the drawing operation that is to be performed. The data in this member allows the owner of the control to determine what drawing action is required.

Before returning from processing this message, an application should ensure that the device context identified by the hDC member of the DRAWITEMSTRUCT structure is restored to the default state.

A DRAWITEMSTRUCT structure has this form:

typedef struct tagDRAWITEMSTRUCT {

WORD CtlType;

WORD CtlID;

WORD itemID;

WORD itemAction;

WORD itemState;

HWND hwndItem;

HDC hDC;

RECT rcItem;

DWORD itemData;

} DRAWITEMSTRUCT;

Members

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

The control ID for a combo box, list box, or button. This member is not used for a menu.

itemID

The menu-item ID for a menu or the index of the item in a list box or combo box. For an empty list box or combo box, this member can be -1. This allows the application to draw only the focus rectangle at the coordinates specified by the rcItem member even though there are no items in the control. This indicates to the user whether the list box or combo box has input focus. The setting of the bits in the itemAction member determines whether the rectangle is to be drawn as though the list box or combo box has input focus.

itemAction

Defines the drawing action required. This will be one or more of the following bits:

Value Meaning

ODA_DRAWENTIRE This bit is set when the entire control needs to be drawn.
ODA_FOCUS This bit is set when the control gains or loses input focus. The itemState member should be checked to determine whether the control has focus.
ODA_SELECT This bit is set when only the selection status has changed. The itemState member should be checked to determine the new selection state.

itemState

Specifies the visual state of the item after the current drawing action takes place. That is, if a menu item is to be dimmed, the state flag ODS_GRAYED will be set. The state flags are:

Value Meaning

ODS_CHECKED This bit is set if the menu item is to be checked. This bit is used only in a menu.
ODS_DISABLED This bit is set if the item is to be drawn as disabled.
ODS_FOCUS This bit is set if the item has input focus.
ODS_GRAYED This bit is set if the item is to be dimmed. This bit is used only in a menu.
ODS_SELECTED This bit is set if the item's status is selected.

hwndItem

For combo boxes, list boxes and buttons, this member specifies the window handle of the control; for menus, it contains the handle of the menu (HMENU) containing the item.

hDC

Identifies a device context; this device context must be used when performing drawing operations on the control.

rcItem

A rectangle in the device context specified by the hDC member that defines the boundaries of the control to be drawn. Windows automatically clips anything the owner draws in the device context for combo boxes, list boxes, and buttons, but does not clip menu items. When drawing menu items, the owner must ensure that the owner does not draw outside the boundaries of the rectangle defined by the rcItem member.

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

This message-handler member function calls Default. Override this member function in your derived class to handle the WM_DRAWITEM message.

See Also

DRAWITEMSTRUCT, CWnd::Default, WM_DRAWITEM, CWnd::FromHandle, ::FromHandle