Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 C++ C MFC Handling
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 11-Jan-12 6:57am
tomay30001.2K
Edited 12-Jan-12 6:57am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here are some assorted videos that show how to handle a few different scenarios.
 
Hope it helps
 
-DrB
  Permalink  
v3
Comments
tomay3000 at 12-Jan-12 12:24pm
   
awesome tuts
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  
Comments
tomay3000 at 12-Jan-12 12:29pm
   
Very helpful
Just one problem (if the user paste the content of the clipboard from the context menu !!!)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
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();
}
  Permalink  
Comments
tomay3000 at 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 at 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).
tomay3000 at 12-Jan-12 12:29pm
   
Solution 4 (Chris Meech) has understand me
Jochen Arndt at 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.
tomay3000 at 12-Jan-12 12:47pm
   
That's it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Comments
tomay3000 at 12-Jan-12 12:10pm
   
OK, but how to cancel input text if it is not valid (inside EN_UPDATE handler)!?
«_Superman_» at 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)

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100