Click here to Skip to main content
15,860,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Where is the best place to handle an CEdit control input text before it is displayed to the screen, so I can control the input text and make changes to it and finally display it to the screen ?

Give me an example code please !
Posted
Updated 12-Jan-12 5:57am
v2

Here are some assorted videos that show how to handle a few different scenarios.

Hope it helps

-DrB
 
Share this answer
 
v3
Comments
Mr. Tomay 12-Jan-12 12:24pm    
awesome tuts
You could also look into inheriting from a CEdit class and write your own control. Then handle the WM_CHAR message and decide what you want to do with it. In a .h file you could have
class CFloatEdit : public CEdit 
{
public:
	// Message handler for WM_CHAR message.
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);    

}


Then in your .cpp implementation file
afx_msg void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if (isdigit(nChar) || (nChar == '.') || (nChar < 0x20))
		CEdit::OnChar(nChar, nRepCnt, nFlags);
	else
		MessageBeep(0xFFFFFFFF);
}


That's not a complete implementation, but gives you the general idea.
 
Share this answer
 
Comments
Mr. Tomay 12-Jan-12 12:29pm    
Very helpful
Just one problem (if the user paste the content of the clipboard from the context menu !!!)
Controls are usually initialized in OnInitDialog of your dialog which is executed before the dialog is shown. It is not necessary to perform input tests before the control is shown, because the user can't enter anything.

Input validation is usually performed in OnOK.

This is rather trivial and basic knowledge. However, here is some code:

C++
void CMyDialog::OnInitDialog()
{
    CDialog::OnInitDialog();
    m_editMyInput.SetWindowText(_T("my input"));
    return TRUE;
}
void CMyDialog::OnOK()
{
    CString str;
    m_editMyInput.GetWindwText(str);
    if (str == _T("invalid"))
        return;
    CDialog::OnOK();
}
 
Share this answer
 
Comments
Mr. Tomay 12-Jan-12 12:06pm    
what I mean concern the input text, not the control (before the text is displayed on the CEdit control).
Ex:
1) CEdit Number property behavior.
2) Masks behavior.
Jochen Arndt 12-Jan-12 12:17pm    
Sorry, but that was not clear stated in your question (and I still don't know what you exactly want to know).
Mr. Tomay 12-Jan-12 12:29pm    
Solution 4 (Chris Meech) has understand me
Jochen Arndt 12-Jan-12 12:44pm    
OK. Now I understand. You want to check the input while the user enters something. Solution 4 does the job. However, you may also add a check when the user is pasting text from the clipboard. This can be done using the EN_UPDATE handler.
Mr. Tomay 12-Jan-12 12:47pm    
That's it.
Edit controls send the EN_UPDATE notification code to the parent dialog after its text has changed and before the text is displayed. This is the notification you probably want to handle.
Check out its documentation here - http://msdn.microsoft.com/en-us/library/windows/desktop/bb761687(v=vs.85).aspx[^]
 
Share this answer
 
Comments
Mr. Tomay 12-Jan-12 12:10pm    
OK, but how to cancel input text if it is not valid (inside EN_UPDATE handler)!?
«_Superman_» 12-Jan-12 20:52pm    
Refer to this link - http://www.codeguru.com/cpp/controls/editctrl/maskededitcontrols/article.php/c3915

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900