INFO: Owner-Draw: Overview and Sources of Information
ID: Q64327
|
The information in this article applies to:
-
Microsoft Win32 Software Development Kit (SDK)
-
Microsoft Windows Software Development Kit (SDK) versions 3.0, 3.1
SUMMARY
Owner-draw controls are a new feature of Windows version 3.0. Because your
application does all the drawing of the contents of the controls, you can
customize them any way you like. Owner-draw controls are similar to
predefined controls in that Windows will handle the control's functionality
and mouse and keyboard input processing. However, you are responsible for
drawing the owner-draw control in its normal, selected, and focus states.
You can create owner-draw controls from the menu, button, and list-box
classes. You can create owner-draw combo boxes, but they must have the
CBS_DROPDOWNLIST style (equates to a static text item and a list box). The
elements of an owner-draw control can be composed of strings, bitmaps,
lines, rectangles, and other drawing functions in any combination, in your
choice of colors.
MORE INFORMATION
The Windows SDK sample application MENU demonstrates owner-draw menu items.
The SDK sample application OWNCOMBO is a fairly large example of owner-draw
and predefined list boxes and combo boxes.
The Microsoft Software Library contains simplified examples of an owner-
draw push button, owner-draw list boxes, and an owner-draw drop-down list
style combo box. Each of these examples includes descriptive text in a
related Knowledge Base article. For additional information, please see the
following article(s) in the Microsoft Knowledge Base:
Q64326
: Owner-Draw: Handling WM_DRAWITEM for Drawing Controls
Q64328
: SAMPLE: Owner-Draw: OdButton.exe - 3-D Push Button
Q65792
: Owner-Draw Example: Right - and Decimal Alignment
To respond to a WM_MEASUREITEM message, you MUST specify the height of the
appropriate item in your control. Optionally, you can specify the item's
width as well.
If you want to do something special when a string is deleted from a list
box, you should process WM_DELETEITEM messages. Windows's default action is
to erase the deleted string and to redraw the list box.
If you want to have control over the sorting for the order of items in a
list box or combo box that does not have the *_HASSTRINGS style, you should
specify the appropriate *_SORT style and process WM_COMPAREITEM messages.
If the *_SORT and *_HASSTRINGS styles are present, Windows will
automatically do the sorting without sending WM_COMPAREITEM messages. If
*_SORT is not specified, WM_COMPAREITEM messages will not be generated and
items will be displayed in the list box in the order in which they were
inserted.
The heart of owner-draw controls is the response to WM_DRAWITEM messages.
During this processing is when you draw an entire button or each individual
item in a menu, list box, or combo box. Because Windows does not interfere
in the drawing of owner-draw controls, your application must draw the
specified control item. The display of the control must indicate the state
of the control. Common states are as follows:
- Focus state (has the focus or not)
- Selection state (selection or not)
- Emphasis state (active, grayed, or disabled) (less common to process)
See the article titled "Owner-Draw: Handling WM_DRAWITEM for Drawing
Controls" for information about drawing controls in their various
states. Familiarity with the WM_DRAWITEM message and the various
control states is extremely helpful before trying to follow the code
examples.
Under Windows 95, the BS_BITMAP style allows buttons to display bitmaps
without using owner-draw.
Additional query words:
owndraw od owner draw win16sdk
Keywords : kbCtrl kbNTOS kbGrpUser kbWinOS
Version :
Platform :
Issue type : kbinfo
Last Reviewed: March 5, 1999