Date: 02-16-2022
Return to Index
created by gbSnippets
'Allows drawing of any aspect of a control.
'The code for Owner Draw is placed in the %WM_DrawItem message response code.
%WM_DrawItem Arguments:
CB.lParam = Control ID
CB.wParam = Pointer to DrawItemStruct
'Works with these controls:
button, combobox, static, listview, menu, listbox, TAB
'Owner Draw is enabled by giving the control an appropriate style.
BS_Ownerdraw Button, Check3State, CheckBox, Frame
ImgButton, ImgButtonX
CBS_OwnerDrawFixed ComboBox
CBS_OwnerDrawVariable ComboBox
SS_OwnerDraw Graphic, Image, ImageX, Label, Line
LBS_OwnerDrawFixed ListBox
LBS_OwnerDrawVariable ListBox
LVS_OwnerData ListView
LVS_OwnerDrawFixed ListView
TCS_OwnerDrawFixed TAB
Button =========================================
BS_NOTIFY
Enables a button to send BN_KILLFOCUS and BN_SETFOCUS
notification messages to its parent window.
Note that buttons send the BN_CLICKED notification message
regardless of whether it has this style. To get BN_DBLCLK
notification messages, the button must have the BS_RADIOBUTTON
or BS_OWNERDRAW style.
BS_OWNERDRAW
Creates an owner-drawn button. The owner window receives a WM_DRAWITEM
message when a visual aspect of the button has changed. Do not combine
the BS_OWNERDRAW style with any other button styles.
ComboBox ======================================
CBS_HASSTRINGS
Specifies that an owner-drawn combo box contains items consisting
of strings. The combo box maintains the memory and address for the
strings so the application can use the CB_GETLBTEXT message to
retrieve the text for a particular item.
CBS_OWNERDRAWFIXED
Specifies that the owner of the list box is responsible for drawing
its contents and that the items in the list box are all the same
height. The owner window receives a WM_MEASUREITEM message when
the combo box is created and a WM_DRAWITEM message when a visual
aspect of the combo box has changed.
CBS_OWNERDRAWVARIABLE
Specifies that the owner of the list box is responsible for drawing
its contents and that the items in the list box are variable in height.
The owner window receives a WM_MEASUREITEM message for each item in
the combo box when you create the combo box and a WM_DRAWITEM message
when a visual aspect of the combo box has changed.
ListBox =========================================
LBS_OWNERDRAWFIXED
Specifies that the owner of the list box is responsible for drawing
its contents and that the items in the list box are the same height.
The owner window receives a WM_MEASUREITEM message when the list box
is created and a WM_DRAWITEM message when a visual aspect of the list
box has changed.
LBS_OWNERDRAWVARIABLE
Specifies that the owner of the list box is responsible for drawing its
contents and that the items in the list box are variable in height. The
owner window receives a WM_MEASUREITEM message for each item in the
combobox when the combo box is created and a WM_DRAWITEM message when
a visual aspect of the combo box has changed.
ListView ==========================================
LVS_OWNERDATA
This style specifies a virtual list-view control. For more information
about this list control style, see About List-View Controls.
LVS_OWNERDRAWFIXED
The owner window can paint items in report view. The list-view control
sends a WM_DRAWITEM message to paint each item; it does not send separate
messages for each subitem. The iItemData member of the DRAWITEMSTRUCT
structure contains the item data for the specified list-view item.
Static Control ======================================
SS_OWNERDRAW
Specifies that the owner of the static control is responsible for drawing
the control. The owner window receives a WM_DRAWITEM message whenever the
control needs to be drawn.
TAB Control =======================================
TCS_OWNERDRAWFIXED
The parent window is responsible for drawing tabs.
'MESSAGES
WM_DRAWITEM
Sent to the parent window of an owner-drawn button, combo box, list box, or
menu when a visual aspect of the button, combo box, list box, or menu has changed.
WM_DRAWITEM
WPARAM wParam
lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
wParam: control ID. If menu, is zero
lParam: ptr to DRAWITEMSTRUCT. info about item to be drawn and the type of drawing required
Remarks
By default, the DefWindowProc function draws the focus rectangle for an owner-drawn list box item.
The itemAction member of the DRAWITEMSTRUCT structure specifies the drawing operation that an
application should perform.
Before returning from processing this message, an application should ensure that the device context
identified by the hDC member of the DRAWITEMSTRUCT structure is in the default state.
'STRUCTURES
DRAWITEMSTRUCT
Provides necessary information the owner window to determine how to paint an
owner-drawn control or menu item. The owner window of the owner-drawn control
or menu item receives a pointer to this structure as the lParam parameter of
the WM_DRAWITEM message.
TYPE DRAWITEMSTRUCT 'from PBWin10 includes
CtlType AS DWORD
CtlID AS DWORD
itemID AS DWORD
itemAction AS DWORD
itemState AS DWORD
hwndItem AS DWORD
hDC AS DWORD
rcItem AS RECT
itemData AS DWORD
END TYPE
CtlType
The control type. This member can be one of the following values. See Remarks.
ODT_BUTTON
Owner-drawn button
ODT_COMBOBOX
Owner-drawn combo box
ODT_LISTBOX
Owner-drawn list box
ODT_LISTVIEW
List-view control
ODT_MENU
Owner-drawn menu item
ODT_STATIC
Owner-drawn static control
ODT_TAB
Tab control
CtlID
The identifier of the combo box, list box, button, or static control.
This member is not used for a menu item.
itemID
The menu item identifier for a menu item 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 the focus. How the bits are set in the itemAction member
determines whether the rectangle is to be drawn as though the list box or
combo box has the focus.
itemAction
The required drawing action. This member can be one or more of the values.
ODA_DRAWENTIRE
The entire control needs to be drawn.
ODA_FOCUS
The control has lost or gained the keyboard focus. The itemState member
should be checked to determine whether the control has the focus.
ODA_SELECT
The selection status has changed. The itemState member should be checked to
determine the new selection state.
itemState
The visual state of the item after the current drawing action takes place.
This member can be a combination of the values shown in the following table.
ODS_CHECKED
The menu item is to be checked. This bit is used only in a menu.
ODS_COMBOBOXEDIT
The drawing takes place in the selection field (edit control) of an owner-drawn combo box.
ODS_DEFAULT
The item is the default item.
ODS_DISABLED
The item is to be drawn as disabled.
ODS_FOCUS
The item has the keyboard focus.
ODS_GRAYED
The item is to be grayed. This bit is used only in a menu.
ODS_HOTLIGHT
Windows 98/Me, Windows 2000/XP: The item is being hot-tracked,
that is, the item will be highlighted when the mouse is on the item.
ODS_INACTIVE
Windows 98/Me, Windows 2000/XP: The item is inactive and the window
associated with the menu is inactive.
ODS_NOACCEL
Windows 2000/XP: The control is drawn without the keyboard accelerator cues.
ODS_NOFOCUSRECT
Windows 2000/XP: The control is drawn without focus indicator cues.
ODS_SELECTED
The menu 's status is selected.
hwndItem
A handle to the control for combo boxes, list boxes, buttons, and static
controls. For menus, this member is a handle to the menu that contains the item.
hDC
A handle to a device context; this device context must be used when performing
drawing operations on the control.
rcItem
A rectangle that defines the boundaries of the control to be drawn. This
rectangle is in the device context specified by the hDC member. The system
automatically clips anything that the owner window draws in the device context
for combo boxes, list boxes, and buttons, but does not clip menu items. When
drawing menu items, the owner window must not draw outside the boundaries of
the rectangle defined by the rcItem member.
itemData
The application-defined value associated with the menu item. For a control,
this parameter specifies the value last assigned to the list box or combo
box by the LB_SETITEMDATA or CB_SETITEMDATA message. If the list box or
combo box has the LBS_HASSTRINGS or CBS_HASSTRINGS style, this value is
initially zero. Otherwise, this value is initially the value that was
passed to the list box or combo box in the lParam parameter of one of
the following messages:
* CB_ADDSTRING
* CB_INSERTSTRING
* LB_ADDSTRING
* LB_INSERTSTRING
If CtlType is ODT_BUTTON or ODT_STATIC, itemData is zero.
Remarks
Some control types, such as status bars, do not set the value of CtlType.
WM_MEASUREITEM
Sent to the owner window of a combo box, list box, list view control, or
menu item when the control or menu is created.
WM_MEASUREITEM
WPARAM wParam
lpMeasureItem = (LPMEASUREITEMSTRUCT) lParam;
wParam: control ID. zero if menu. if non-zero was sent by combobox or listbox
If itemID of MEASUREITEMSTRUCT –1, the message was sent by a combo edit field.
lParam: ptr to MEASUREITEMSTRUCT. dimensions of owner-drawn control or menu item.
Remarks
When the owner window receives the WM_MEASUREITEM message,
the owner fills in the MEASUREITEMSTRUCT structure pointed
to by the lpMeasureItem parameter of the message and returns;
this informs the system of the dimensions of the control.
If a list box or combo box is created with the LBS_OWNERDRAWVARIABLE
or CBS_OWNERDRAWVARIABLE style, this message is sent to the owner
for each item in the control; otherwise, this message is sent once.
The system sends the WM_MEASUREITEM message to the owner window 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 message,
the system 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.
'gbs_00431
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm