[英]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. 但是,当工具提示与标题栏按钮相关联时,存在两个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.