Currency Edit Control
The Objective Toolkit currency edit control classes provide a specialized edit control for the display and entry of currency data. The control includes a bitmap button for dropping down a calculator.
Figure 23 – Objective Toolkit’s Currency Edit Class Hierarchy
SECDropEdit
The SECDropEdit class adds a combo-like drop-down button to an edit control.
SECCurrencyEdit uses the special SECDropEdit capabilities to display a bitmap button that activates a calculator to help in the data entry.
SECCurrencyEdit
SECCurrencyEdit provides an extensible class for entering and displaying custom-formatted currency data. In addition, it includes a context menu and an optional bitmap button.
The methods of the Format class, a helper class, provide a comprehensive set of custom formatting options. If you need implement behavior that is not addressed by Format’s methods, you can customize the input data parsing and output display formatting by descending new classes from SECCurrencyEdit::Format and SECCurrencyEdit.
Using SECCurrencyEdit
To attach an SECBitmap Button to a dialog resource:
1. Add an edit control to your dialog using the resource editor.
2. Instantiate an SECCurrencyEdit object in your dialog class. This object must be in scope when the dialog is displayed.
3. In OnInitDialog(), replace the edit control with your SECCurrencyEdit object by calling the Initialize() method.
4. Create and configure an SECCurrencyEdit::Format object to specify formatting options. Call SetFormat() to start using the new formatting information.
Use GetValue() and SetValue() to obtain and recover the current value in the control. You can also use the DDX_Currency() method in your DoDataExchange() function.
Call SetBitmap(IDB_CALC) to display the calculator drop-down button.
SECCurrencyEdit::Format
Format is a nested helper class that provides the core currency formatting and parsing methods used by an SECCurrencyEdit control. As the following list of methods suggests, the Format class provides extensive control over the appearance of the currency data.
*void EnableLeadingZero(BOOL b);
*void EnableDecimalSeparatorLine(BOOL b);
*void SetMonetarySymbol(LPCTSTR p);
*void SetThousandSeparator(TCHAR c);
*void EnableLeadingThousSeparator (BOOL b);
*void SetDecimalSeparator(TCHAR c);
*BOOL SetGrouping(LPCTSTR x);
*BOOL SetPaddingCharacter(TCHAR c);
*void SetPositiveFormat(int i);
*void SetNegativeFormat(int i);
*void SetDecimalDigits(int i);
*void SetFractionalDigits(int i);
*void SetBackgroundColor(COLORREF cr);
*void SetNegativeColor(COLORREF cr);
*void SetPositiveColor(COLORREF cr);
*void SetDecimalSeparatorLineColor(COLORREF cr);
Consider the following facts before you use the currency display options:
*Setting the thousands separator to the null character (‘\0’) prevents its use.
*With EnableLeadingThousSeparator, the thousands separator will present ‘5555555’ as ‘$ , 5,555,555.00’ as opposed to ‘$ 5,555,555.00’.
*When you set decimal digits to negative one (-1) the application uses every digit that is necessary to display the number. If the number of decimal digits is greater than is required, the output is padded with the padding character.
*You can use the values in the table below with the SetNegativeFormat() and SetPositiveFormat() methods. These values are taken directly from Microsoft’s documentation regarding the international section of WIN.INI.
Negative Format
Positive Format
0
($1)
0
$1
1
-$1
1
1$
2
$-1
2
$ 1
3
$1-
3
1 $
4
(1$)
 
 
5
-1$
 
 
6
1-$
 
 
7
1$-
 
 
8
-1 $
 
 
9
-$ 1
 
 
10
$ 1-
 
 
The ParseValue() and FormatValue() methods convert between a numeric and a string representation. If you need to use a format that is not supported by the basic Format class, derive your own Format class and override those methods. Then, derive your own version of SECCurrencyEdit and override its CreateFormatObject() method to provide an object of your descendant class.
For example, the following code:
 
SECCurrencyEdit m_Edit;
// fmt(TRUE) will load the default system settings.
SECCurrencyEdit::Format fmt(FALSE);
fmt.EnableLeadingZero(TRUE);
fmt.EnableDecimalSeparatorLine(FALSE);
fmt.SetMonetarySymbol(_T("$"));
fmt.SetThousandSeparator(_T(','));
fmt.SetDecimalSeparator(_T('.'));
fmt.SetGrouping(_T("3;0")); // 3 digits per group repeated.
fmt.SetPaddingCharacter(_T(' '));
fmt.SetPositiveFormat(0);
fmt.SetNegativeFormat(0);
fmt.SetDecimalDigits(10);
fmt.SetFractionalDigits(2);
fmt.SetNegativeColor(RGB(255,0,0));
fmt.SetPositiveColor(RGB(0,0,255));
m_Edit.SetFormat(fmt);
will present "5555555" as "$ , 5,555,555.00" in blue color; and "-5555555" as "($ , 5,555,555.00)" in red color.
SECCurrencyEdit Messages
The SECCurrencyEdit class supports some of the WM_* windows messages and EM_* edit control messages.
The supported messages are as follows:
Table 9 – Windows Messages Supported by SECCurrencyEdit 
Windows Message
Description
WM_COPY
Copies the current selection to the clipboard.
WM_CUT
Deletes or cuts the current selection, if any, in the control and then copies the deleted text to the clipboard.
WM_GETFONT
Retrieves the font with which the control is currently drawing its text.
WM_PASTE
Copies the current content on the clipboard to the control.
WM_SETFONT
Specifies the font that the control uses when drawing text.
WM_SETREDRAW
Allows changes in the control to be redrawn or prevents changes in the control from being redrawn.
WM_SETTEXT
Sets the text of the control.
WM_UNDO
Undoes the last operation.
Table 10 – Edit Control Messages Supported by SECCurrencyEdit 
Edit Control Message
Description
EM_CANUNDO
Determines whether the user can undo an operation.
EM_EMPTYUNDOBUFFER
Resets the undo flag of the control.
EM_GETSEL
Gets the starting and ending character positions of the current selection in the control.
EM_SETREADONLY
Sets or removes the read-only style (ES_READONLY) of the control.
EM_SETSEL
Selects a range of characters in the control.
EM_UNDO
Undoes the last edit control operation.
SECCurrencyEdit Sample
The use of SECCurrencyEdit and its supporting classes is demonstrated in the Objective Toolkitcurrency sample in the Samples\Toolkit\MFC\Controls\currency directory. This sample is not shipped with the product. For information on how to obtain this sample, see “Location of Sample Code” in the Getting Started part.