Click here to Skip to main content
6,630,586 members and growing! (15,436 online)
Email Password   helpLost your password?
Desktop Development » Edit Controls » General     Intermediate

Dim Edit Control

By James R. Twine

An edit control that can provide visual cues in its text area.
VC6Win2K, MFC, Dev
Posted:21 Sep 2000
Updated:28 Aug 2001
Views:97,229
Bookmarked:35 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
43 votes for this article.
Popularity: 6.73 Rating: 4.12 out of 5
1 vote, 12.5%
1

2

3
1 vote, 12.5%
4
6 votes, 75.0%
5

This article describes a class (CDimEdit) for a "Dim Edit" control. I first saw the idea for a Dim Edit control in some (D)HTML code, a while back. The idea behind a Dim Edit control is that an input control can provide visual clues to how it should be used, like a Masked edit control. In the case of a Dim Edit control, the control can tell you what it is for, or that certain data is required or optional, rather than enforce the format of data.

This control is useful when you have to provide the user with a form-like interface, like a "request for more information" form on a web page. There might not be enough room on the interface to indicate with complete clarity that certain fields are required as opposed to optional. That is where this control can help.

The Dim Edit control will show some specified text (called Dim Text) centered in the edit control's visible area. This text is only visible while the control has no data within it. So when the user starts typing in the control, the Dim Text will be hidden. If the control becomes empty again, it gets shown again. The color of the Dim Text can also be specified.

This control is not a solution to every UI problem out there, but it sure beats the hell out of putting "*"s next to fields to indicate that they are required! :)

Functions of interest are:

  • void SetShowDimControl( bool bShow )
  • void SetDimText( LPCTSTR cpText )
  • void SetDimColor( COLORREF crDColor )
  • void SetDimOffset( char cRedOS, char cGreenOS, char cBlueOS )

The SetShowDimControl(...) function is used to override the automatic handling of showing/hiding the Dim Text. That being said, this function is not really that useful. There is no GetShowDimControl(...), because checking to see if the control has any text is (usually) good enough.

The SetDimText(...) function is used to set the string that will be displayed as Dim Text. In the .H file, there is a constant that determines the maximum length of the buffer used for storing the Dim Text. Adjust this value to your liking.

The SetDimColor(...) function is used to directly specify the color to be used when drawing the Dim Text. Take care when using this function to make sure that you are taking the user's current color settings into consideration.

The SetDimOffset(...) function is used to construct a color value based on the offsets applied. For example, with a normal GetSysColor( COLOR_WINDOW ) return value of white, an offset value of "-0x40" provides a nice grey color for the Dim Text.

In the demo image above, the numbered dialogs show the operation of the control before and after a Username was typed:

  1. No characters typed
  2. A Username was entered into the first control. The Dim Text is hidden after the first character is entered.

Conditions of use are detailed in the header and source file(s).

Feel free to contact me if there are any questions. Have fun.

License

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

James R. Twine


Member
Programming since the age of 10, started professionally at the age of 17. Currently involved in both Client and Server side development on Win32 platforms for MC/HA/FT financial applications. Development experience with Win32, Win16, Linux and other flavors of Unix.

Extensive multithreaded development experience on Windows platforms using the Win32 SDK, and MFC.

Experience with HA/FT n-tiered Client/Server systems as well as GUI apps of varying complexity. Some experience with Game developement.

Having learned that the stuff you can barely get away with doing Client-side apps just does not cut it in the real "Server World", I am amazed how many 'professionals' cannot tell the difference between "works" and "correct" or try to (mis)use VB and/or MFC on server-side development projects, never considering that just because it RUNS, does not mean it runs WELL.

Lastly, I am also a collector of arcade games, and can perform repairs, conversions, etc. Search for my name, you will find me on lots of arcade-related documents and sites.

Sites of interest(?):
http://www.jrtwine.com
http://www.jrtwine.com/jtwine
http://www.signingtime.com
http://www.deletefxpfiles.com
http://www.checkfavorites.com
http://www.coinop.org
Occupation: President
Company: JRTwine Software, LLC
Location: United States United States

Other popular Edit Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 21 of 21 (Total in Forum: 21) (Refresh)FirstPrevNext
GeneralNative Support On Windows XP... PinmemberJames R. Twine1:41 16 Mar '05  
Generala minor improvement PinmemberFranz Brunner0:54 23 Oct '04  
GeneralCode Not Found PinmemberKoundinya19:46 23 Dec '03  
GeneralRe: Code Not Found PinmemberJames R. Twine2:10 24 Dec '03  
GeneralRe: Code Not Found PinmemberKoundinya2:13 24 Dec '03  
GeneralRe: Code Not Found PinmemberKoundinya2:15 24 Dec '03  
GeneralRe: Code Not Found PinmemberJames R. Twine15:31 25 Dec '03  
GeneralRe: Code Not Found PinmemberKoundinya22:10 25 Dec '03  
GeneralRe: Code Not Found PinmemberKoundinya22:14 25 Dec '03  
GeneralRe: Code Not Found PinmemberJames R. Twine16:40 27 Dec '03  
GeneralDim function to a CComboBox Pinmemberelkhaze4:47 30 May '03  
GeneralRe: Dim function to a CComboBox PinmemberJames R. Twine11:00 12 Jun '03  
GeneralRe: Dim function to a CComboBox Pinmemberelkhaze10:51 8 Jul '03  
General(D)HTML version... PinmemberEclypce17:07 25 Aug '01  
GeneralRe: (D)HTML version... PinmemberJames R. Twine5:34 27 Aug '01  
GeneralRe: (D)HTML version... PinmemberTerry Denham10:27 30 Aug '01  
GeneralThere 'ya go, Eclypce (Was: Re: (D)HTML version...) PinmemberJames R. Twine10:53 30 Aug '01  
GeneralRe: (D)HTML version... PinmemberEclypce17:34 31 Aug '01  
GeneralRe: (D)HTML version... PinmemberJames R. Twine18:33 31 Aug '01  
GeneralSource will be updated soon... PinmemberJames R. Twine15:32 22 Aug '01  
GeneralIt has been updated. PinmemberJames R. Twine10:55 30 Aug '01  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Aug 2001
Editor: Smitha Vijayan
Copyright 2000 by James R. Twine
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project