The information in this article applies to:
SUMMARY
In the Microsoft Windows graphical environment, the primary feature of an
owner-draw control is the ability to customize the manner that a control
displays information and to extend its capabilities. An example of a
customized presentation is to decimal align a column of numbers in an owner-draw list box. This article describes how to perform this alignment, and then describes some example code in the Microsoft Software Library.
MORE INFORMATION
The following file is available for download from the Microsoft
Software Library:
Q119591 How to Obtain Microsoft Support Files from Online Services To right align a string (of digits or of text) at a particular horizontal position "X," the application must compute the length of the string. Then, move that distance to the left of "X" before drawing the string. The width of a string is contained in the low-order word of the value returned by the GetTextExtent() or GetTabbedTextExtent() functions. For example, if the following are true
Because digit characters have equal widths, aligning the right side of the
digit strings in an owner-draw list box to the same horizontal position
keeps all the columns lined up. If the decimal point is located
consistently, as for dollars and cents, the numbers are easily aligned. For
example:
One technique to right align substrings is to use multiple calls to
the TextOut function when drawing each list box item. Calculate the
origin of each substring as follows:
Another way to right align a string or substring of digits is to use
tab stops. A tab can be defined so that its position, plus the width
of the digit string, is equal to the desired right position "X."
The code sample below implements a tab stop before a digit substring. To use this code, place it into the code that processes the WM_DRAWITEM message for an owner-draw list box with the LBS_USETABSTOPS style:
Additional query words:
Keywords : kbfile kbsample kb16bitonly kbComboBox kbCtrl kbListBox kbSDKPlatform kbGrpUser kbUser |
Last Reviewed: June 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |