WinUI3 : How to get Width/ Height of the windows default border and titlebar

Harshithraj1871 1,681 Reputation points
2023-12-05T09:38:05.5766667+00:00

Hi,

I'm working on WinUI3 desktop application in c++ without using XAML. After creating the WinUi3 window, I set its height and width with SetWindowPos with (1000, 600) dimension. But when I get the Window.SizeChanged Event the Width and height will be lesser than the one which i have set, which is (984,561).

As i can understand, this is the client area not the whole windows area.

So now when i set Height and width of the window, i will have to dimension the contents as per the Client area not the height and width i have set.

So how can i get Width/ Height of the windows default border and titlebar (NON-cleant area) so that i can dimension my contents correctly.

[ I could have used GetClientArea(), but my dimensioning will happen before the window is created, so i want to know the client area before the window is created, so im checking for default non client area sizes]

I tried using GetSystemMetrics (SM_CXSIZEFRAME); but the result was not adding up.

What is the right way to get windows default height/width on the border and titlebar?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
866 questions
{count} votes

Accepted answer
  1. RLWA32 48,056 Reputation points
    2023-12-05T11:54:24.4833333+00:00

    I don't know if these will be useful for a WinUI3 application but you might want to take a look at AdjustWindowRect, AdjustWindowRectEx and AdjustWindowRectExForDpi.

    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.