简体   繁体   English

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

[英]Override tooltip text for Titlebar buttons (Close, Maximize, Minimize, Help)

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. 简而言之,我们利用Windows窗体的“帮助”按钮来实现其他目的。 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. 我知道您可以通过修改regedit中的'UserPreferencesMask'键来禁用整个操作系统的工具提示,但是我真的想有一种方法可以使它仅影响我的应用程序。

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. 同样,理想情况下,可以使用某种方法来使用托管代码,但是我不反对链接到Windows API等。

Thanks for any suggestions for resolving this issue! 感谢您提供解决此问题的建议!

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. 尽管此示例不是那么完美,但是它向您展示了这个想法。

This is an extremely interesting question. 这是一个非常有趣的问题。 My first idea was to alter the system menu, using GetSysMenu. 我的第一个想法是使用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. 然后,我尝试捕获工具提示窗口的HWND,但未成功。 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. 如果让表单(我在Delphi中工作)显示一个名为“ Test”的工具提示,则可以通过FindWindow(nil,'Test')获得其HWND,然后可以向其发送SendMessage WM_CLOSE。

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. 在这种情况下,当工具提示与客户端控件相关联时,只需使用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;

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'); 我无法通过使用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. OnHint(在Delphi中-类似的事件存在于所有本机Win32应用程序中)可能仅适用于客户端控件。 One might use the WM_NC* messages to deduce when a title bar tooltip is to be shown. 当显示标题栏工具提示时,可能会使用WM_NC *消息来推断。

暂无
暂无

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

相关问题 最小化/最大化/关闭按钮的工具提示和Devexpress lookAndFeel - Minimize/Maximize/Close buttons' tooltip and Devexpress lookAndFeel c#最大化,最小化和关闭表单上的按钮 - c# Maximize, Minimize and Close buttons on form 更改工具提示 c# winform 的最小化最大化或关闭按钮 - Change tooltip c# winform of minimize maximize or close button 如何创建带有关闭,最大化和最小化按钮的PictureBox? - How can I create a PictureBox with close, maximize, and minimize buttons? WPF RibbonWindow 最小化、最大化/恢复和关闭按钮不可见 - WPF RibbonWindow Minimize, Maximize / Restore, and Close Buttons Not Visible 隐藏最小化,最大化,关闭窗口中的按钮并显示图标 - Hide minimize, maximize, close buttons from a window and show the icon SetWindowsHookEx,然后单击冻结表单上的最小化/最大化/关闭按钮 - SetWindowsHookEx and clicking minimize/maximize/close buttons on form freezing WinForm App运行控制台-在控制台问题上禁用最小/最大化/关闭按钮 - WinForm App running a console - Disabling minimize/maximize/close buttons on console issue 使用命令绑定或事件处理程序是否是在WPF中实现“关闭”,“最小化”和“最大化”按钮的更好方法? - Is using command binding or event handler a better approach to implement Close, Minimize and Maximize Buttons in WPF? 打开菜单时,单击一次时Windows标题栏的“最小化”,“最大化”和“关闭”按钮不起作用 - Minimize, Maximize and close buttons of Windows title bar does not work on single click when Menu is open
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM