Masked Edit Control (3)


We had been using the MSMask.ocx control in our MFC application for almost a year. Recently a 200K memory leak was traced to the setText method (200K each time it was called), so we downloaded another masked edit class from the web, but it flickered intensely and the code was kind of icky. Anyway, I decided to write my own. Turns out it works better than I could have hoped. It's easy to use and the source code very simple allowing anyone to extend it as necessary.

In ::OnInitDialog()
m_maskEdit.SubclassDlgItem(IDC_EDIT_MASK, this);

// Initialize the control to "State: KS, Zip: 66202-1234"
m_maskEdit.setMask("State: ??, Zip: #####-####");

In ::OnOk()

// getText returns "KS66202123"
CString strTemp = m_maskEdit.getText();

// GetWindowText yields "State: KS, Zip: 66202-1234"

Download demo project - [17] KB

Download source - [2] KB


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • IDC estimates that more than 70% of organizations have a cloud-first application deployment strategy to align with digital transformation initiatives. As such, many organizations are transitioning to Microsoft Office 365 and utilizing public clouds such as Microsoft Azure. However, IT leaders are discovering that default data protection schemes are not as robust as they desire. As a result, many are turning to Veeam® to provide the necessary data management and protection policies demanded by the …

  • Milliseconds matter. Make your systems faster with an uncompromising approach to designing and deploying your cloud foundation on IBM Cloud.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date