YaelS

Hi,

I create MyCDialog with 3 buttons: ok(=IDCANCEL2), yes(=IDOK),no(=IDCANCEL),

(the default is IDOK & IDCANCEL).

I have bool value that if is true I set respectively :

GetDlgItem(IDCANCEL2)->ShowWindow(FALSE);

GetDlgItem(IDCANCEL)->ShowWindow(TRUE);

GetDlgItem(IDOK)->ShowWindow(TRUE);

How to set to my ok button the same as cancel button behavior (close the dialog).

Thank's,

Yael




Re: Visual C++ General CDialog

Nishant Sivakumar

By default, the OK button (with IDOK) will close the dialog. Are you overriding OnOK() by any chance




Re: Visual C++ General CDialog

YaelS

I want to add button with IDOK2 that will close me the dialog to additional to IDOK button, with what method I clode the dialog

I tried this but it's not work:

int nResponse = dlg.DoModal();

switch ( nResponse )

{

case IDOK:

break;

case IDOK2:

{

dlg.EndDialog(IDOK2);

//dlg.CloseWindow();

break;

}

default:

break;

};






Re: Visual C++ General CDialog

Sarath.

What you are doing is not correct.

Normally DoModal() function will return only after the Dialog exits and the return value of the DoModal function will be the value passing to the EndDialog function. The basic implementation of CDialog return IDOK, IDCANCEL, -1 (error creating dialog) or IDABORT

You can override IDOK, IDCANCEL functions in you dialog class and you can have your own implementation or Exiting procedures in that. One more thing you need to do is that add a message handler on clicking IDCANCEL2 function. Inside that handler call you required exit function (probably OnCancel) function.

e.g

CMyDialog::OnOK()
{
// ... custom code for IDOK
}

CMyDialog::OnCancel()
{
// ... custom code for IDCANCEL
}

CMyDialog::OnCancel2
{
// Add button message handler inside the message map
// ... Write your own implementation or call the other functions for exiting.
}


Check MSDN and learn through samples





Re: Visual C++ General CDialog

TilakGopi

Hi,

This is excerpt from MSDN-

If the user cancels a modal dialog box, the OnCancel member function terminates the dialog box and DoModal returns the value IDCANCEL. In that case, no data is exchanged between the dialog box and the dialog object.

But if the user pressess OK button, data exchange will be done first and then the dialog will closed.This is the basic difference between OK and Cancel buttons.

How to set to my ok button the same as cancel button behavior (close the dialog).

for this u can modify ur code as follows

[code language="c++]

int nResponse = dlg.DoModal();

switch ( nResponse )

{

case IDOK:

dlg.EndDialog(IDOK);

break;

case IDOK2:

{

UpdateData(TRUE);

dlg.EndDialog(IDOK2);

//dlg.CloseWindow();

break;

}

default:

break;

};

[/code]

Hope , ur doubt is cleared.

Thanx,

Ch.T.Gopi Kumar.






Re: Visual C++ General CDialog

YaelS

Thanks