DoModal() question?
-
Hello, Can we use DoModal like this:
CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") }
I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanks -
Hello, Can we use DoModal like this:
CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") }
I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanksGofur Halmurat wrote:
I want to know when IDOK is clicked On CMyAlert,
The CMyAlert dialog will have to notify the parent window that the OK button was clicked. either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. What is your intention ? Do you want to have the dialog dismissed when the user clicks on Ok ?
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Gofur Halmurat wrote:
I want to know when IDOK is clicked On CMyAlert,
The CMyAlert dialog will have to notify the parent window that the OK button was clicked. either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. What is your intention ? Do you want to have the dialog dismissed when the user clicks on Ok ?
Maximilien Lincourt Your Head A Splode - Strong Bad
Hello, My parent window has a button, if i click the button the CMyAlert appears, and there is a button on CMyAlert, when i click the button on CMyAlert, Some changes will have to be done on parent window. How can i implement this? either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. How can i implement this option? can u show me with examples? thanks
-
Hello, My parent window has a button, if i click the button the CMyAlert appears, and there is a button on CMyAlert, when i click the button on CMyAlert, Some changes will have to be done on parent window. How can i implement this? either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked. How can i implement this option? can u show me with examples? thanks
are you wanting a modeless dialog by any chances ? if not, then why don't you do the job when the modal dialog is closed ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
are you wanting a modeless dialog by any chances ? if not, then why don't you do the job when the modal dialog is closed ?
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Hello, yes, i want a modeless dialog by any changes
-
Hello, yes, i want a modeless dialog by any changes
so you mustn't use DoModal() (which, as its name states, creates a Modal Dialog). use Create() method to create it. to have the possibility to modify the window which spamn it, you must give it a pointer to its parent (commonly,
this
) as a constructor parameter also read This[^] good article about modeless dialogs.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
so you mustn't use DoModal() (which, as its name states, creates a Modal Dialog). use Create() method to create it. to have the possibility to modify the window which spamn it, you must give it a pointer to its parent (commonly,
this
) as a constructor parameter also read This[^] good article about modeless dialogs.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Thanks, that was what i was looking for. it helped me alot
-
Hello, Can we use DoModal like this:
CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") }
I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanksAnd no, you can't use Create() and DoModal() - you use one or the other, depending on whether you want a modal or a modeless dialog. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hello, Can we use DoModal like this:
CMyAlert *alert = new CMYAlert; alert->Create(CMYAlert::IDD,this); // ... some code if (alert->DoModal()==IDOK) { message("IDOK is clicked") }
I want to know when IDOK is clicked On CMyAlert, Is there another way to know it? thanksNo. By calling the
Create
function for your alert dialog, you've made it a modeless dialog. CallingDoModal()
in this case will not work correctly. There are two solutions here. One, use the alert dialog modally:CMyAlert *alert = new CMyAlert;
if (alert->DoModal() == IDOK) {
message("IDOK is clicked");
}
delete alert;The second is to use your alert dialog as a modeless dialog, and have it send a user-defined message to the parent when the OK button is clicked, which is more complicated:
#define WM_MyAlertMessage (WM_USER + 1)
void CMyAlert::OnOK()
{
CWnd *parent = GetParent();
if (parent != NULL) {
parent->SendMessage(WM_MyAlertMessage,0,0);
}
}
BEGIN_MESSAGE_MAP(CMyParentWindow,CDialog)
ON_MESSAGE(WM_MyAlertMessage,OnMyAlertMessage)
END_MESSAGE_MAP()
LRESULT CMyParentWindow::OnMyAlertMessage(WPARAM /*wParam*/,LPARAM /*lParam*/)
{
message("IDOK is clicked");
return (LRESULT)0;
}
Software Zen:
delete this;