Click here to Skip to main content
13,293,474 members (66,345 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 31 Aug 2001

A WTL Dim Edit control

, 31 Aug 2001
Rate this:
Please Sign up or sign in to vote.
A WTL adaptation of James Twine's Dim Edit control.
<!-- Download Links --> <!-- Article image -->

<!-- Add the rest of your HTML here -->


As I was working on an application with a property sheet, I realized that James Twine's Dim Edit Control would be perfect for presenting some of the information. However, his control was written in MFC, and I was using WTL. And so, my WTL Dim Edit control was born!

I purposely didn't put in as many features as James has in his, because I am trying to keep the code behind my property pages as light as possible. However, I wanted to be a little more flexible about where the "dim text" string was stored, and how it was displayed. What I ended up with is a mixture of WTL and STL.


The dim text string is stored using an STL std::basic_string < TCHAR >, which allows the control to be compiled for ANSI or Unicode use. Also, doing it this way does not impose an arbitrary limit on the length of the dim text. Next, notice that the dim text is not actually stored as the "window" text, which means the control does not have to make sure that the correct string is stored for when the client application requests it.

Message handlers for WM_SETFOCUS and WM_KILLFOCUS are used to set a simple boolean flag for whether or not the dim text should be displayed in the control. The WM_PAINT handler looks at this flag to decide if the dim text or the control's window text should be displayed. Windows is queried for the fonts and colors to use, so your users can use any theme they like, and the control will perform identically to the normal edit control.


To use this control in your WTL application, just add a normal edit control to your dialog or window, and then subclass it. Your code will look something like:

#include <span class="code-keyword"><DimEdit.h></span>

class CMainDlg : public CDialogImpl< CMainDlg >

  OnInitDialog( HWND hWnd, LPARAM lParam )
    m_dimEdit.SubclassWindow( GetDlgItem( IDC_EDIT1 ) );
    m_dimEdit.SetDimText( "This is the dim text" )
             .SetDimColor( RGB( 192, 192, 192 ) );

  CDimEdit m_dimEdit;


If the pair of lines that set the text and color look a little strange to you, it is because any time I write my "get/set" function pairs, the set functions always return a reference to the object, itself. That allows this kind of function chaining. It's really no different than being able to write code like: a = a + a + a. Over time, I have found it more convenient to be able to write code in this way.

One last note on WTL: As you look at the code in DimEdit.h and maindlg.h, you will see that the message map doesn't look quite normal. This is because I found that WTL has a message cracking system, very similar to the one that has been present in the windowsx.h header since the Windows 3.x days. Message crackers release you from the responsibility of casting the various parameters to a more useable form. The only problem with doing it this way is that the event handler wizard is based on the normal ATL message map, not the extended cracking version. You will have to add messages to the map and handler code by hand, but I do not find this to be much of a burden.


I hope you find this control useful! If you would like any additional functionality, leave a message in the forum at the bottom of this page, and I will take your thoughts into consideration.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Paul A. Howes
Software Developer (Senior)
United States United States
Mr. Howes has been programming since he was first introduced to the Apple II+ at the tender age of ten. After briefly dabbling with circuit design as a combined CS/EE major, he came to his senses and completed a pure CS degree at RIT

All these years later, the programming bug still bites him each day and causes him to go to work, where he writes software for a living. Now he is even learning Cocoa for the Mac!

In his copious amounts of "spare" time, Mr. Howes is learning the art of cabinet-making, flies radio-controlled helicopters and airplanes, and mountain cycles. Next summer he would like to learn how to kayak.

Linked In Page:

You may also be interested in...


Comments and Discussions

GeneralThanks^_^ Pin
AnnaWang12-Sep-07 17:41
memberAnnaWang12-Sep-07 17:41 
GeneralRe: Thanks^_^ Pin
Paul A. Howes15-Sep-07 17:02
memberPaul A. Howes15-Sep-07 17:02 
Generala = a + a + a Pin
Uwe Keim1-Sep-01 5:58
memberUwe Keim1-Sep-01 5:58 
GeneralRe: a = a + a + a Pin
Paul A. Howes1-Sep-01 6:07
memberPaul A. Howes1-Sep-01 6:07 
GeneralRe: a = a + a + a Pin
Tim Smith1-Sep-01 8:54
memberTim Smith1-Sep-01 8:54 
GeneralRe: a = a + a + a Pin
Paul A. Howes1-Sep-01 9:25
memberPaul A. Howes1-Sep-01 9:25 
GeneralRe: a = a + a + a Pin
Jörgen Sigvardsson1-Sep-01 8:54
memberJörgen Sigvardsson1-Sep-01 8:54 
GeneralRe: a = a + a + a Pin
Uwe Keim2-Sep-01 20:35
memberUwe Keim2-Sep-01 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 1 Sep 2001
Article Copyright 2001 by Paul A. Howes
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid