|
|
Scanf Masked Edit control
If you have ever worked with parsing text files, you have probably stumbled upon
the
When looking for a Windows control that would lend me some standard formatting,
the closest that comes to the mind is the Date Time Picker control.
Now, many UI fanatics don't really like the Date Time Picker control at all, arguing that it does not follow the standard caret navigation or clipboard manipulation rules. This is true, and it does need a bit of "getting use to"-time before most users feel comfortable with its inner workings. Still, I agree that the cursor key navigation is controversial in a standard UI, but you'll just have to live with it. FormattingA format specification has the following form:%[-][#][0][width][.precision]type Each field is a single character or a number signifying a particular format option. The type characters that appear after the last optional format field determine whether the associated argument is interpreted as a character, a string, or a number. The simplest format specification contains only the percent sign and a type character (for example, %s). The optional fields control other aspects of the formatting. Following are the optional and required fields and their meanings.
-
Pad the output with blanks or zeros to the right to fill the field width, justifying output to the left. If this field is omitted, the output is padded to the left, justifying it to the right. # Prefix hexadecimal values with 0x. 0 Pad the output value with zeros to fill the field width. If this field is omitted, the output value is padded with blank spaces. width Copy the specified minimum number of characters to the output buffer. The width field is a nonnegative integer. precision For numbers, copy the specified minimum number of digits to the output buffer. type Output the corresponding argument as a string, or a number. This field can be any of the following values.
FormattingA few sample formats:%3d . %3d . %3d . %3d Using the controlTo use it, place aSTATIC control (label) on your dialog. Make sure the rename
the resource from IDC_STATIC to e.g. IDC_EDIT1.
Add a member variable to your dialog implementation file...
In the OnInitDialog() event handler, add the following line:
The control gets its initial formatting string from the window text, however
you can use the
To retrieve the values from the cells, you have two choices:
This retrieves the arguments from a control which is formatted as an IP Address.
Note that the formatting string itself is not passed, and all cells must be retrieved.
Likewise, use the sprintf() method to set the control values.
Source Code DependenciesMicrosoft Visual C++ 6.0Microsoft WTL 3.1 Library Download Files
Written by Bjarke Viksoe. Article submitted 2/16/2003. To the top
|
|||