我必须使用什么 Uxtheme 函数来获取最小化、最大化和关闭按钮的默认大小?
我正在使用 DrawThemeBackground
函数在画布上绘制一些系统元素,我需要绘制表单的标题按钮,我唯一错过的部分是如何获得标题按钮的默认
大小。 是否存在任何 Uxtheme 函数来获取该信息?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来这比听起来更困难。
首先是
GetThemeMetric
< /a> 或GetThemeInt
。但是,当您尝试检索标题按钮的属性时,您会看到很多引用,这些函数返回0x8007490
,以及一些“未找到元素”。然后是
GetThemePartSize
< /a>.这个似乎有点作用。也就是说,对于WP_CLOSEBUTTON
来说,它可以正常工作,但是对于WP_MINBUTTON
来说,它会返回无意义的结果。无论如何,我不建议使用此函数,因为它会检索按钮的默认尺寸。例如,如果用户更改了标题大小,您将无法获得正确的值。无论如何,它可以这样调用:我不知道前两个函数如果工作的话会返回什么(当前标题栏大小或默认标题栏大小的按钮尺寸)。
获得准确结果的唯一可能方法似乎是使用
WM_GETTITLEBARINFOEX
消息。但有一个缺点;它仅适用于 Vista 及更高版本。您可能需要定义消息及其使用的结构,具体取决于您使用的 Delphi 版本(此处为 D2007)。然后,您可以从矩形
TitleInfo.rgrect[5]
中获取关闭按钮的大小。有关详细信息,请参阅“TITLEBARINFOEX 结构”。请注意,这些值采用屏幕坐标。如果您需要支持 XP 和/或更低版本,我建议您使用旧的
GetSystemMetrics(SM_CXSIZE)
和GetSystemMetrics(SM_CYSIZE)
("窗口标题或标题栏中按钮的宽度,以像素为单位”)。您需要根据是否启用主题、是否启用航空等来进行一些近似。Looks like this is more difficult then it sounds.
First there's
GetThemeMetric
orGetThemeInt
. But you'll see a lot of references that these functions return a0x8007490
, some "element not found", when you try to retrieve properties of caption buttons.Then there's
GetThemePartSize
. This one seems to work some. That is it works ok for instance forWP_CLOSEBUTTON
, but it returns nonsense for instance forWP_MINBUTTON
. I would not suggest this function's use anyway since it retrieves the default dimensions of the button. If the user has changed the title size for instance, you won't get correct values. Anyway, it could be called like this:I have no idea what the former two functions would return if they worked (the dimensions of buttons for current title bar size or the default title bar size).
The only possible way to get an accurate result seems to be to use the
WM_GETTITLEBARINFOEX
message. But there's a drawback; it works only for Vista and up. You may need to define the message and the struct it uses depending on the Delphi version you use (D2007 here).Then, you can get the size for the close button from the rect
TitleInfo.rgrect[5]
. See "TITLEBARINFOEX structure" for details. Notice the values are in screen coordinates.If you need to support XP and/or below, I suggest you to use the good old
GetSystemMetrics(SM_CXSIZE)
andGetSystemMetrics(SM_CYSIZE)
("The width of a button in a window caption or title bar, in pixels"). You'd need to workout some approximations depending on if themes are enabled, if aero is enabled etc..我认为 SystemParametersInfo与
SPI_GETNONCLIENTMETRICS
就是您要寻找的。我猜最小化和最大化按钮使用 NONCLIENTMETRICS.iSmCaptionWidth
关闭时使用iCaptionWidth
来确定宽度。I think SystemParametersInfo with
SPI_GETNONCLIENTMETRICS
is what you're looking for. I guess the minimize and maximize buttons use NONCLIENTMETRICS.iSmCaptionWidth
while close usesiCaptionWidth
to determine width.