Click here to Skip to main content
13,044,115 members (82,018 online)
Rate this:
Please Sign up or sign in to vote.
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 11-Jan-12 5:57am
Updated 12-Jan-12 5:57am
Rate this: bad
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

tomay3000 12-Jan-12 12:24pm
awesome tuts
Rate this: bad
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 
	// 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);

That's not a complete implementation, but gives you the general idea.
tomay3000 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
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()
    m_editMyInput.SetWindowText(_T("my input"));
    return TRUE;
void CMyDialog::OnOK()
    CString str;
    if (str == _T("invalid"))
tomay3000 12-Jan-12 12:06pm
what I mean concern the input text, not the control (before the text is displayed on the CEdit control).
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).
tomay3000 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.
tomay3000 12-Jan-12 12:47pm
That's it.
Rate this: bad
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 -[^]
tomay3000 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 -

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Jan 2012
Copyright © CodeProject, 1999-2017
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