Click here to Skip to main content
12,445,916 members (64,424 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++ MFC
Please could someone assist me.

I have a dialog that has a few edit controls that must all add up to equal 100. The user can change the values of the edit controls but they must always add up to 100.

I would like to know how to overide OnOK so that when the user clicks ok, if the total does not equal 100 a message pops up and the dialog stays open so the user can correct the values

or when the user clicks the OK button, if the total does equal 100 the dialog closes.

I have figured out how to overide the OnOK by checking the total and popping up a message if the total doesn't equal 100, but after the message pops up the dialog closes which it must not do, rather it must stay open so the user can fix the values.

Thanks
Posted 3-Dec-12 0:56am
Updated 3-Dec-12 8:56am
CPallini387.8K
v2
Comments
JackDingler 3-Dec-12 12:57pm
   
Another way to approach this is to disable the OK button on start up and evaluate the values with every key entry. When the values satisfy the condition enable the button, when they don't, disable it.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi There,

I sorted it myself and it works as I want it to.

Code is as follow:
void CTestDlg::OnBnClickedOk()
{
    CString percentage;
    percentage.Format(L"Percentage total does not equal 100");
 
    if  ((inp_TestEdit) > 100)
        AfxMessageBox(percentage);
 
    else if ((inp_TestEdit) < 100)
        AfxMessageBox(percentage);
 
    else
        CDialog::OnOK();
}
  Permalink  
v2
Comments
Richard MacCutchan 4-Dec-12 4:48am
   
You should really be overriding OnOK which can be called when the user presses the enter key if your OK button is the default.
Argonia 4-Dec-12 10:18am
   
i think you can just do it with one if else construction using the operator !=

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.160811.3 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2016
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