Introduction
Microsoft provides to developers rich collection of GUI controls. The
edit box control is very useful, but has one diasadvantage: it
does not supports the numeric decimals. This article describes the creation
of numeric edit box.
Background
The Microsoft's controls are localized. For example, if you change the local
time format from the "Regional Options" dialog, CDateTimeCtrl
change it time format. The presented numeric edit box is localized as
well. By the creation time it loads the locale decimal point delimiter and use
it. Here is the code:
CNumericEdit::CNumericEdit()
{
const int nBuffLen = ::GetLocaleInfo( LOCALE_USER_DEFAULT,
LOCALE_SDECIMAL, NULL, 0 );
_ASSERT( nBuffLen > 0 );
const int nResult = ::GetLocaleInfo( LOCALE_USER_DEFAULT,
LOCALE_SDECIMAL,
m_strDelim.GetBuffer(nBuffLen), nBuffLen );
_ASSERT(nResult != 0);
m_strDelim.ReleaseBuffer();
}
Using the code
You should do following steps:
- Place the edit box control on the dialog.
- Assotiate the
CEdit
dialog class member to the edit box
control.
- Include the "NumericEdit.h" to the your dialog class header.
- Replace the
CEdit
with CNumericEdit
.
#include "NumericEdit.h"
protected:
CNumericEdit m_editNumeric;
Points of Interest
Microsoft says about WM_SETTINGCHANGE :
The system sends the WM_SETTINGCHANGE
message to all top-level
windows when the SystemParametersInfo
function changes a
system-wide setting or when policy settings have changed.
I checked it, it works. Currently the numeric edit box control sets it's
locale by creation time. It will be much better the control to react to
operation system changes. But the WM_SETTINGCHANGE
message is sent
only to top-level windows, not to child windows. The possible solution is
to handle the WM_SETTINGCHANGE
in main window and delegate the
WM_SETTINGCHANGE
message to all child windows, but it seams ugly. I
continue find other solution of this problem.
History
- 12.08.2003 - First version of the code.