diff options
-rw-r--r-- | win32/PlatWin.cxx | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index f710f9fde..58ae06f97 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -1788,23 +1788,31 @@ Surface *Surface::Allocate(int technology) { #endif } +namespace { + +HWND HwndFromWindowID(WindowID wid) { + return static_cast<HWND>(wid); +} + +} + Window::~Window() { } void Window::Destroy() { if (wid) - ::DestroyWindow(static_cast<HWND>(wid)); - wid = 0; + ::DestroyWindow(HwndFromWindowID(wid)); + wid = nullptr; } PRectangle Window::GetPosition() { RECT rc; - ::GetWindowRect(static_cast<HWND>(wid), &rc); + ::GetWindowRect(HwndFromWindowID(wid), &rc); return PRectangle::FromInts(rc.left, rc.top, rc.right, rc.bottom); } void Window::SetPosition(PRectangle rc) { - ::SetWindowPos(static_cast<HWND>(wid), + ::SetWindowPos(HwndFromWindowID(wid), 0, static_cast<int>(rc.left), static_cast<int>(rc.top), static_cast<int>(rc.Width()), static_cast<int>(rc.Height()), SWP_NOZORDER | SWP_NOACTIVATE); } @@ -1830,10 +1838,10 @@ static RECT RectFromMonitor(HMONITOR hMonitor) { } void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { - const LONG style = ::GetWindowLong(static_cast<HWND>(wid), GWL_STYLE); + const LONG style = ::GetWindowLong(HwndFromWindowID(wid), GWL_STYLE); if (style & WS_POPUP) { POINT ptOther = {0, 0}; - ::ClientToScreen(static_cast<HWND>(relativeTo.GetID()), &ptOther); + ::ClientToScreen(HwndFromWindowID(relativeTo.GetID()), &ptOther); rc.Move(static_cast<XYPOSITION>(ptOther.x), static_cast<XYPOSITION>(ptOther.y)); const RECT rcMonitor = RectFromPRectangle(rc); @@ -1863,28 +1871,28 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { PRectangle Window::GetClientPosition() { RECT rc={0,0,0,0}; if (wid) - ::GetClientRect(static_cast<HWND>(wid), &rc); + ::GetClientRect(HwndFromWindowID(wid), &rc); return PRectangle::FromInts(rc.left, rc.top, rc.right, rc.bottom); } void Window::Show(bool show) { if (show) - ::ShowWindow(static_cast<HWND>(wid), SW_SHOWNOACTIVATE); + ::ShowWindow(HwndFromWindowID(wid), SW_SHOWNOACTIVATE); else - ::ShowWindow(static_cast<HWND>(wid), SW_HIDE); + ::ShowWindow(HwndFromWindowID(wid), SW_HIDE); } void Window::InvalidateAll() { - ::InvalidateRect(static_cast<HWND>(wid), NULL, FALSE); + ::InvalidateRect(HwndFromWindowID(wid), NULL, FALSE); } void Window::InvalidateRectangle(PRectangle rc) { const RECT rcw = RectFromPRectangle(rc); - ::InvalidateRect(static_cast<HWND>(wid), &rcw, FALSE); + ::InvalidateRect(HwndFromWindowID(wid), &rcw, FALSE); } void Window::SetFont(Font &font) { - ::SendMessage(static_cast<HWND>(wid), WM_SETFONT, + ::SendMessage(HwndFromWindowID(wid), WM_SETFONT, reinterpret_cast<WPARAM>(font.GetID()), 0); } @@ -2129,7 +2137,7 @@ void ListBoxX::Create(Window &parent_, int ctrlID_, Point location_, int lineHei lineHeight = lineHeight_; unicodeMode = unicodeMode_; technology = technology_; - HWND hwndParent = static_cast<HWND>(parent->GetID()); + HWND hwndParent = HwndFromWindowID(parent->GetID()); HINSTANCE hinstanceParent = GetWindowInstance(hwndParent); // Window created as popup so not clipped within parent client area wid = ::CreateWindowEx( @@ -2170,7 +2178,7 @@ int ListBoxX::GetVisibleRows() const { } HWND ListBoxX::GetHWND() const { - return static_cast<HWND>(GetID()); + return HwndFromWindowID(GetID()); } PRectangle ListBoxX::GetDesiredRect() { @@ -2611,11 +2619,9 @@ void ListBoxX::OnSelChange() { } POINT ListBoxX::GetClientExtent() const { - Window win = *this; // Copy HWND to avoid const problems - const PRectangle rc = win.GetPosition(); - POINT ret; - ret.x = static_cast<LONG>(rc.Width()); - ret.y = static_cast<LONG>(rc.Height()); + RECT rc; + ::GetWindowRect(HwndFromWindowID(wid), &rc); + POINT ret { rc.right - rc.left, rc.bottom - rc.top }; return ret; } @@ -2656,6 +2662,7 @@ void ListBoxX::Paint(HDC hDC) { LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { try { + ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd))); switch (iMessage) { case WM_ERASEBKGND: return TRUE; @@ -2663,9 +2670,9 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, case WM_PAINT: { PAINTSTRUCT ps; HDC hDC = ::BeginPaint(hWnd, &ps); - ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd))); - if (lbx) + if (lbx) { lbx->Paint(hDC); + } ::EndPaint(hWnd, &ps); } return 0; @@ -2681,7 +2688,6 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, const int item = LOWORD(lResult); if (HIWORD(lResult) == 0 && item >= 0) { ::SendMessage(hWnd, LB_SETCURSEL, item, 0); - ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd))); if (lbx) { lbx->OnSelChange(); } @@ -2693,7 +2699,6 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, return 0; case WM_LBUTTONDBLCLK: { - ListBoxX *lbx = static_cast<ListBoxX *>(PointerFromWindow(::GetParent(hWnd))); if (lbx) { lbx->OnDoubleClick(); } @@ -2719,7 +2724,7 @@ LRESULT PASCAL ListBoxX::ControlWndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { switch (iMessage) { case WM_CREATE: { - HINSTANCE hinstanceParent = GetWindowInstance(static_cast<HWND>(parent->GetID())); + HINSTANCE hinstanceParent = GetWindowInstance(HwndFromWindowID(parent->GetID())); // Note that LBS_NOINTEGRALHEIGHT is specified to fix cosmetic issue when resizing the list // but has useful side effect of speeding up list population significantly lb = ::CreateWindowEx( @@ -2755,7 +2760,7 @@ LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam case WM_COMMAND: // This is not actually needed now - the registered double click action is used // directly to action a choice from the list. - ::SendMessage(static_cast<HWND>(parent->GetID()), iMessage, wParam, lParam); + ::SendMessage(HwndFromWindowID(parent->GetID()), iMessage, wParam, lParam); break; case WM_MEASUREITEM: { @@ -2906,7 +2911,7 @@ void Menu::Destroy() { void Menu::Show(Point pt, Window &w) { ::TrackPopupMenu(static_cast<HMENU>(mid), TPM_RIGHTBUTTON, static_cast<int>(pt.x - 4), static_cast<int>(pt.y), 0, - static_cast<HWND>(w.GetID()), NULL); + HwndFromWindowID(w.GetID()), NULL); Destroy(); } |