覆盖标题栏按钮的工具提示文本(关闭、最大化、最小化、帮助)

发布于 2024-08-27 08:03:59 字数 377 浏览 8 评论 0原文

我一直在尝试更改表单主标题栏上的按钮显示的工具提示文本,但没有成功。

简而言之,我们利用 Windows 窗体的“帮助”按钮来实现其他目的。这工作正常。问题是,当将鼠标悬停在该按钮上时,会出现“帮助”工具提示,这对应用程序没有任何意义。

理想情况下,有某种方法可以更改我的应用程序的工具提示文本;然而,此时我只要找到一种完全禁用工具提示的方法就很满意了。

我知道您可以通过修改 regedit 中的“UserPreferencesMask”键来禁用整个操作系统的工具提示,但我真的希望有一种方法让它只影响我的应用程序。

同样,理想情况下应该有某种方法可以使用托管代码来执行此操作,但我不反对链接到 Windows API 等。

感谢您提供解决此问题的任何建议!

I have been trying without luck to change the text of the tooltip that appears for the buttons on the main title bar of a form.

In a nutshell, we have harnessed the 'Help' button for Windows Forms to have some other purpose. This is working fine. The issue is that when hovering the mouse over that button, a 'Help' tooltip appears, which doesn't make any sense for the application.

Ideally, there would be some way to change the text of that tooltip for my application; however, at this point I would be satisfied just finding a way to disable the tooltips altogether.

I know that you can disable the tooltips for the entire OS by modifying the 'UserPreferencesMask' key in regedit, but I would really like a way to have this only affect my application.

Again, ideally there would be some way to do this with managed code, but I would not be opposed to linking into the Windows API or the like.

Thanks for any suggestions for resolving this issue!

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

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

发布评论

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

评论(2

z祗昰~ 2024-09-03 08:03:59

作为解决方法,您可以不使用帮助按钮,而是:添加自定义按钮。

虽然这个示例不太完美,但它向您展示了这个想法。

As a workaround, you may not use the help button, instead: add your custom button.

Although this sample not so perfect, but it shows you the idea.

孤千羽 2024-09-03 08:03:59

这是一个非常有趣的问题。我的第一个想法是使用 GetSysMenu 更改系统菜单。我尝试删除并重命名“关闭”项目,但“关闭”按钮的工具提示没有改变。然后我尝试捕获工具提示窗口的HWND,但没有成功。如果我让表单(我在 Delphi 中工作)显示一个名为“Test”的工具提示,我可以通过 FindWindow(nil, 'Test') 获取它的 HWND,然后我可以向它发送 WM_CLOSE 消息。

在下面的示例代码中,我使用计时器不断搜索工具提示。这对性能不利,因此人们希望确切地知道工具提示何时出现。在这种情况下,当工具提示与客户端控件关联时,可以简单地使用 OnHint 事件。

procedure TForm1.Timer1Timer(Sender: TObject);
var
  h: HWND;
begin
  h := FindWindow(nil, 'Test');
  if h <> 0 then
    SendMessage(h, WM_CLOSE, 0, 0);
end;

然而,当工具提示与标题栏按钮关联时,存在两个问题。

  1. 我无法使用 FindWindow(nil, 'Close'); 获取“关闭”按钮的工具提示句柄;
  2. 如果我们能够获得句柄,我们需要一个智能的地方来编写代码 - 我们不希望它在计时器中。 OnHint(在 Delphi 中 - 所有本机 Win32 应用程序中都存在类似的事件)可能仅适用于客户端控件。人们可以使用 WM_NC* 消息来推断何时显示标题栏工具提示。

This is an extremely interesting question. My first idea was to alter the system menu, using GetSysMenu. I tried both to remove and rename the "Close" item, but the tooltip of the Close button did not change. Then I tried to capture the HWND of the tooltip window, but I did not succeed. If I let the form (I work in Delphi) display a tooltip named "Test", I can get its HWND by FindWindow(nil, 'Test'), and then I can SendMessage WM_CLOSE to it.

In the following sample code, I use a timer to constantly search for the tooltip. This is bad for performance, so one would want to find out exactly when the tooltip appears. In this case, when the tooltip is associated with a client control, one can simply use the OnHint event.

procedure TForm1.Timer1Timer(Sender: TObject);
var
  h: HWND;
begin
  h := FindWindow(nil, 'Test');
  if h <> 0 then
    SendMessage(h, WM_CLOSE, 0, 0);
end;

However, there are two problems when the tooltip is associated with the title bar buttons.

  1. I was unable to get a handle of the tooltip for the Close button by using FindWindow(nil, 'Close');
  2. If we are able to get the handle, we need a smart place to write the code - we do not want it in a timer. OnHint (in Delphi - similar events exist in all native Win32 apps) will probably only work for client controls. One might use the WM_NC* messages to deduce when a title bar tooltip is to be shown.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文