How to make a modeless dialog box NOT always on top
Marty Wagner -- marty@concentra.com
Thursday, February 15, 1996
This sounds like a question which should be in a FAQ, but I couldn't
find it in either the FAQ or the MSDN.
I have a non-modal dialog box which always sits on top of my other
windows. I would like it to behave like every other window, that is,
it should be obscured by active windows.
I tried setting the WS_EX_TOPMOST style off using ModifyStyleEx, but
it seems that that style is not actually on. Something else is causing
the dialog box to always sit on top. I can't figure out what it is, so
HELP please.
Here is the code that creates the dialog and tries to make it
non-topmost:
m_pDlgErrorTrace = new CuiErrorTraceDlg ();
m_pDlgErrorTrace->InitErrorTraceDlg (pDoc);
m_pDlgErrorTrace->Create(IDD_ERROR_TRACE);
// Make it a "non-topmost" window so that it doesn't always sit on top
BOOL bSuccess = m_pDlgErrorTrace->ModifyStyleEx (WS_EX_TOPMOST, 0);
Thanks!
Marty Wagner
marty@concentra.com
Aravind Balakrishnan -- abalakri@us.oracle.com
Friday, February 16, 1996
--Boundary-16991269-0-0
I think all popup windows have this behavior of not being obscured by parent
windows. Since a dialog is a popup window, it is exhibiting this behavior.
If this is true, the workaround could be creating a window derived from
CFrameWnd, and floating the modeless dialog within it. Since the mainframe is
an overlapped window, it will hide when other windows of your application are
active.
If I am not right here, I am bound to be corrected by others! :-)
Cheers,
Aravind.
===
Aravind Balakrishnan
Systems Management Products, Oracle Corp.
(415)506-0432
Marty Fried -- mfried@linex.com
Sunday, February 18, 1996
At 11:04 AM 2/15/96 EST, marty@concentra.com wrote:
> I have a non-modal dialog box which always sits on top of my other
> windows. I would like it to behave like every other window, that is,
> it should be obscured by active windows.
I had a similar situation, and came up with a solution, but I'm not sure
whether it has any bad side effects or not. I created the dialog with
the desktop window as the parent ( GetDesktopWindow() ). I know it requires
a little more attention to what happens when you close the app, since the
dialog doesn't get a close message when the main window closes, but that isn't
really a problem.
Anyone know if this is OK?
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Marty Fried (mfried@linex.com)
Marin County, California
Mike Blaszczak -- mikeblas@msn.com
Monday, February 26, 1996
It's just fine... as long as you're careful during cleanup.
.B ekiM
TCHAR sz[] = _T("Ask me how you can get a job at Microsoft.");
----------
From: owner-mfc-l@netcom.com on behalf of Marty Fried
Sent: Sunday, February 18, 1996 12:07
To: mfc-l@netcom.com
Cc: mfc-l@netcom.com; marty@concentra.com
Subject: Re: How to make a modeless dialog box NOT always on top
At 11:04 AM 2/15/96 EST, marty@concentra.com wrote:
> I have a non-modal dialog box which always sits on top of my other
> windows. I would like it to behave like every other window, that is,
> it should be obscured by active windows.
I had a similar situation, and came up with a solution, but I'm not sure
whether it has any bad side effects or not. I created the dialog with
the desktop window as the parent ( GetDesktopWindow() ). I know it requires
a little more attention to what happens when you close the app, since the
dialog doesn't get a close message when the main window closes, but that isn't
really a problem.
Anyone know if this is OK?
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Marty Fried (mfried@linex.com)
Marin County, California
Bruce Rainwater -- rainwatr@intertex.net
Thursday, November 14, 1996
Environment: VC++ 4.1, Win 95
I have another solution to this question (This is written for a dialog based app) :
Create a modeless dialog class and add it as a member of the main dialog window:
#include "mydialog.h"
class CMainDialog : public CDialog
{
.......
CMyDialog *m_pMyDialog;
.......
}
In the main dialog window OnInitDialog() invoke the modless dialog:
void CMainDlg::OnInitDialog()
{
......
m_pMyDialog = new CMyDialog;
......
}
add "delete this" to PostNcDestroy to the modeless dialog to delete it when the
application is closed:
void CMyDialog::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PostNcDestroy();
delete this;
}
When creating modless dialogs it is suggested that DestroyWindow() be added to the OnOK
and OnCancel functions since the default implimentations of these handlers do not
destroy the dialog. My idea is to add a new public function to the dialog to handle the
destruction this way when the user clicks OK or Cancel the dialog simply hides, to close
the modeless dialog call this function from the applications OnClose() handler :
void CMyDlg::Close()
{
CDialog::OnOK();
DestroyWindow()
}
to make the modless dialog visible when needed call m_pMyDialog->ShowWindow(SW_SHOW);
to make the modless dialog hide when needed call m_pMyDialog->ShowWindow(SW_HIDE);
If it is desired that the dialog disappear when the mouse is clicked outside the dialog
add a OnLButtonDown handler to the main window and call
m_pMyDialog->ShowWindow(SW_HIDE).
When the application closes add a call to the modeless dialog's Close() function
from the main dialog window's OnClose() handler:
void CMainDlg::OnClose()
{
.....
m_pMyDialog->Close();
CDialog::OnClose();
}
This should insure that everything is cleaned up properly. This sounds a little
complicated, but it is easier to do than to describe.
Bruce Rainwater
| Вернуться в корень Архива
|