Problem : GetWindowText CMFCMaskedEdit?
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
always returns the wrong value.
DDX_Text(pDX, IDC_EDIT_FLEK, m_strFLEK);
_T(“DESTLE__________”), // Literal, “_” char = character entry
_T(‘ ‘)); // Default char
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
bool bLE = false;
CEdit *pEDit = (CEdit *)GetDlgItem(IDC_EDIT_FLEK
if (m_strFLEK.Find(” “) > -1/)
bLE = true;
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
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.