From c48926e149739055b0ed978d9e893f7898a51a73 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 20 Aug 2001 23:02:27 +0000 Subject: [PATCH] fixes for Raise() to work correctly with both top level and child windows git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11430 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/frame.h | 1 + src/msw/frame.cpp | 10 ++++++++ src/msw/window.cpp | 53 ++++++++++++++++++------------------------ 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 22509da920..abd5752e93 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -45,6 +45,7 @@ public: virtual ~wxFrameMSW(); // implement base class pure virtuals + virtual void Raise(); virtual void Maximize(bool maximize = TRUE); virtual bool IsMaximized() const; virtual void Iconize(bool iconize = TRUE); diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index b1b4e12a8f..7013f9d85d 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -347,6 +347,16 @@ bool wxFrameMSW::Show(bool show) return TRUE; } +void wxFrameMSW::Raise() +{ +#ifdef __WIN16__ + // no SetForegroundWindow() in Win16 + wxFrameBase::Raise(); +#else // Win32 + ::SetForegroundWindow(GetHwnd()); +#endif // Win16/32 +} + void wxFrameMSW::Iconize(bool iconize) { DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 3d030562ba..0ba56334b2 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -157,7 +157,27 @@ static void TranslateKbdEventToMouse(wxWindowMSW *win, static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win); // check if the mouse is in the window or its child -//static bool IsMouseInWindow(HWND hwnd); +static bool IsMouseInWindow(HWND hwnd); + +// wrapper around BringWindowToTop() API +static inline wxBringWindowToTop(HWND hwnd) +{ +#ifdef __WXMICROWIN__ + // It seems that MicroWindows brings the _parent_ of the window to the top, + // which can be the wrong one. + + // activate (set focus to) specified window + ::SetFocus(hwnd); + + // raise top level parent to top of z order + ::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); +#else // !__WXMICROWIN__ + if ( !::BringWindowToTop(hwnd) ) + { + wxLogLastError(_T("BringWindowToTop")); + } +#endif // __WXMICROWIN__/!__WXMICROWIN__ +} // --------------------------------------------------------------------------- // event tables @@ -503,19 +523,7 @@ bool wxWindowMSW::Show(bool show) if ( show ) { -#ifdef __WXMICROWIN__ - // It seems that MicroWindows brings the _parent_ of the - // window to the top, which can be the wrong one. - - // activate (set focus to) specified window - ::SetFocus(hWnd); - - // raise top level parent to top of z order - ::SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, - SWP_NOMOVE|SWP_NOSIZE); -#else - BringWindowToTop(hWnd); -#endif + wxBringWindowToTop(hWnd); } return TRUE; @@ -524,22 +532,7 @@ bool wxWindowMSW::Show(bool show) // Raise the window to the top of the Z order void wxWindowMSW::Raise() { -#ifdef __WIN16__ - ::BringWindowToTop(GetHwnd()); -#else // Win32 -#ifdef __WXMICROWIN__ - // It seems that MicroWindows brings the _parent_ of the - // window to the top, which can be the wrong one. - - // activate (set focus to) specified window - ::SetFocus(GetHwnd()); - - // raise top level parent to top of z order - ::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); -#else - ::SetForegroundWindow(GetHwnd()); -#endif -#endif + wxBringWindowToTop(GetHwnd()); } // Lower the window to the bottom of the Z order -- 2.45.2