简体   繁体   English

获取主题编辑控件的非客户区域的大小

[英]Get the size of non-client area of a themed Edit Control

How do you get the width of the border (non-client) of a themed Edit control in Windows XP and later versions? 如何获得Windows XP及更高版本中主题Edit控件的边框(非客户端)的宽度?

On Windows 7 GetThemeMetric with TMT_BORDERSIZE as property identifier returns 0 for an existing edit control and 1 if no handle is provided. 在Windows 7 GetThemeMetric带有TMT_BORDERSIZE作为属性标识符,对于现有编辑控件,返回0;如果未提供句柄,则返回1。 But on closer inspection it seems it should be 2. 但经过仔细检查,它似乎应该是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. WS_VSCROLL包含WS_VSCROLLWS_HSCROLL窗口样式时,滚动条将在该边框内绘制,它们实际上距离控件的外边缘2个像素,因此我假设有一种获取正确信息的方法。

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. 查询的原因是我在创建自定义控件时发生WM_NCCALCSIZE时能够设置客户区大小。

在此输入图像描述

How do you get the width of the border (non-client) of a themed Edit control in Windows XP and later versions? 如何获得Windows XP及更高版本中主题Edit控件的边框(非客户端)的宽度?

The following works for all controls, whether they are themed or not. 以下适用于所有控件,无论它们是否为主题。 It doesn't even need the theme API. 它甚至不需要主题API。

  1. Call GetClientRect() to get the size of the client area. 调用GetClientRect()以获取客户区的大小。
  2. Call ClientToScreen() to transform client rect to screen coordinates. 调用ClientToScreen()将客户端rect转换为屏幕坐标。
  3. Call GetWindowRect() to get the rectangle of the control including NC area, in screen coordinates. 调用GetWindowRect()以获取控件的矩形,包括NC区域,在屏幕坐标中。
  4. Calculate difference between client rect and window rect coordinates to get size of border (eg leftBorderWidth = clientRect.left - windowRect.left ). 计算客户端rect和window rect坐标之间的差异以获得边框的大小(例如, leftBorderWidth = clientRect.left - windowRect.left )。

Edit: 编辑:

Interestingly, the Wine source theme_edit.c doesn't use GetThemeMetric() at all. 有趣的是,Wine源theme_edit.c根本不使用GetThemeMetric() Instead they call GetSystemMetrics() with SM_CXEDGE and SM_CYEDGE . 相反,他们使用SM_CXEDGESM_CYEDGE调用GetSystemMetrics()

On my systems (Windows 7 and Windows 10), this returns the correct value of 2 . 在我的系统(Windows 7和Windows 10)上,这将返回正确的值2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用自定义绘制的标题栏扩展窗体上的非客户区域 - Extend non-client area on form with custom drawn titlebar 如何计算 WPF 中的非客户端窗口大小? - How do I compute the non-client window size in WPF? 使非客户区域无效 - Invalidating non-client areas (Win API)我无法使用WM_NCPAINT更改标题栏(非工作区)的颜色 - (Win API) I cannot change title bar (non-client area) color with WM_NCPAINT 缩放非客户区(标题栏、菜单栏)以支持每个显示器的高 DPI - Scaling the non-client area (title bar, menu bar) for per-monitor high-DPI support 如何获取 window 相对于 window 的非客户端矩形的客户端矩形偏移量? - How to get the client rect offsets of a window relative to the non-client rect of that window? Winapi:处理自定义和默认的非客户端控件 - Winapi : Handling custom and default non-client controls 在哪里可以找到详细说明各种类型的窗口的非客户端尺寸的图? - Where can I find diagrams detailing non-client dimensions of various types of windows? Windows Messaging-通过非客户端区域获取设备上下文的各种方法 - Windows Messaging - Various ways to get a Device Context with the non client area 如何处理非客户区域上的按钮事件 - How to handle event of push button on non client area
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM