Skip to content

Commit

Permalink
Merge pull request #18 from Mario1159/master
Browse files Browse the repository at this point in the history
Remove border and title bar from get and set window size
  • Loading branch information
alaingalvan authored Jul 15, 2022
2 parents 3fb97e8 + 7fc3f3f commit 3511e43
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/CrossWindow/Win32/Win32Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,19 @@ void Window::setPosition(unsigned x, unsigned y)

void Window::setSize(unsigned width, unsigned height)
{
SetWindowPos(hwnd, nullptr, -1, -1, width, height,
RECT rect, frame, border;
GetWindowRect(hwnd, &rect);
DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &frame, sizeof(RECT));

border.left = frame.left - rect.left;
border.top = frame.top - rect.top;
border.right = rect.right - frame.right;
border.bottom = rect.bottom - frame.bottom;

int titlebarHeight = (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) +
GetSystemMetrics(SM_CXPADDEDBORDER));

SetWindowPos(hwnd, nullptr, -1, -1, width + border.right + border.left, height + border.top + border.bottom + titlebarHeight,
SWP_NOMOVE | SWP_NOREDRAW);
}

Expand All @@ -290,8 +302,9 @@ UVec2 Window::getPosition() const
UVec2 Window::getWindowSize() const
{
RECT lpRect;
GetWindowRect(hwnd, &lpRect);
return UVec2(lpRect.right - lpRect.left, lpRect.bottom - lpRect.top);
DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &lpRect, sizeof(lpRect));
int titlebarHeight = (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXPADDEDBORDER));
return UVec2(lpRect.right - lpRect.left, lpRect.bottom - lpRect.top - titlebarHeight);
}

UVec2 Window::getCurrentDisplaySize() const
Expand Down

0 comments on commit 3511e43

Please sign in to comment.