+        // remember where the focus was
+        wxWindow *oldFocus = m_pOldFocus;
+        if ( !oldFocus )
+        {
+            // VZ: do we really want to do this?
+            oldFocus = parent;
+        }
+
+        // We have to remember the HWND because we need to check
+        // the HWND still exists (oldFocus can be garbage when the dialog
+        // exits, if it has been destroyed)
+        HWND hwndOldFocus = oldFocus ? GetHwndOf(oldFocus) : NULL;
+
+
+        //
+        // Before entering the modal loop, reset the "is in OnIdle()" flag (see
+        // comment in app.cpp)
+        //
+        extern bool                     gbInOnIdle;
+        bool                            bWasInOnIdle = gbInOnIdle;
+
+        gbInOnIdle = FALSE;
+
+        // enter and run the modal loop
+        {
+            wxDialogModalDataTiedPtr modalData(&m_modalData,
+                                               new wxDialogModalData(this));
+            modalData->RunLoop();
+        }
+        gbInOnIdle = bWasInOnIdle;
+
+        // and restore focus
+        // Note that this code MUST NOT access the dialog object's data
+        // in case the object has been deleted (which will be the case
+        // for a modal dialog that has been destroyed before calling EndModal).
+        if ( oldFocus && (oldFocus != this) && ::WinIsWindow(vHabmain, hwndOldFocus))
+        {
+            // This is likely to prove that the object still exists
+            if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus)
+                oldFocus->SetFocus();
+        }
+    }
+
+    return GetReturnCode();
+} // end of wxDialog::ShowModal
+
+void wxDialog::EndModal(
+  int                               nRetCode
+)