<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Library &#187; CEdit</title>
	<atom:link href="http://www.ucosoft.com/tag/cedit/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Mon, 19 Jul 2010 04:51:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Simple CEdit Validation</title>
		<link>http://www.ucosoft.com/simple-cedit-validation.html</link>
		<comments>http://www.ucosoft.com/simple-cedit-validation.html#comments</comments>
		<pubDate>Wed, 27 Jun 2007 09:41:55 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CEdit]]></category>
		<category><![CDATA[Cpp]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/06/27/simple-cedit-validation.html</guid>
		<description><![CDATA[Sometime you need some CEdit Validation, for example, restricting the data number only. The simple implemetion is to handle the EN_UPDATE notification message. The EN_UPDATE message is useful to handle as it caters for both normal entry and clipboard paste. You can do that in the Dialog or subclass the CEdit class. Here is an]]></description>
			<content:encoded><![CDATA[<p>Sometime you need some CEdit Validation, for example, restricting the data number only.</p>
<p>The simple implemetion is to handle the <strong>EN_UPDATE</strong> notification message. The <strong>EN_UPDATE</strong> message is useful to handle as it caters for both normal entry and clipboard paste. You can do that in the Dialog or subclass the CEdit class.</p>
<p>Here is an example of a derived CEdit class.</p>
<p><coolcode lang="cpp" linenum="no"><br />
class CNumEdit : public CEdit<br />
{<br />
//â€¦.<br />
    afx_msg void OnUpdate();<br />
    //}}AFX_MSG </p>
<p>    DECLARE_MESSAGE_MAP()<br />
private:<br />
    CString m_strLastGood;<br />
}; </p>
<p></coolcode></p>
<p>In the cpp file:</p>
<p> <span id="more-86"></span><br />
<coolcode lang="cpp" linenum="no"><br />
BEGIN_MESSAGE_MAP(CNumEdit, CEdit)<br />
    //{{AFX_MSG_MAP(CNumEdit)<br />
    ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)<br />
    //}}AFX_MSG_MAP<br />
END_MESSAGE_MAP() </p>
<p>void CNumEdit::OnUpdate()<br />
{<br />
    CString str;<br />
    GetWindowText( str );<br />
    bool bProblem = false;<br />
    for ( int indx = 0; indx < str.GetLength(); indx++ )<br />
    {<br />
        if (( str[indx] < â€˜0â€² ) || ( str[indx] > â€˜9â€²) )<br />
        {<br />
            bProblem = true;<br />
            break;<br />
        }<br />
    }<br />
    if ( bProblem )<br />
    {<br />
        int start, end;<br />
        /* Find the current caret position */<br />
        GetSel( start, end );<br />
        /* Restore the last good text that was entered */<br />
        SetWindowText( m_strLastGood );<br />
        /* Restore the caret */<br />
        SetSel( start-1, end-1, true );<br />
        /* Let the user know */<br />
        MessageBeep( MB_OK );<br />
    }<br />
    else<br />
    {<br />
    /* Store the last good entry string in a member variable of the Hex edit class*/<br />
        m_strLastGood = str;<br />
    }<br />
} </p>
<p></coolcode></p>
<p>At last, you may find one of these meets your needs:</p>
<ul>
<li>http://www.codeproject.com/editctrl/maskededit.asp</li>
<li>http://www.codeproject.com/editctrl/validatingedit.asp</li>
</ul>

	Tags: <strong><a href="http://www.ucosoft.com/tag/cedit" title="CEdit" rel="tag">CEdit</a>, <a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/ucogrid-a-great-grid-control-of-mfc.html" title="ucoGrid, a great grid control of MFC (November 26, 2006)">ucoGrid, a great grid control of MFC</a> (18)</li>
	<li><a href="http://www.ucosoft.com/sscanf-with-cstring.html" title="sscanf with CString (March 20, 2007)">sscanf with CString</a> (3)</li>
	<li><a href="http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html" title="Solution: Crash in Release build with self-defined message (November 28, 2006)">Solution: Crash in Release build with self-defined message</a> (0)</li>
	<li><a href="http://www.ucosoft.com/simple-code-to-create-an-emf-or-bitmap-file-from-existed-draw-code.html" title="Simple code to create an EMF or Bitmap file from existed draw code (December 16, 2006)">Simple code to create an EMF or Bitmap file from existed draw code</a> (0)</li>
	<li><a href="http://www.ucosoft.com/moving-selection-of-clistctrl.html" title="Moving selection of CListCtrl (December 3, 2006)">Moving selection of CListCtrl</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html" title="How to translate among CString,string and char array (June 22, 2007)">How to translate among CString,string and char array</a> (0)</li>
	<li><a href="http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html" title="How to get ClistCtrl item text of another process (September 24, 2008)">How to get ClistCtrl item text of another process</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-check-whether-the-window-is-in-minimise-or-maximise-mode.html" title="How to check whether the window is in minimise or Maximise mode (March 21, 2007)">How to check whether the window is in minimise or Maximise mode</a> (0)</li>
	<li><a href="http://www.ucosoft.com/a-powerful-math-function-parser.html" title="A powerful math function parser(zz) (November 29, 2006)">A powerful math function parser(zz)</a> (0)</li>
	<li><a href="http://www.ucosoft.com/write-and-read-binary-data-in-variant.html" title="Write and read binary data in VARIANT (November 22, 2006)">Write and read binary data in VARIANT</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/simple-cedit-validation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
