X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3723b7b1d8cbeebccef4f8ad7fe3884dfca9eca6..585266618c27ac77a5e5316c03e06ffc514715c9:/src/msw/window.cpp diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 2680a55bcd..b19210ce93 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1897,7 +1897,8 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) case WM_LBUTTONDOWN: // set focus to this window - SetFocus(); + if (AcceptsFocus()) + SetFocus(); // fall through @@ -2365,14 +2366,22 @@ bool wxWindow::MSWCreate(int id, } #endif // 0 - HWND hParent = (HWND)NULL; - if ( parent ) - hParent = (HWND) parent->GetHWND(); + HWND hParent = parent ? GetHwndOf(parent) : NULL; wxWndHook = this; if ( dialog_template ) { + // for the dialogs without wxDIALOG_NO_PARENT style, use the top level + // app window as parent - this avoids creating modal dialogs without + // parent + if ( !hParent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) + { + wxWindow *winTop = wxTheApp->GetTopWindow(); + if ( winTop ) + hParent = GetHwndOf(winTop); + } + m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(), dialog_template, hParent, @@ -2380,27 +2389,37 @@ bool wxWindow::MSWCreate(int id, if ( m_hWnd == 0 ) { - wxLogError(_("Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.")); + wxLogError(_("Can't find dialog template '%s'!\nCheck resource include path for finding wx.rc."), + dialog_template); return FALSE; } - if (extendedStyle != 0) + + if ( extendedStyle != 0 ) { ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, extendedStyle); ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); + SWP_NOSIZE | + SWP_NOMOVE | + SWP_NOZORDER | + SWP_NOACTIVATE); } + #if defined(__WIN95__) // For some reason, the system menu is activated when we use the // WS_EX_CONTEXTHELP style, so let's set a reasonable icon if (extendedStyle & WS_EX_CONTEXTHELP) { - if (wxTheApp->GetTopWindow() && (wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))) + wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); + if ( winTop ) { - wxIcon icon = ((wxFrame*)wxTheApp->GetTopWindow())->GetIcon(); - if (icon.Ok()) - SendMessage(GetHwnd(), WM_SETICON, - (WPARAM)TRUE, (LPARAM)(HICON) icon.GetHICON()); + wxIcon icon = winTop->GetIcon(); + if ( icon.Ok() ) + { + ::SendMessage(GetHwnd(), WM_SETICON, + (WPARAM)TRUE, + (LPARAM)GetHiconOf(icon)); + } } } #endif // __WIN95__ @@ -2425,7 +2444,7 @@ bool wxWindow::MSWCreate(int id, wxLogLastError(wxT("MoveWindow")); } } - else + else // creating a normal window, not a dialog { int controlId = 0; if ( style & WS_CHILD ) @@ -2461,6 +2480,7 @@ bool wxWindow::MSWCreate(int id, } wxWndHook = NULL; + #ifdef __WXDEBUG__ wxNode* node = wxWinHandleList->Member(this); if (node) @@ -2471,7 +2491,8 @@ bool wxWindow::MSWCreate(int id, wxLogError(wxT("A second HWND association is being added for the same window!")); } } -#endif +#endif // Debug + wxAssociateWinWithHandle((HWND) m_hWnd, this); return TRUE; @@ -4389,9 +4410,15 @@ static TEXTMETRIC wxGetTextMetrics(const wxWindow *win) // position. wxWindow* wxFindWindowAtPointer(wxPoint& pt) { - // Use current message to find last mouse position - extern MSG s_currentMsg; - HWND hWndHit = ::WindowFromPoint(s_currentMsg.pt); + return wxFindWindowAtPoint(wxGetMousePosition()); +} + +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + POINT pt2; + pt2.x = pt.x; + pt2.y = pt.y; + HWND hWndHit = ::WindowFromPoint(pt2); wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ; HWND hWnd = hWndHit; @@ -4408,7 +4435,8 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt) // Get the current mouse position. wxPoint wxGetMousePosition() { - extern MSG s_currentMsg; - return wxPoint(s_currentMsg.pt.x, s_currentMsg.pt.y); + POINT pt; + GetCursorPos( & pt ); + return wxPoint(pt.x, pt.y); }