views:

407

answers:

2

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!

+1  A: 

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.

Sameh Serag
I'd certainly recommend avoiding changing the purpose of standard system facilities as a rule. I can imagine this causing accessibility problems in particular for users with assistive software.
eftpotrm
This solution does not really meet my needs. We use a 3rd party library (DevExpress) to allow skinning of the WinForms components. The button that gets drawn in this case is just a flat windows button. Also, it seems to have some bad flickering problems and redraw issues.
Tim
A: 

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.
Andreas Rejbrand