Click here to Skip to main content
15,882,152 members
Articles / Desktop Programming / MFC
Article

Dim Edit Control

Rate me:
Please Sign up or sign in to vote.
4.53/5 (8 votes)
28 Aug 2001CPOL 146.8K   2.8K   44   21
An edit control that can provide visual cues in its text area.

Image 1

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( <FONT color=#008000>COLOR_WINDOW</FONT> ) 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President JRTwine Software, LLC
United States United States
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

Comments and Discussions

 
GeneralNative Support On Windows XP... Pin
James R. Twine16-Mar-05 0:41
James R. Twine16-Mar-05 0:41 
Generala minor improvement Pin
Franz Brunner22-Oct-04 23:54
Franz Brunner22-Oct-04 23:54 
GeneralCode Not Found Pin
Koundinya23-Dec-03 18:46
Koundinya23-Dec-03 18:46 
GeneralRe: Code Not Found Pin
James R. Twine24-Dec-03 1:10
James R. Twine24-Dec-03 1:10 
GeneralRe: Code Not Found Pin
Koundinya24-Dec-03 1:13
Koundinya24-Dec-03 1:13 
GeneralRe: Code Not Found Pin
Koundinya24-Dec-03 1:15
Koundinya24-Dec-03 1:15 
GeneralRe: Code Not Found Pin
James R. Twine25-Dec-03 14:31
James R. Twine25-Dec-03 14:31 
GeneralRe: Code Not Found Pin
Koundinya25-Dec-03 21:10
Koundinya25-Dec-03 21:10 
GeneralRe: Code Not Found Pin
Koundinya25-Dec-03 21:14
Koundinya25-Dec-03 21:14 
GeneralRe: Code Not Found Pin
James R. Twine27-Dec-03 15:40
James R. Twine27-Dec-03 15:40 
GeneralDim function to a CComboBox Pin
elkhaze30-May-03 3:47
elkhaze30-May-03 3:47 
GeneralRe: Dim function to a CComboBox Pin
James R. Twine12-Jun-03 10:00
James R. Twine12-Jun-03 10:00 
GeneralRe: Dim function to a CComboBox Pin
elkhaze8-Jul-03 9:51
elkhaze8-Jul-03 9:51 
General(D)HTML version... Pin
25-Aug-01 16:07
suss25-Aug-01 16:07 
GeneralRe: (D)HTML version... Pin
James R. Twine27-Aug-01 4:34
James R. Twine27-Aug-01 4:34 
GeneralRe: (D)HTML version... Pin
30-Aug-01 9:27
suss30-Aug-01 9:27 
GeneralThere 'ya go, Eclypce (Was: Re: (D)HTML version...) Pin
James R. Twine30-Aug-01 9:53
James R. Twine30-Aug-01 9:53 
GeneralRe: (D)HTML version... Pin
31-Aug-01 16:34
suss31-Aug-01 16:34 
GeneralRe: (D)HTML version... Pin
James R. Twine31-Aug-01 17:33
James R. Twine31-Aug-01 17:33 
GeneralSource will be updated soon... Pin
James R. Twine22-Aug-01 14:32
James R. Twine22-Aug-01 14:32 
GeneralIt has been updated. Pin
James R. Twine30-Aug-01 9:55
James R. Twine30-Aug-01 9:55 

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.