Click here to Skip to main content
Rate this: bad
good
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
Edited 3-Dec-12 8:56am
CPallini318.2K
v2
Comments
JackDingler at 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 at 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 at 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
0 CPallini 350
1 Sergey Alexandrovich Kryukov 320
2 BillWoodruff 309
3 George Jonsson 274
4 OriginalGriff 237
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 3 Dec 2012
Copyright © CodeProject, 1999-2014
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