Validating Changes in a Dialog | CodeGuru

Validating Changes in a Dialog

The cChangeValidate class is a useful tool for validating changes that a user may or may not have made to a dialog. For example, take for instance that a user pops up a dialog that has 3 buttons and an edit box. All 3 buttons are checked, and there is no text in the edit […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 6, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

The cChangeValidate class is a useful tool for validating changes that a user may or may not have made
to a dialog. For example, take for instance that a user pops up a dialog that has 3 buttons and an edit box.
All 3 buttons are checked, and there is no text in the edit box. If the user does not uncheck ANY of the check boxes
AND does not put any text into the edit box, they have in effect made no changes. Now when they press OK (or whichever
button performs processing), if you were doing a whole bunch of processing from the root app (such as database calls, updates
to activity logs, etc….) that aren’t necessary because you have in effect not made any changes, why do it?

cChangeValidate is extremely easy to implement and use. It was written in a very basic form, and anyone should be
able to incorporate it into their project with a minimum of difficulty. Note: cChangeValidate only stores the data for
Combo Boxes, Edits, Buttons, and List Controls. If you wish to store data for say Static text or a specific class, just
add another check in the cChangeValidate CALLBACK functions for your class and perform data storage and checking as necessary.
Below is some sample code to actually run the class.

void Foo::Init()
{
 // cChangeValidateClass is a member variable of whichever class 
 // wants to use it. It must be global in scope and not local 
 // otherwise you obviously would not be able to store the data 
 // for later use
 cChangeValidateClass.CycleControls( GetSafeHwnd());
 return;
}
void Foo::OnOK()
{
 if( cChangeValidateClass.Compare())
 {
  //data has not been changed
  OnCancel(); 	//Or whichever process you wish to perform
  return;
 }
 //If data has been changed continue with processing
}

Downloads

Download source – 3 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.