OwnerDraw decription

A rendering mode in which you take responsibility for drawing a control, rather than relying on the control’s default rendering behavior.

Typically, Windows handles painting automatically by using property settings such as BackColor to determine the appearance of a control. With owner drawing, you take over the painting process, changing elements of appearance that are not available by using properties. For example, many controls let you set the color of the text that is displayed, but you are limited to a single color. Owner drawing enables you to do things like display part of the text in black and part in red.

In practice, owner drawing is similar to drawing graphics on a form. For example, you could use graphics methods in a handler for the form's Paint event to emulate a ListBox control, but you would have to write your own code to handle all user interaction. With owner drawing, the control uses your code to draw its contents but otherwise retains all its intrinsic capabilities. You can use DRAW methods to draw each item in the control or to customize some aspects of each item while you use the default appearance for other aspects of each item.  DRAW methods based on Device context API methods and GDI Plus methods. Please, feel free for ask to add new methods if need.

To perform owner drawing in controls that support it, you will typically set one property and write OnerDraw context script.

Most controls that support owner drawing have an OwnerDraw property that indicates whether the control will raise its drawing-related event or events when it paints itself.

There are many different kinds of drawing events, but a typical drawing event occurs in order to draw a single item within a control. BRIZ provides automaticaly binding of Your OnerDraw context script when receives an OwnerDraw events. BRIZ sets variables to drawing. For example, variables typically contains the item's index number, a Rectangle that indicates the item's display boundaries and for some objects provides additional information about the item such as the background or a focus rectangle.

OnerDraw context script is reusable (You can use one context with many objects).

The following Objects support owner drawing:

How it works

BRIZ handles Windows messages WM_DRAWITEM and WM_MEASUREITEM . BRIZ executes OwnerDrawContext script on each message. You can manage OwnerDrawContext by sytem methods through subroutines GP.SystemSub( SubStr ) and GP.SystemFn( SubStr, Ret )

Setting the Owner-Drawn Flag

For menu You should use the Menu subroutines to specify an owner-drawn menu item, just add option 'O' to flag and define OwnerDrawContext name after flag. For example "EO;CONTEXT=MyMenu"

For objects You should specify ownerdraw style and define OwnerDrawContext name with help of method "SetDrawContext ContextName" or DRAWCONTEXT=xxxxx; option in intial string.

OwnerDraw styles for objects:

 

Owner-Drawn Menus and the WM_MEASUREITEM Message

Before the system displays an owner-drawn menu item for the first time, it sends the WM_MEASUREITEM message to the window procedure of the window that owns the item's menu. BRIZ automaticaly calls DrawContext that  must fill the itemWidth and itemHeight members before returning. The system uses the information in these members when creating the bounding rectangle in which an application draws the menu item. It also uses the information to detect when the user chooses the item.

Owner-Drawn Menus and the DRAWITEM

Whenever the item must be drawn (for example, when it is first displayed or when the user selects it), the system calls the DrawContext. DrawContext contains flags that indicate the state of the item (such as whether it is grayed or selected) as well as a bounding rectangle and a device context that the application uses to draw the item.

An application must do the following while processing the DRAWITEM:

If the user selects the menu item, the system sets the itemAction member to the ODA_SELECT value and sets the ODS_SELECTED value in the itemState member. This is an application's cue to redraw the menu item to indicate that it is selected.

DrawContext script predefined values

Specific predefine values by ControlType

  • ODT_BUTTON    (4) Owner-drawn button
  • ODT_COMBOBOX    (3) Owner-drawn combo box
  • ODT_LISTBOX (2)  Owner-drawn list box
  • ODT_MENU    (1) Owner-drawn menu
  • ODT_LISTVIEW (102)  List view control
  • ODT_STATIC (5)  Owner-drawn static control
  • ODT_TAB    (101) Tab control
  • ODT_HEADER  (100) Tab control