procedure TForm1.TreeView1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
const
TOOLTIPS_CLASS = 'tooltips_class32';
TTS_ALWAYSTIP = $01;
TTS_NOPREFIX = $02;
TTS_BALLOON = $40;
TTF_SUBCLASS = $0010;
TTF_TRANSPARENT = $0100;
TTF_CENTERTIP = $0002;
TTM_ADDTOOL = $0400 + 50;
TTM_SETTITLE = (WM_USER + 32);
ICC_WIN95_CLASSES = $000000FF;
type
TOOLINFO = packed record
cbSize: Integer;
uFlags: Integer;
hwnd: THandle;
uId: Integer;
rect: TRect;
hinst: THandle;
lpszText: PWideChar;
lParam: Integer;
end;
var
i,lleft,ltop,l:integer;
n:tTreenode;
a:tPoint;
r:trect;
hWndTip: THandle;
ti: TOOLINFO;
hWnd: THandle;
begin
with treeview1 do
begin
n:=getnodeat(x,y);
if n=nil then exit;
i:=n.AbsoluteIndex;
if posises=i then exit;
r:=n.DisplayRect(true);
a:=ClientToScreen(r.TopLeft);
l:=canvas.TextWidth(n.Text);
if (n.Level+1)*19+l<=width then exit;
if a.X+l>screen.Width then
a.x:=screen.Width-l;
hWnd := treeview1.Handle;
hWndTip := CreateWindow(TOOLTIPS_CLASS, nil,
WS_POPUP or TTS_NOPREFIX or TTS_BALLOON or TTS_ALWAYSTIP,
0, 0, 0, 0, hWnd, 0, HInstance, nil);
if hWndTip <> 0 then
begin
SetWindowPos(hWndTip, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
ti.cbSize := SizeOf(ti);
ti.uFlags := TTF_CENTERTIP or TTF_TRANSPARENT or TTF_SUBCLASS;
ti.hwnd := hWnd;
ti.lpszText := pwidechar(n.Text);
ti.rect.Left:=a.X;
ti.rect.Top:=a.Y;
ti.rect.Right:=r.Right;
ti.rect.Bottom:=r.Bottom;
Windows.GetClientRect(hWnd, ti.rect);
SendMessage(hWndTip, TTM_ADDTOOL, 1, Integer(@ti));
end;
end;
end;
Y: Integer);
const
TOOLTIPS_CLASS = 'tooltips_class32';
TTS_ALWAYSTIP = $01;
TTS_NOPREFIX = $02;
TTS_BALLOON = $40;
TTF_SUBCLASS = $0010;
TTF_TRANSPARENT = $0100;
TTF_CENTERTIP = $0002;
TTM_ADDTOOL = $0400 + 50;
TTM_SETTITLE = (WM_USER + 32);
ICC_WIN95_CLASSES = $000000FF;
type
TOOLINFO = packed record
cbSize: Integer;
uFlags: Integer;
hwnd: THandle;
uId: Integer;
rect: TRect;
hinst: THandle;
lpszText: PWideChar;
lParam: Integer;
end;
var
i,lleft,ltop,l:integer;
n:tTreenode;
a:tPoint;
r:trect;
hWndTip: THandle;
ti: TOOLINFO;
hWnd: THandle;
begin
with treeview1 do
begin
n:=getnodeat(x,y);
if n=nil then exit;
i:=n.AbsoluteIndex;
if posises=i then exit;
r:=n.DisplayRect(true);
a:=ClientToScreen(r.TopLeft);
l:=canvas.TextWidth(n.Text);
if (n.Level+1)*19+l<=width then exit;
if a.X+l>screen.Width then
a.x:=screen.Width-l;
hWnd := treeview1.Handle;
hWndTip := CreateWindow(TOOLTIPS_CLASS, nil,
WS_POPUP or TTS_NOPREFIX or TTS_BALLOON or TTS_ALWAYSTIP,
0, 0, 0, 0, hWnd, 0, HInstance, nil);
if hWndTip <> 0 then
begin
SetWindowPos(hWndTip, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
ti.cbSize := SizeOf(ti);
ti.uFlags := TTF_CENTERTIP or TTF_TRANSPARENT or TTF_SUBCLASS;
ti.hwnd := hWnd;
ti.lpszText := pwidechar(n.Text);
ti.rect.Left:=a.X;
ti.rect.Top:=a.Y;
ti.rect.Right:=r.Right;
ti.rect.Bottom:=r.Bottom;
Windows.GetClientRect(hWnd, ti.rect);
SendMessage(hWndTip, TTM_ADDTOOL, 1, Integer(@ti));
end;
end;
end;
解决方案 »
- 打开网页,如何屏蔽掉flash,声音,activex控件
- 调用存储过程
- 关于Form的FormStyle属性
- 怎样将影音文件以二进制的形式上传到数据库中
- 一个窗口显示问题?
- 高手请进,请教条SQL语句,怎样将table1的数据插到table2中.
- 如何将自解压文件解压到指定目录,并自动运行其中的某个文件?
- 请教一个用线程做一个动画的问题!
- 我的三个MDISA问题怎么就没人知道?没有高手吗?
- delphi 调用C写的动态库,传入指针型record,传出也一样,但是在返回参数解析时导致我的程序死机
- TestComplete IDispatch问题
- ehlib4 DBDateTimeEditEh readonly无效
没有一句注释,对问题也没有详细的解释,不知道楼主在说什么。
你要显示提示,一句ShowMessage不就搞定了?不知道楼主Create了一个Window为哪般。
为何不能显示提示?
unit Unit1;interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs,commctrl, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
RadioButton1: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; const TTS_BALLOON = $40;
TTM_SETTITLE = (WM_USER + 32); var
Form1: TForm1;
hTooltip: Cardinal;
ti: TToolInfo;
buffer : array[0..255] of char; implementation
{$R *.dfm}procedure CreateToolTips(hWnd: Cardinal);
begin
hToolTip := CreateWindowEx(0, 'Tooltips_Class32', nil, TTS_ALWAYSTIP or
TTS_BALLOON, Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT), hWnd, 0, hInstance, nil);
if hToolTip <> 0 then
begin
SetWindowPos(hToolTip, HWND_TOPMOST, 0,0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE); ti.cbSize := SizeOf(TToolInfo);
ti.uFlags := TTF_SUBCLASS or TTF_TRANSPARENT;
ti.hInst := hInstance;
end;
end;
procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer;
Text, Title: PChar; BackColor,TextColor:TColor); //BackColor,TextColor分别是背景颜色和文本颜色,如果是0则取默认值.
var
Rect: TRect;
begin
if (hwnd <> 0) AND (GetClientRect(hwnd, Rect)) then
begin
lpti.hwnd := hwnd;
lpti.Rect := Rect;
lpti.lpszText := Text;
SendMessage(hToolTip, TTM_ADDTOOL, 0, Integer(lpti));
FillChar(buffer, sizeof(buffer), #0);
lstrcpy(buffer, Title);
if (IconType > 3) or (IconType < 0) then
IconType := 0;
if BackColor<>0 then
SendMessage(hToolTip, TTM_SETTIPBKCOLOR, BackColor, 0);
if TextColor<>0 then
SendMessage(hToolTip, TTM_SETTIPTEXTCOLOR, TextColor, 0);
SendMessage(hToolTip, TTM_SETTITLE, IconType, Integer(@buffer));
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
CreateToolTips(Button1.Handle);
AddToolTip(Button1.Handle, @ti, 1, '提示内容', '提示标题',0,0);
end;procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
if Components[i] is TWinControl then
begin
CreateToolTips(TWinControl(Components[i]).Handle);
AddToolTip(TWinControl(Components[i]).Handle, @ti, 1,'Abc' , '提示标题',0,0);
end;
end;
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,CommCtrl, StdCtrls;
const
TTS_BALLOON = $40;
TTM_SETTITLE = (WM_USER + 32);
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Edit1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
hTooltip: Cardinal;
ti: TToolInfo;
buffer : array[0..255] of char;
implementation{$R *.dfm}procedure CreateToolTips(hWnd: Cardinal);
begin
hToolTip := CreateWindowEx(0, 'Tooltips_Class32', nil, TTS_ALWAYSTIP or TTS_BALLOON,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT), hWnd, 0, hInstance, nil);
if hToolTip <> 0 then
begin
SetWindowPos(hToolTip, HWND_TOPMOST, 0,0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE or SWP_NOACTIVATE);
ti.cbSize := SizeOf(TToolInfo);
ti.uFlags := TTF_SUBCLASS or TTF_TRANSPARENT;
ti.hInst := hInstance;
end;
end;//BackColor,TextColor分别是背景颜色和文本颜色,如果是0则取默认值.
procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer; Text, Title: PChar;
BackColor,TextColor:TColor);
var
Rect: TRect;
begin
if (hwnd <> 0) AND (GetClientRect(hwnd, Rect)) then
begin
lpti.hwnd := hwnd;
lpti.Rect := Rect;
lpti.lpszText := Text;
SendMessage(hToolTip, TTM_ADDTOOL, 0, Integer(lpti));
FillChar(buffer, sizeof(buffer), #0);
lstrcpy(buffer, Title);
if (IconType > 3) or (IconType < 0) then IconType := 0;
if BackColor <> 0 then
SendMessage(hToolTip, TTM_SETTIPBKCOLOR, BackColor, 0);
if TextColor <> 0 then
SendMessage(hToolTip, TTM_SETTIPTEXTCOLOR, TextColor, 0);
SendMessage(hToolTip, TTM_SETTITLE, IconType, Integer(@buffer));
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
CreateToolTips(Button1.Handle);
AddToolTip(Button1.Handle, @ti, 1, '提示内容', '提示标题',0,0); //数字1可以该为其它的数字来显示不同的图标
end;procedure TForm1.Edit1Click(Sender: TObject);
begin
CreateToolTips(edit1.Handle);
AddToolTip(edit1.Handle, @ti, 1, '电脑你好', '亲爱的',0,0); //数字1可以该为其它的数字来显示不同的图标
end;end.
仅供参考
SWP_NOSIZE or SWP_NOACTIVATE);
根本没意义。另外楼主的用法就不正确。 气泡两种方式显示,一种是发送消息,一个是鼠标停留指定时间后,自动显示出来。
楼主用的是哪种呢?