Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Updated 3-Dec-12 8:56am
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

Hi There,

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

Code is as follow:
C++
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();
}
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900