From e258a17b18ed7413863934fb56381a5e10965f82 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 23 Jan 2016 23:01:01 +0100 Subject: [PATCH] Draw size box for windows with WS_SIZEBOX style --- DDrawCompat/CompatGdiWinProc.cpp | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/DDrawCompat/CompatGdiWinProc.cpp b/DDrawCompat/CompatGdiWinProc.cpp index 1cda7dd..025a1df 100644 --- a/DDrawCompat/CompatGdiWinProc.cpp +++ b/DDrawCompat/CompatGdiWinProc.cpp @@ -10,6 +10,7 @@ namespace { void eraseBackground(HWND hwnd, HDC dc); + bool isScrollBarVisible(HWND hwnd, LONG windowStyles, LONG sbStyle, LONG sbObjectId); void ncPaint(HWND hwnd); void updateScrolledWindow(HWND hwnd); @@ -45,6 +46,36 @@ namespace return CallNextHookEx(nullptr, nCode, wParam, lParam); } + void drawSizeBox(HWND hwnd, HDC compatDc, const RECT& windowRect, const RECT& clientRect) + { + LONG style = GetWindowLongPtr(hwnd, GWL_STYLE); + if (!(style & WS_SIZEBOX)) + { + return; + } + + int width = GetSystemMetrics(SM_CXHSCROLL); + int height = GetSystemMetrics(SM_CXVSCROLL); + RECT sizeBoxRect = { 0, 0, width, height }; + + const bool isVisibleH = isScrollBarVisible(hwnd, style, WS_HSCROLL, OBJID_HSCROLL); + const bool isVisibleV = isScrollBarVisible(hwnd, style, WS_VSCROLL, OBJID_VSCROLL); + + OffsetRect(&sizeBoxRect, + clientRect.right - (!isVisibleH ? width : 0), + clientRect.bottom - (!isVisibleV ? height : 0)); + + if (!isVisibleH || !isVisibleV) + { + HRGN sizeBoxRgn = CreateRectRgnIndirect(&sizeBoxRect); + OffsetRgn(sizeBoxRgn, windowRect.left, windowRect.top); + ExtSelectClipRgn(compatDc, sizeBoxRgn, RGN_OR); + DeleteObject(sizeBoxRgn); + } + + CALL_ORIG_GDI(DrawFrameControl)(compatDc, &sizeBoxRect, DFC_SCROLL, DFCS_SCROLLSIZEGRIP); + } + void eraseBackground(HWND hwnd, HDC dc) { if (CompatGdi::beginGdiRendering()) @@ -59,6 +90,20 @@ namespace } } + bool isScrollBarVisible(HWND hwnd, LONG windowStyles, LONG sbStyle, LONG sbObjectId) + { + if (!(windowStyles & sbStyle)) + { + return false; + } + + SCROLLBARINFO sbi = {}; + sbi.cbSize = sizeof(sbi); + GetScrollBarInfo(hwnd, sbObjectId, &sbi); + + return !(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN)); + } + LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam) { if (HC_ACTION == nCode) @@ -97,6 +142,8 @@ namespace CALL_ORIG_GDI(BitBlt)(compatDc, 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, windowDc, 0, 0, SRCCOPY); + drawSizeBox(hwnd, compatDc, windowRect, clientRect); + CompatGdiDc::releaseDc(windowDc); }