Reputation: 1607
How do you get the width of the border (non-client) of a themed Edit control in Windows XP and later versions?
On Windows 7 GetThemeMetric
with TMT_BORDERSIZE
as property identifier returns 0 for an existing edit control and 1 if no handle is provided. But on closer inspection it seems it should be 2.
When WS_VSCROLL
or WS_HSCROLL
windows styles are included for the control then the scrollbars are drawn inside that border and they are indeed 2 pixels away from the outside edge of the control, so I assume there is a way of getting the correct information.
The reason for the query is for me to be able to set the client area size when WM_NCCALCSIZE
occurs when creating a custom control.
Upvotes: 4
Views: 1471
Reputation: 27776
How do you get the width of the border (non-client) of a themed Edit control in Windows XP and later versions?
The following works for all controls, whether they are themed or not. It doesn't even need the theme API.
GetClientRect()
to get the size of the client area.ClientToScreen()
to transform client rect to screen coordinates.GetWindowRect()
to get the rectangle of the control including NC area, in screen coordinates.leftBorderWidth = clientRect.left - windowRect.left
).Edit:
Interestingly, the Wine source theme_edit.c doesn't use GetThemeMetric()
at all. Instead they call GetSystemMetrics()
with SM_CXEDGE
and SM_CYEDGE
.
On my systems (Windows 7 and Windows 10), this returns the correct value of 2
.
Upvotes: 6