]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/dialog.cpp
fixed wxExecute() for console programs (process messagse for the hidden window, don...
[wxWidgets.git] / src / msw / dialog.cpp
index 90ed1c507f4343236964e3e9e7cc02561325dffd..748ef0595f8a1d09be1660d5518c87efa0110668 100644 (file)
@@ -194,6 +194,28 @@ bool wxDialog::IsModalShowing() const
     return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
 }
 
+wxWindow *wxDialog::FindSuitableParent() const
+{
+    // first try to use the currently active window
+    HWND hwndFg = ::GetForegroundWindow();
+    wxWindow *parent = hwndFg ? wxFindWinFromHandle((WXHWND)hwndFg)
+                              : NULL;
+    if ( !parent )
+    {
+        // next try the main app window
+        parent = wxTheApp->GetTopWindow();
+    }
+
+    // finally, check if the parent we found is really suitable
+    if ( !parent || parent == (wxWindow *)this || !parent->IsShown() )
+    {
+        // don't use this one
+        parent = NULL;
+    }
+
+    return parent;
+}
+
 void wxDialog::DoShowModal()
 {
     wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
@@ -285,12 +307,7 @@ bool wxDialog::Show(bool show)
             // modal dialog needs a parent window, so try to find one
             if ( !GetParent() )
             {
-                wxWindow *parent = wxTheApp->GetTopWindow();
-                if ( parent && parent != this && parent->IsShown() )
-                {
-                    // use it
-                    m_parent = parent;
-                }
+                m_parent = FindSuitableParent();
             }
 
             DoShowModal();
@@ -398,14 +415,6 @@ void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
 // dialog window proc
 // ---------------------------------------------------------------------------
 
-BOOL CALLBACK wxRefreshChildProc(HWND hwnd, LPARAM WXUNUSED(lParam))
-{
-    ::InvalidateRect(hwnd, NULL, FALSE /* don't erase bg */);
-
-    // continue enumeration
-    return TRUE;
-}
-
 long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
 {
     long rc = 0;
@@ -430,7 +439,7 @@ long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
             processed = TRUE;
             if ( !HasFlag(wxNO_FULL_REPAINT_ON_RESIZE) )
             {
-                ::EnumChildWindows(GetHwnd(), wxRefreshChildProc, 0);
+                ::InvalidateRect(GetHwnd(), NULL, FALSE /* erase bg */);
             }
             break;