am2000hintwindow.pas
上传用户:powellwoo
上传日期:2007-01-07
资源大小:109k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

C++ Builder

  1. {*******************************************************}
  2. {                                                       }
  3. {       AnimatedMenus/2000                              }
  4. {       T_AM2000_HintWindow Component Unit              }
  5. {                                                       }
  6. {       Copyright (c) 1997-99 AnimatedMenus.com         }
  7. {       All rights reserved.                            }
  8. {                                                       }
  9. {*******************************************************}
  10. unit am2000hintwindow;
  11. interface
  12. uses
  13.   Windows, Messages, Controls;
  14. type
  15.   // T_AM2000_HintWindow
  16.   T_AM2000_ToolTipWindow = class
  17.   private
  18.     id: UINT;
  19.     Owner: TWinControl;
  20.     hwndOwner: HWND;
  21.     hwndToolTip: HWND;
  22.     FActive: Boolean;
  23.   public
  24.     property Active: Boolean read FActive;
  25.     constructor Create(AOwner: TWinControl);
  26.     destructor Destroy; override;
  27.     procedure AddTool(R: TRect; Hint: String);
  28.     procedure RelayMouseMove(Pos: TSmallPoint);
  29.     procedure Clear;
  30.     procedure Activate;
  31.     procedure Deactivate;
  32.   end;
  33. implementation
  34. uses
  35.   Classes, Forms;
  36. const
  37.   MAX_TOOLTIP_WINDOW_WIDTH = 220;
  38.   TOOLTIPS_CLASS = 'tooltips_class32';
  39. type
  40.   TToolInfo = packed record
  41.     cbSize: UINT;
  42.     uFlags: UINT;
  43.     hwnd: HWND;
  44.     uId: UINT;
  45.     Rect: TRect;
  46.     hInst: THandle;
  47.     lpszText: PAnsiChar;
  48.     lParam: LPARAM;
  49.   end;
  50. const
  51.   TTS_ALWAYSTIP           = $01;
  52.   TTS_NOPREFIX            = $02;
  53.   TTM_ACTIVATE            = WM_USER + 1;
  54.   TTM_SETDELAYTIME        = WM_USER + 3;
  55.   TTM_SETTIPBKCOLOR       = WM_USER + 19;
  56.   TTM_SETTIPTEXTCOLOR     = WM_USER + 20;
  57.   TTM_SETMAXTIPWIDTH      = WM_USER + 24;
  58.   TTM_ADDTOOL             = WM_USER + 4;
  59.   TTM_DELTOOL             = WM_USER + 5;
  60.   TTM_RELAYEVENT          = WM_USER + 7;
  61.   TTM_GETTOOLCOUNT        = WM_USER +13;
  62. { T_AM2000_ToolTipWindow }
  63. constructor T_AM2000_ToolTipWindow.Create(AOwner: TWinControl);
  64. begin
  65.   inherited Create;
  66.   Owner:= AOwner;
  67.   // set owner's handle
  68.   if Owner is TForm
  69.   then hwndOwner:= Owner.Handle
  70.   else hwndOwner:= 0;
  71.   hwndToolTip:= CreateWindow(TOOLTIPS_CLASS, nil, TTS_ALWAYSTIP, 0, 0, 0, 0,
  72.     hwndOwner, 0, HInstance, nil);
  73.   SendMessage(hwndToolTip, TTM_SETMAXTIPWIDTH, 0, MAX_TOOLTIP_WINDOW_WIDTH);
  74.   hwndOwner:= Owner.Handle;
  75. end;
  76. destructor T_AM2000_ToolTipWindow.Destroy;
  77. begin
  78.   DestroyWindow(hwndToolTip);
  79.   inherited;
  80. end;
  81. procedure T_AM2000_ToolTipWindow.AddTool(R: TRect; Hint: String);
  82. var
  83.   ti: TToolInfo;
  84. begin
  85.   ti.cbSize:= sizeof(TToolInfo);
  86.   ti.uFlags:= 0;
  87.   ti.hwnd:= hwndOwner;
  88.   ti.hinst:= HInstance;
  89.   ti.uId:= id;
  90.   ti.lpszText:= PChar(Hint);
  91.   Inc(id);
  92.   ti.rect:= R;
  93.   SendMessage(hwndToolTip, TTM_ADDTOOL, 0, LongInt(@ti));
  94. end;
  95. procedure T_AM2000_ToolTipWindow.RelayMouseMove(Pos: TSmallPoint);
  96. var
  97.   Msg: TMsg;
  98. begin
  99.   Msg.wParam:= 0;
  100.   Msg.lParam:= LongInt(Pos);
  101.   Msg.message:= wm_MouseMove;
  102.   Msg.hwnd:= hwndOwner;
  103.   SendMessage(hwndToolTip, ttm_RelayEvent, 0, LongInt(@Msg));
  104. end;
  105. procedure T_AM2000_ToolTipWindow.Clear;
  106. var
  107.   I: Integer;
  108.   ti: TToolInfo;
  109. begin
  110.   ti.cbSize:= SizeOf(ti);
  111.   ti.hwnd:= hwndOwner;
  112.   for I:= 0 to id -1 do begin
  113.     ti.uId:= I;
  114.     SendMessage(hwndToolTip, TTM_DELTOOL, 0, LongInt(@ti));
  115.   end;
  116.   id:= 0;
  117. end;
  118. procedure T_AM2000_ToolTipWindow.Activate;
  119. begin
  120.   if FActive then Exit;
  121.   SendMessage(hwndToolTip, TTM_ACTIVATE, 1, 0);
  122.   FActive:= True;
  123. end;
  124. procedure T_AM2000_ToolTipWindow.Deactivate;
  125. begin
  126.   if not FActive then Exit;
  127.   SendMessage(hwndToolTip, TTM_ACTIVATE, 0, 0);
  128.   FActive:= False;
  129. end;
  130. end.