WM_DRAWITEM

The WM_DRAWITEM message for a combination box or a list box are not exactly identical to their Windows counterpart. In Windows, when the item selection is changed using the mouse or keyboard, two WM_DRAWITEM messages are sent for the item deselected and four WM_DRAWITEM messages are sent for the item being selected.

For the deselected item, the messages received are:

┌──────────┬──────────────────────────────┬──────────────────────────────┐
│A         │ODA_FOCUS                     │ODS_SELECTED                  │
├──────────┼──────────────────────────────┼──────────────────────────────┤
│B         │ODA_SELECT                    │0                             │
└──────────┴──────────────────────────────┴──────────────────────────────┘

For the selected item, the messages received are:

┌──────────┬──────────────────────────────┬──────────────────────────────┐
│C         │ODA_FOCUS                     │ODS_FOCUS                     │
├──────────┼──────────────────────────────┼──────────────────────────────┤
│D         │ODA_FOCUS                     │0                             │
├──────────┼──────────────────────────────┼──────────────────────────────┤
│E         │ODA_SELECT                    │ODS_SELECTED                  │
├──────────┼──────────────────────────────┼──────────────────────────────┤
│F         │ODA_FOCUS                     │ODS_FOCUS | ODS_SELECTED      │
└──────────┴──────────────────────────────┴──────────────────────────────┘

The order of messages received, assuming the list box had the focus, is:

If the list box did not have the focus and the user clicks in the list box on a new item (such that the list box is also gaining the focus), only messages A, E, and F are sent.

If the list box is just receiving the focus but no new item is being selected, only message F is sent for the item currently selected.

When the list box loses the focus, only message A is sent for the currently selected item.

A special case arises when the user is at the beginning or end of the list and re-selects the selected item using the mouse or keyboard. In this case, only message A is sent.

In the Open32 implementation, one WM_DRAWITEM message is sent for the item deselected and one WM_DRAWITEM message for the item being selected.

For the deselected item, the message received is:

┌──────────┬──────────────────────────────┬──────────────────────────────┐│A         │ODA_SELECT                    │0                             │
└──────────┴──────────────────────────────┴──────────────────────────────┘

For the selected item, the message received is:

┌──────────┬──────────────────────────────┬──────────────────────────────┐
│B         │ODA_FOCUS                     │ODS_FOCUS | ODS_SELECTED      │
└──────────┴──────────────────────────────┴──────────────────────────────┘

The order of messages received is A, then B. If the list box did not have the focus and the user clicks in the list box on a new item (such that the list box is also gaining the focus), messages A and B are again sent. If the list box is just receiving the focus, only message B is sent. When the list box loses the focus, the following message is sent for the currently selected item:

┌──────────┬──────────────────────────────┬──────────────────────────────┐
│C         │ODA_FOCUS                     │ODS_SELECTED                  │
└──────────┴──────────────────────────────┴──────────────────────────────┘

For the special case when the user is at the beginning or end of the list and re-selects the selected item using the mouse or keyboard, no message is sent in Open32.

When an item is just to be drawn (in response to painting the list is), the WM_DRAWITEM message received in both implementations is:

┌──────────┬──────────────────────────────┬──────────────────────────────┐
│A         │ODA_DRAWENTIRE                │0                             │
└──────────┴──────────────────────────────┴──────────────────────────────┘

In both implementations, the WM_DRAWITEM message received for the combination box edit are:

This implementation can cause problems if the drawing of the item's focus relies on only the ODA_FOCUS Action and the ODS_FOCUS state flags. Likewise, problems can occur drawing the item's selection state relies on only the ODA_SELECT Action and ODS_SELECTED State flags. By properly arranging the logic for the WM_DRAWITEM message, an application can be written to work efficiently under both Windows and Open32.


[Back: Messages]
[Next: Metafiles]