closing dialog by clicking on it
-
hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the
WM_RBUTTONDOWN
an i associated to it the following code :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnClose();
CDialog::OnRButtonDown(nFlags, point);
}Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling
OnClose
(), i callOnOk
() :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnOk();
CDialog::OnRButtonDown(nFlags, point);
}It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?
TOXCCT >>> GEII power
-
hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the
WM_RBUTTONDOWN
an i associated to it the following code :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnClose();
CDialog::OnRButtonDown(nFlags, point);
}Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling
OnClose
(), i callOnOk
() :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnOk();
CDialog::OnRButtonDown(nFlags, point);
}It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?
TOXCCT >>> GEII power
Why not call
EndDialog()
:-D Ant. -
Why not call
EndDialog()
:-D Ant. -
hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the
WM_RBUTTONDOWN
an i associated to it the following code :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnClose();
CDialog::OnRButtonDown(nFlags, point);
}Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling
OnClose
(), i callOnOk
() :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnOk();
CDialog::OnRButtonDown(nFlags, point);
}It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?
TOXCCT >>> GEII power
You can do it like this:
void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_CLOSE); CDialog::OnRButtonDown(nFlags, point); }
and then in OnClose(), you can do the cleanup. OnClose() is called after WM_CLOSE is processed, I guess. So it doesn't actually close the window. -
You can do it like this:
void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) { SendMessage(WM_CLOSE); CDialog::OnRButtonDown(nFlags, point); }
and then in OnClose(), you can do the cleanup. OnClose() is called after WM_CLOSE is processed, I guess. So it doesn't actually close the window. -
hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the
WM_RBUTTONDOWN
an i associated to it the following code :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnClose();
CDialog::OnRButtonDown(nFlags, point);
}Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling
OnClose
(), i callOnOk
() :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnOk();
CDialog::OnRButtonDown(nFlags, point);
}It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?
TOXCCT >>> GEII power
Any reason why
OnRButtonDown()
is callingOnLButtonDown()
? toxcct wrote: Unfortunately, it doesn't work BecauseEndDialog()
is not being called. Take a look atCDialog::OnOK()
andCDialog::OnCancel()
. Notice how they both callEndDialog()
.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Any reason why
OnRButtonDown()
is callingOnLButtonDown()
? toxcct wrote: Unfortunately, it doesn't work BecauseEndDialog()
is not being called. Take a look atCDialog::OnOK()
andCDialog::OnCancel()
. Notice how they both callEndDialog()
.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
work fine :-D thank you anyway, do you have an idea of the reasons
OnClose
() doesn't work ? would thevirtual BOOL CWnd::DestroyWindow(void);
have work better too ?
TOXCCT >>> GEII power
You would use
DestroyWindow()
for a modeless dialog andEndDialog()
for a modal dialog. OnClose() will callDestroyWindow()
anyway IIRC. However without looking I can not recall why they are done differently. Now I will have to look and find out ;) Ant. -
You would use
DestroyWindow()
for a modeless dialog andEndDialog()
for a modal dialog. OnClose() will callDestroyWindow()
anyway IIRC. However without looking I can not recall why they are done differently. Now I will have to look and find out ;) Ant.From MSDN CDialog::OnOK "If you implement the OK button in a modeless dialog box, you must override the OnOK method and call DestroyWindow from within it. Do not call the base-class method, because it calls EndDialog, which makes the dialog box invisible but does not destroy it." Had to look this up so here for your benefit too. :) Ant.
-
From MSDN CDialog::OnOK "If you implement the OK button in a modeless dialog box, you must override the OnOK method and call DestroyWindow from within it. Do not call the base-class method, because it calls EndDialog, which makes the dialog box invisible but does not destroy it." Had to look this up so here for your benefit too. :) Ant.
-
hi everybody, i designed a dialog which i'd like to close by right-click anywhere inside it. For that, i overrided the
WM_RBUTTONDOWN
an i associated to it the following code :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnClose();
CDialog::OnRButtonDown(nFlags, point);
}Unfortunately, it doesn't work :( i've been obliged to create a "OK" button which i hide, and instead of calling
OnClose
(), i callOnOk
() :void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point) {
this->OnOk();
CDialog::OnRButtonDown(nFlags, point);
}It now works, but i don't like this way of contourning the problem. can anybody tell me why my first code doesn't work, and what i could do do resolve th pb ...?
TOXCCT >>> GEII power
[Message Deleted]
-
[Message Deleted]