2020年7月20日 星期一

Display Menu Item Hints


  F_HintWindow:THintWindow;
  ..
  Private
    procedure WMMenuSelect(var Msg: TWMMenuSelect) ; message WM_MENUSELECT; 
  ..
  ..
procedure TForm1.WMMenuSelect(var Msg: TWMMenuSelect); 
var miSelectItem:TMenuItem;
  hSubMenu : HMENU;
begin
  if Msg.MenuFlag and MF_POPUP = MF_POPUP then
  begin
    hSubMenu := GetSubMenu(Msg.Menu, Msg.IDItem) ;
    miSelectItem := Self.Menu.FindItem(hSubMenu, fkHandle) ;
  end
  else
  begin
    miSelectItem := Self.Menu.FindItem(Msg.IDItem, fkCommand) ;
  end;
  //
  if not Assigned(miSelectItem) then
    Exit;
  //
  if True then
  begin
    pr_Show_HintWindow('Display Menu Item Hints');
  end
  else
  begin
    pr_Close_HintWindow;
  end;
end;

procedure TForm1.pr_Show_HintWindow(AText:String);
var pPoint:TPoint;
  iHeight, iWidth:Integer;
begin
  if not Assigned(F_HintWindow) then
    F_HintWindow := THintWindow.Create(Self);
  //
  pPoint := ClientToScreen(Mouse.CursorPos);
  iHeight := Canvas.TextHeight(AText);
  iWidth := Canvas.TextWidth(AText);
  F_HintWindow.ActivateHint(Rect(pPoint.X, pPoint.Y,pPoint.X+iWidth, pPoint.Y+iHeight), AText);
end;

procedure TForm1.pr_Close_HintWindow;
begin
  if Assigned(F_HintWindow) then
    F_HintWindow.ReleaseHandle;
end;

參考
  https://www.thoughtco.com/how-to-display-menu-item-hints-1058397

沒有留言:

張貼留言