<?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>Thu, 22 Jul 2010 05:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</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 />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/simple-cedit-validation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

