Get Window Border Metric Corresponding to Current Theme

semih artan 41 Reputation points
2021-01-03T18:35:08.107+00:00

Hello,

In my case, I call the SetWindowTheme function to disable window theming(last two params are empty string), doing so, I have a XP-styled window like this.

52780-ads%C4%B1z.jpg

As you can see, the window now has thicker edges. I use the GetSystemMetrics function but it returns wrong metrics (BorderX = 1, Caption = 23). Is there any method or API to troubleshoot this issue?

Thanks.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,841 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,431 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rita Han - MSFT 2,161 Reputation points
    2021-01-04T03:28:07.223+00:00

    Hello @semih artan ,

    I can reproduce the same result using a Win32 C++ window application. SetWindowTheme(hWnd, L"", L""); doesn't cause the window's border's width change. The same behavior found for SM_CXEDGE and SM_CXFRAME. And also you can check distance from the left of the client area to the left of the non-client, it keeps unchanged with or without calling SetWindowTheme(hWnd, L"", L""); like this:

    	GetClientRect(hWnd, &rcClient);  
    	GetWindowRect(hWnd, &rcWind);  
    	ptDiff.x = ((rcWind.right - rcWind.left) - rcClient.right) / 2;	  
    

    Based on the document: "When pszSubAppName and pszSubIdList are NULL, the theme manager removes the previously applied associations. You can prevent visual styles from being applied to a specified window by specifying an empty string, (L" ")".

    It seems removing the previously applied associations and visual styles don't affect the size of the border. What you see the bordor appearance's changes may be caused by the visual effects.

    Thank you!


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful