我必须使用什么 Uxtheme 函数来获取最小化、最大化和关闭按钮的默认大小?

发布于 2024-12-26 02:07:38 字数 331 浏览 0 评论 0 原文

我正在使用 DrawThemeBackground 函数在画布上绘制一些系统元素,我需要绘制表单的标题按钮,我唯一错过的部分是如何获得标题按钮的默认大小。 是否存在任何 Uxtheme 函数来获取该信息?

在此处输入图像描述

I'm using the DrawThemeBackground function to draw some system elements on a canvas, And I need draw the title buttons of a form, the only part that i missed is how i can get the default sizes of the title buttons. Exist any Uxtheme function to get that info?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

a√萤火虫的光℡ 2025-01-02 02:07:38

看起来这比听起来更困难。

首先是 GetThemeMetric< /a> 或 GetThemeInt。但是,当您尝试检索标题按钮的属性时,您会看到很多引用,这些函数返回 0x8007490,以及一些“未找到元素”

然后是 GetThemePartSize< /a>.这个似乎有点作用。也就是说,对于 WP_CLOSEBUTTON 来说,它可以正常工作,但是对于 WP_MINBUTTON 来说,它会返回无意义的结果。无论如何,我不建议使用此函数,因为它会检索按钮的默认尺寸。例如,如果用户更改了标题大小,您将无法获得正确的值。无论如何,它可以这样调用:

uses
  uxtheme, themes;
...

var
  Err: HRESULT;
  Size: TSize;
begin
  Err := GetThemePartSize(ThemeServices.Theme[teWindow], 0,
                          WP_CLOSEBUTTON, CBS_NORMAL, nil, TS_TRUE, Size);

我不知道前两个函数如果工作的话会返回什么(当前标题栏大小或默认标题栏大小的按钮尺寸)。

获得准确结果的唯一可能方法似乎是使用WM_GETTITLEBARINFOEX 消息。但有一个缺点;它仅适用于 Vista 及更高版本。您可能需要定义消息及其使用的结构,具体取决于您使用的 Delphi 版本(此处为 D2007)。

const
  CCHILDREN_TITLEBAR = 5;
  WM_GETTITLEBARINFOEX = $033F;

type
  tagTITLEBARINFOEX = record
    cbSize: DWORD;
    rcTitleBar: TRect;
    rgstate: array[0..CCHILDREN_TITLEBAR] of DWORD;
    rgrect: array [0..CCHILDREN_TITLEBAR] of TRect;
  end;
  TITLEBARINFOEX = tagTITLEBARINFOEX;
  TTitleBarInfoEx = tagTITLEBARINFOEX;
  PTitleBarInfoEx = ^TTitleBarInfoEx;

...

var
  TitleInfo: TTitleBarInfoEx;
begin
  SendMessage(Handle, WM_GETTITLEBARINFOEX, 0, NativeInt(@TitleInfo));

然后,您可以从矩形 TitleInfo.rgrect[5] 中获取关闭按钮的大小。有关详细信息,请参阅“TITLEBARINFOEX 结构”。请注意,这些值采用屏幕坐标。

如果您需要支持 XP 和/或更低版本,我建议您使用旧的 GetSystemMetrics(SM_CXSIZE)GetSystemMetrics(SM_CYSIZE) ("窗口标题或标题栏中按钮的宽度,以像素为单位”)。您需要根据是否启用主题、是否启用航空等来进行一些近似。

Looks like this is more difficult then it sounds.

First there's GetThemeMetric or GetThemeInt. But you'll see a lot of references that these functions return a 0x8007490, 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 for WP_CLOSEBUTTON, but it returns nonsense for instance for WP_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:

uses
  uxtheme, themes;
...

var
  Err: HRESULT;
  Size: TSize;
begin
  Err := GetThemePartSize(ThemeServices.Theme[teWindow], 0,
                          WP_CLOSEBUTTON, CBS_NORMAL, nil, TS_TRUE, Size);

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).

const
  CCHILDREN_TITLEBAR = 5;
  WM_GETTITLEBARINFOEX = $033F;

type
  tagTITLEBARINFOEX = record
    cbSize: DWORD;
    rcTitleBar: TRect;
    rgstate: array[0..CCHILDREN_TITLEBAR] of DWORD;
    rgrect: array [0..CCHILDREN_TITLEBAR] of TRect;
  end;
  TITLEBARINFOEX = tagTITLEBARINFOEX;
  TTitleBarInfoEx = tagTITLEBARINFOEX;
  PTitleBarInfoEx = ^TTitleBarInfoEx;

...

var
  TitleInfo: TTitleBarInfoEx;
begin
  SendMessage(Handle, WM_GETTITLEBARINFOEX, 0, NativeInt(@TitleInfo));

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) and GetSystemMetrics(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..

时间你老了 2025-01-02 02:07:38

我认为 SystemParametersInfoSPI_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 uses iCaptionWidth to determine width.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文