delphi 应用程序工厂_如何在Delphi应用程序中显示菜单项提示

delphi 应用程序工厂

Use specific coding language to program Delphi applications to display a hint, or tooltip, when the mouse hovers over a menu component. If the "ShowHint" property is set to "true" and you add text to the "hint" property, this message will be displayed when the mouse is placed over the component (a TButton, for example).

当鼠标悬停在菜单组件上时,使用特定的编码语言对Delphi应用程序进行编程以显示提示或工具提示。 如果将“ ShowHint”属性设置为“ true”,并且将文本添加到“ hint”属性,则将鼠标置于组件上方(例如TButton)时,将显示此消息。

启用菜单项提示 ( Enable Hints for Menu Items )

Because of the way Windows is designed, even if you set the value for the hint property to a menu item, the popup hint will not get displayed. However, the Windows start menu items do display hints. The favorites menu in Internet Explorer also displays menu item hints.

由于Windows的设计方式,即使您将hint属性的值设置为菜单项,也不会显示弹出提示。 但是,Windows开始菜单项确实会显示提示。 Internet Explorer中的“收藏夹”菜单还显示菜单项提示。

It is possible to use the OnHint event of the global application variable in Delphi applications to display menu item hints in a status bar.

可以在Delphi应用程序中使用全局应用程序变量的OnHint事件在状态栏中显示菜单项提示。

Windows does not expose the messages needed to support a traditional OnMouseEnter event. However, the WM_MENUSELECT message is sent when the user selects a menu item.

Windows不会公开支持传统OnMouseEnter事件所需的消息。 但是,当用户选择菜单项时,将发送WM_MENUSELECT消息。

The WM_MENUSELECT implementation of the TCustomForm (ancestor of the TForm) sets the menu item hint to "Application.Hint" so it can be used in the Application.OnHint event.

TCustomForm(TForm的祖先)的WM_MENUSELECT实现将菜单项提示设置为“ Application.Hint”,以便可以在Application.OnHint事件中使用。

If you want to add menu item popup hints (tooltips) to your Delphi application menus, focus on the WM_MenuSelect message.

如果要向Delphi应用程序菜单中添加菜单项弹出提示(工具提示),请关注WM_MenuSelect消息。

弹出提示 ( Popup Hints )

Since you cannot rely on the Application.ActivateHint method to display the hint window for menu items (as menu handling is completely done by Windows), to get the hint window displayed you must create your own version of the hint window by deriving a new class from the "THintWindow."

由于您不能依赖Application.ActivateHint方法显示菜单项的提示窗口(因为菜单处理完全由Windows完成),因此要显示显示的提示窗口,必须通过派生新类来创建自己的提示窗口版本从“ THintWindow”。

Here's how to create a TMenuItemHint class. This is a hint widow that actually gets displayed for menu items!

这是创建TMenuItemHint类的方法。 这是一个提示寡妇,实际上是为菜单项显示的!

First, you need to handle the WM_MENUSELECT Windows message:

首先,您需要处理WM_MENUSELECT Windows消息:


type
TForm1 = class(TForm)
...privateprocedure 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) thenbeginif Msg.MenuFlag and MF_POPUP = MF_POPUP thenbegin
hSubMenu := GetSubMenu(Msg.Menu, Msg.IDItem) ;
menuItem := Self.Menu.FindItem(hSubMenu, fkHandle) ;endelsebegin
menuItem := Self.Menu.FindItem(Msg.IDItem, fkCommand) ;end;end;  miHint.DoActivateHint(menuItem) ;
end
; (*WMM

Quick info: the WM_MENUSELECT message is sent to a menu's owner window when the user selects (but does not click) a menu item. Using the FindItem method of the TMenu class, you can get the menu item currently selected. Parameters of the FindItem function relate to the properties of the message received. Once we know what menu item the mouse is over, we call the DoActivateHint method of the TMenuItemHint class. The miHint variable is defined as "var miHint : TMenuItemHint" and is created in the Form's OnCreate event handler.

快速信息:当用户选择(但未单击)菜单项时,WM_MENUSELECT消息将发送到菜单的所有者窗口。 使用TMenu类的FindItem方法,可以获得当前选定的菜单项。 FindItem函数的参数与接收到的消息的属性有关。 一旦知道鼠标悬停在哪个菜单项上,就调用TMenuItemHint类的DoActivateHint方法。 miHint变量定义为“ var miHint:TMenuItemHint”,并在窗体的OnCreate事件处理程序中创建。

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

现在,剩下的就是TMenuItemHint类的实现。

Here's the interface part:

这是界面部分:


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;

Basically, the DoActivateHint function calls the ActivateHint method of the THintWindow using the TMenuItem's Hint property (if it is assigned). The showTimer is used to ensure that the HintPause of the Application elapses before the hint is displayed. The hideTimer uses Application.HintHidePause to hide the hint window after a specified interval.

Using Menu Item Hints

While some might say that it is not a good design to display hints for menu items, there are situations where actually displaying menu item hints is much better than using a status bar. A most recently used (MRU) menu item list is one such case. A custom taskbar menu is another.

翻译自: https://www.thoughtco.com/how-to-display-menu-item-hints-1058397

delphi 应用程序工厂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值