How to Display Menu Item Hints in Delphi Applications

Menu Item Hints in Delphi Applications. Use specific coding language to application Delphi applications to show a hint, or tooltip. While the mouse hovers over a menu aspect.

If the “ShowHint” property is about to “actual” and you add textual content to the “hint” assets. This message may be displayed while the mouse is placed over the issue (a TButton, for instance).

Menu Item Hints in Delphi Applications, Enable Hints for Menu Items

Menu Item Hints in Delphi Applications. Because of the way Windows is designed. Eeven in case you set the cost for the hint property to a menu item. The popup hint will now not get displayed.

However, the Windows start menu gadgets do display tips. The favorites menu in Internet Explorer additionally presentations menu item suggestions.

It is possible to apply the OnHint event of the global utility. Variable in Delphi programs to display menu item pointers in a standing bar.

Windows does now not disclose the messages needed to support a conventional OnMouseEnter occasion. However, the WM_MENUSELECT message is sent when the consumer selects a menu item.

The WM_MENUSELECT implementation of the TCustomForm (ancestor of the TForm). Sets the menu object hint to “Application.Hint” so it could be used in the Application.OnHint event.

If you want to feature menu object popup recommendations (tooltips) for your Delphi utility menus, awareness at the WM_MenuSelect message.

Popup Hints

Since you can’t rely on the Application.ActivateHint technique to show. The hint window for menu objects (as menu managing is absolutely performed with the aid of Windows).

To get the hint window displayed you must create your personal version of the hint. Window through deriving a new magnificence from the “THintWindow.”

Here’s a way to create a TMenuItemHint elegance. This is a hint widow that definitely gets displayed for menu items!

First, you want to deal with the WM_MENUSELECT Windows message:

type
 TForm1 = class(TForm)
 ...
 private
 procedure WMMenuSelect(var Msg: TWMMenuSelect) ; message WM_MENUSELECT;
 end...
implementation...
procedure TForm1.WMMenuSelect(var Msg: TWMMenuSelect) ;
var  menuItem : TMenuItem;  hSubMenu : HMENU;
begin
 inherited; // from TCustomForm (so that Application.Hint is assigned)
 menuItem := nil;
 if (Msg.MenuFlag <> $FFFF) or (Msg.IDItem <> 0) then
 begin
 if Msg.MenuFlag and MF_POPUP = MF_POPUP then
 begin
 hSubMenu := GetSubMenu(Msg.Menu, Msg.IDItem) ;
 menuItem := Self.Menu.FindItem(hSubMenu, fkHandle) ;
 end
 else
 begin
 menuItem := Self.Menu.FindItem(Msg.IDItem, fkCommand) ;
 end;
 end;  miHint.DoActivateHint(menuItem) ;
end; (*WMMenuSelect*) 

Quick info: the WM_MENUSELECT message is despatched to a menu’s owner window. While the person selects (however does now not click) a menu item.

Using the FindItem technique of the TMenu magnificence, you may get the menu object presently selected.

Parameters of the FindItem feature relate to the houses of the message acquired. Once we recognize what menu object the mouse is over, we name the DoActivateHint technique of the TMenuItemHint magnificence.

The miHint variable is described as “var miHint : TMenuItemHint” and is created in the Form’s OnCreate occasion handler.

Now, what’s left is the implementation of the TMenuItemHint class.

Here’s the interface element:

TMenuItemHint = class(THintWindow)
private
 activeMenuItem : TMenuItem;
 showTimer : TTimer;
 hideTimer : TTimer;
 procedure HideTime(Sender : TObject) ;
 procedure ShowTime(Sender : TObject) ;
public
 constructor Create(AOwner : TComponent) ; override;
 procedure DoActivateHint(menuItem : TMenuItem) ;
 destructor Destroy; override;
end;

Basically, the DoActivateHint function calls the ActivateHint approach of the THintWindow. The usage of the TMenuItem’s Hint belongings (if it’s miles assigned).

The showTimer is used to make sure that the HintPause of the Application elapses earlier than the hint is displayed.

The hideTimer makes use of Application.HintHidePause to hide the trace window after a designated c program languageperiod.

Using Menu Item Hints

While a few would possibly say that it is not an awesome design to show recommendations for menu objects.

There are conditions wherein clearly showing menu object pointers is lots higher than the use of a status bar. A maximum recently used (MRU) menu object listing is one such case. A custom taskbar menu is another.