October 10th, 2018

Notes on DrawText and tab stops

The Draw­Text function will recognize tab characters if you ask for DT_EXPAND­TABS.

And then things get weird.

If you ask for DT_EXPAND­TABS, then you cannot ask for any of the DT_*_ELLIPSIS features. The ellipsis code doesn’t support tabs.

Tab stops default to every eight average character widths. If you want to change the default, you can specify DT_TAB­STOP and put the desired number of average characters per tab in bits 8 through 15. For example, if you want tabs every four average characters, you would use DT_TAB­STOP | 0x0400.

The DT_TAB­STOP flag precludes you from using any of the flags that normally occupy bits 8 through 15, since it takes over those bits for its own purposes. Specifically, these flags cannot be combined with DT_TAB­STOP:

#define DT_NOCLIP                   0x00000100
#define DT_EXTERNALLEADING          0x00000200
#define DT_CALCRECT                 0x00000400
#define DT_NOPREFIX                 0x00000800
#define DT_INTERNAL                 0x00001000
#define DT_EDITCONTROL              0x00002000
#define DT_PATH_ELLIPSIS            0x00004000
#define DT_END_ELLIPSIS             0x00008000

You can avoid this problem with DT_TAB­STOP by using Draw­Text­Ex: When you use using Draw­Text­Ex, the tab stop interval is specified by the iTabLength member of the DRAW­TEXT­PARAMS structure instead of being smuggled inside bits 8 through 15 of the flags.

If you do not specify DT_TAB­STOP, then the value of iTabLength is ignored.

The tab stop positions are relative to the left edge of the formatting rectangle you provided plus any left margin.

If you specify DT_TAB­STOP but forgot to say DT_EXPAND­TABS, then you don’t get tab expansion. You went to the effort of configuring something you didn’t enable.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.