1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Draw size box for windows with WS_SIZEBOX style

This commit is contained in:
narzoul 2016-01-23 23:01:01 +01:00
parent 7555fb02d2
commit e258a17b18

View File

@ -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);
}