Owner-Draw: Overview and Sources of InformationLast reviewed: March 11, 1996Article ID: Q64327 |
The information in this article applies to:
SUMMARYOwner-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 INFORMATIONThe 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:
ARTICLE-ID: Q64326 TITLE : Owner-Draw: Handling WM_DRAWITEM for Drawing Controls -or- ARTICLE-ID: Q64328 TITLE : Owner-Draw: 3-D Push Button made from Bitmaps with Text -or- ARTICLE-ID: Q65792 TITLE : Owner-Draw Example: Right - and Decimal AlignmentTo 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:
Under Windows 95, the BS_BITMAP style allows buttons to display bitmaps without using owner-draw.
|
Additional reference words: 3.00 3.10 3.50 4.00 owndraw od owner draw
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |