在 Delphi 11 Alexandria的Windows 10中的一个32位VCL应用程序中,我有一个TMainMenu
,每个菜单项上都有一个提示:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.AppEvnts;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
mFile: TMenuItem;
mEdit: TMenuItem;
mOpen: TMenuItem;
ApplicationEvents1: TApplicationEvents;
procedure ApplicationEvents1Hint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
CodeSiteLogging;
procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
CodeSite.Send('TForm1.ApplicationEvents1Hint: Application.Hint', Application.Hint);
end;
end.
这是DFM:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 366
ClientWidth = 639
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
Menu = MainMenu1
Position = poScreenCenter
ShowHint = True
PixelsPerInch = 120
TextHeight = 20
object MainMenu1: TMainMenu
Left = 248
Top = 144
object mFile: TMenuItem
Caption = 'File'
Hint = 'Click here to open the File menu'
object mOpen: TMenuItem
Caption = 'Open'
Hint = 'Click here to open a File'
end
end
object mEdit: TMenuItem
Caption = 'Edit'
Hint = 'Click here to open the Edit menu'
end
end
object ApplicationEvents1: TApplicationEvents
OnHint = ApplicationEvents1Hint
Left = 248
Top = 160
end
end
当我将鼠标指针悬停在“文件”菜单项上时,没有应用程序提示!只有在打开文件菜单后,当我将鼠标指针悬停在“文件”菜单项上时,我确实得到了一个Application.Hint
。
那么,当我将鼠标指针悬停在mFile
菜单项上而不打开菜单时,如何获得通知呢?
2条答案
按热度按时间xwbd5t1u1#
如果您只想对鼠标光标移动(而不是键盘输入)做出React,则处理
WM_NCMOUSEMOVE
消息:TApplicationEvents.OnHint
)已经涵盖了键盘输入(Alt或F10)。GetMenuItemRect()
和X1 E3 F1 X中的X1 M3 N1 X。
PtInRect()
精确比较X和Y:X的>=
在矩形的左边,但X的<
在右边(不是<=
); Y也一样。只有左/上包含在内,而右/下不包含在内。hkmswyz62#
我改变了你想法的逻辑,这太棒了!
你觉得呢?