Problem : GetWindowText CMFCMaskedEdit?

Problem : GetWindowText CMFCMaskedEdit?

Hi all,
I got a new problem CMFCMaskedEdit. I have a edit field, and for this edit field, only 16 characters are allowed, the first 6 stays unchanged, the rest is numbers. And I did this using CMFCMaskedEdit.
But now there is a problem, whenever I change the  content of this edit field, and using GetWindowText to get it, it always returns the previous value. For example:
At start, my string is DESTLE, I change it to DESTLE1, use GetWindowText, it returns DESTLE??
then I change it to DESTLE12,  use GetWindowText, it returns DESTLE1??

And here is my code, IDC_EDIT_FLEK is the name of edit field. In function OnSelChangeLE, this line
m_wndMaskEdit.GetWindowText(m_strFLEK);
always returns the wrong value.

void CDlgSchlagInfo::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_FLEK, m_strFLEK);
}

BEGIN_MESSAGE_MAP(CDlgSchlagInfo, CDialog)
ON_EN_CHANGE(IDC_EDIT_FLEK, OnSelChangeLE)
END_MESSAGE_MAP()

CMFCMaskedEdit m_wndMaskEdit;
BOOL CDlgSchlagInfo::OnInitDialog()
{
CDialog::OnInitDialog();
VERIFY(m_wndMaskEdit.SubclassDlgItem( IDC_EDIT_FLEK, this ));
if (m_strFLEK.IsEmpty())
{

m_wndMaskEdit.EnableMask(_T(”      aaaaaaaaaa”), // The mask string
_T(“DESTLE__________”), // Literal, “_” char = character entry
_T(‘ ‘)); // Default char

m_wndMaskEdit.SetValidChars(_T(“1234567890″)); // Valid string characters
m_wndMaskEdit.EnableGetMaskedCharsOnly(FALSE);
m_wndMaskEdit.SetWindowText(_T(“DESTLE          “));
m_wndMaskEdit.GetWindowText(m_strFLEK);
}

return TRUE;  // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgSchlagInfo::OnSelChangeLE()
{
UpdateData(TRUE);
bool bLE = false;
if (m_wndMaskEdit)
m_wndMaskEdit.GetWindowText(m_strFLEK);

CString strFLEK;
CEdit *pEDit = (CEdit *)GetDlgItem(IDC_EDIT_FLEK);

if (m_strFLEK.Find(” “) > -1/)
bLE = true;
else
bLE = false;
}

Does anybody have an idea why and give me a suggestion?
Thank you very much.


Solution : GetWindowText CMFCMaskedEdit?

>>>> CMFCMaskedEdit (from afxmaskededit.cpp) is part of Microsoft’s MFCFeaturePack
Thanks, I already wondered about the naming …

>>>> This CMFCMaskedEdit has it’s own ‘SetWindowText’ and ‘GetWindowText’
???
You can overcome this by calling

GetDlgItem(IDC_EDIT_FLEK)->GetWindowText(strFLEK);

Here the GetDlgItem returns a CWnd* and as GetWindowText isn’t a virtual function it will return the text already shown at screen.

Anyway, the CMFCMaskedEdit variable should no made a global but a member of the dialog and the subclassing should be done by DoDataExchange.

To catch edit messages of the edit control you must derive your own edit class from CMFCMaskedEdit and have a OnGetDlgCode as I described for CMFCMaskedEdit. Instead of replacing CEdit by CMFCMaskedEdit, you then would use your edit class instead.

Again, The OnEnChange handler isn’t the right place to calling UpdateData(TRUE) as it was called for each character entered. You better use the OnKillFocus which was called when the focus changes from the edit to any other field.