GetActiveWindow
-
Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;
CDlg1 \* dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD\_DIALOG1,this);
CWnd * wnd;
wnd = (CDialog*)GetActiveWindow();
if(wnd == dlg1)
wnd->DestroyWindow();I wrote this code to close the window. How can I know that which wnidow is active? Thanks
-
Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;
CDlg1 \* dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD\_DIALOG1,this);
CWnd * wnd;
wnd = (CDialog*)GetActiveWindow();
if(wnd == dlg1)
wnd->DestroyWindow();I wrote this code to close the window. How can I know that which wnidow is active? Thanks
-
Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;
CDlg1 \* dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD\_DIALOG1,this);
CWnd * wnd;
wnd = (CDialog*)GetActiveWindow();
if(wnd == dlg1)
wnd->DestroyWindow();I wrote this code to close the window. How can I know that which wnidow is active? Thanks
iayd wrote:
CDlg1 * dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD_DIALOG1,this);
Since you're creating your child dialogs by passing your main dialog as parent, call
GetTopWindow()
by passingparent window handle
. It will give you the top most window of your application. Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
These are not working in my situations.I think the problem is not about GetActiveWindow(). The problem is that when I want to know if this window (active window) is the same window with the dialog box that I created before, it couldn't compare them. This part has problem I think;
if(dlg == wnd)
-
iayd wrote:
CDlg1 * dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD_DIALOG1,this);
Since you're creating your child dialogs by passing your main dialog as parent, call
GetTopWindow()
by passingparent window handle
. It will give you the top most window of your application. Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
Hi, There are many dialog boxes in my project. I want to know that which one is active at a certain time. For example;
CDlg1 \* dlg1; // A global object for the dialog box. dlg1= new CDlg1; dlg1->Create(IDD\_DIALOG1,this);
CWnd * wnd;
wnd = (CDialog*)GetActiveWindow();
if(wnd == dlg1)
wnd->DestroyWindow();I wrote this code to close the window. How can I know that which wnidow is active? Thanks
iayd wrote:
if(wnd == dlg1)
Use window handles instead of MFC objects to compare. Since MFC window objects are just wrappers around window handles. if( wnd.GetSafeHwnd() == dlg1.GetSafeHwnd() ) ;;//...
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com