各位大虾,我现在想实现输入框为空时候,用气泡实现提示信息,但网上现成的气泡代码,但没有效果出来,请高手指点。谢谢下面这个 编译通过,但点击没有气泡效果出来,怎么回事啊
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(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); //数字1可以该为其它的数字来显示不同的图标
end;还有一个SherryHint,不知道怎么调出效果来,请高手指点
unit SherryHint;interfaceuses
Windows, Messages, Classes, Controls, Forms, CommCtrl;type
THintWin=class(THintWindow)
private
FLastActive: THandle;
public
procedure ActivateHint(Rect:TRect;Const AHint:string);override;
end;implementationprocedure AddTipTool(hWnd: DWORD; IconType: Integer; Title, Text: PChar);
const
TTS_BALLOON =$0040;
TTM_SETTITLE=WM_USER + 32;
var
hWndTip: DWORD;
ToolInfo: TToolInfo;
begin
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
ToolInfo.cbSize:=SizeOf(ToolInfo);
ToolInfo.uFlags:=TTF_IDISHWND or TTF_SUBCLASS or TTF_TRANSPARENT;
ToolInfo.uId:=hWnd;
ToolInfo.lpszText:=Text;
SendMessage(hWndTip,TTM_ADDTOOL,1,Integer(@ToolInfo));
SendMessage(hWndTip,TTM_SETTITLE,IconType,Integer(Title));
end;
InitCommonControls();
end;procedure THintWin.ActivateHint(Rect:TRect;const AHint:string);
begin
if FLastActive<>WindowFromPoint(Mouse.CursorPos) then
AddTipTool(WindowFromPoint(Mouse.CursorPos),1,'Sherry SoftWare', PChar(AHint));//Application.Hint));
FLastActive:=WindowFromPoint(Mouse.CursorPos);
end;initialization
Application.HintPause:=0;
Application.ShowHint:=False;
HintWindowClass:=THintWin;
Application.ShowHint:=True;
end.
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(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); //数字1可以该为其它的数字来显示不同的图标
end;还有一个SherryHint,不知道怎么调出效果来,请高手指点
unit SherryHint;interfaceuses
Windows, Messages, Classes, Controls, Forms, CommCtrl;type
THintWin=class(THintWindow)
private
FLastActive: THandle;
public
procedure ActivateHint(Rect:TRect;Const AHint:string);override;
end;implementationprocedure AddTipTool(hWnd: DWORD; IconType: Integer; Title, Text: PChar);
const
TTS_BALLOON =$0040;
TTM_SETTITLE=WM_USER + 32;
var
hWndTip: DWORD;
ToolInfo: TToolInfo;
begin
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
ToolInfo.cbSize:=SizeOf(ToolInfo);
ToolInfo.uFlags:=TTF_IDISHWND or TTF_SUBCLASS or TTF_TRANSPARENT;
ToolInfo.uId:=hWnd;
ToolInfo.lpszText:=Text;
SendMessage(hWndTip,TTM_ADDTOOL,1,Integer(@ToolInfo));
SendMessage(hWndTip,TTM_SETTITLE,IconType,Integer(Title));
end;
InitCommonControls();
end;procedure THintWin.ActivateHint(Rect:TRect;const AHint:string);
begin
if FLastActive<>WindowFromPoint(Mouse.CursorPos) then
AddTipTool(WindowFromPoint(Mouse.CursorPos),1,'Sherry SoftWare', PChar(AHint));//Application.Hint));
FLastActive:=WindowFromPoint(Mouse.CursorPos);
end;initialization
Application.HintPause:=0;
Application.ShowHint:=False;
HintWindowClass:=THintWin;
Application.ShowHint:=True;
end.
然后Button1的ShowHint属性设为true
运行后 把鼠标移到Button1上试试气泡提示是当鼠标移上去才会激活的
要实现你的功能,你可以自己改一下
我说补充一下我要的效果:查询关键字输入框,点查询按纽的时候,如果输入框为空,气泡提示不能为空,且气泡指向输入框,当查询有结果的时候,同样气泡提示发现的记录条数。
我用的是Delphi6 ideation_shang :
Raize 是控件吗?可以实现我要的效果吗,我先搜一下先。stherix :
我不是要鼠标移上去这种的效果,你的建议我试试看
//一、方法一//效果图片如下:
//说明:这个效果不好,鼠标必须放在按钮上,气泡提示才可以出来,如果鼠标在按钮的范围之外,
// 用回车键点击按钮也不会激活气泡提示。unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,CommCtrl;
const
TTS_BALLOON = $40;
TTM_SETTITLE = (WM_USER + 32);
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(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;
二、方法二//效果图片如下:
//说明:这个方法比较好,鼠标不必放在按钮上,只要按钮有焦点,用回车和空格键都可以出现气泡提示,
// 而且气泡提示是跟着鼠标的,也就是说鼠标移动到什么地方气泡提示也会出现在那里!http://hiphotos.baidu.com/about%5F2008/pic/item/4eabbb0a16dd7a1194ca6b24.jpg//代码如下:
//说明:这个是封装的一个类,调用的时候需要创建一个实例后,再调用那个方法即可。1、类的代码:unit uHintWin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,CommCtrl;type
THintWin = class(THintWindow)
private
FLastActive: THandle;
public
procedure ActivateHint(Rect:TRect;Const AHint:string);override;
end;implementation
{ THintWin }
procedure AddTipTool(hWnd: DWORD; IconType: Integer; Title, Text: PChar);
const
TTS_BALLOON =$0040;
TTM_SETTITLE=WM_USER + 32;
var
hWndTip: DWORD;
ToolInfo: TToolInfo;
begin
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
ToolInfo.cbSize:=SizeOf(ToolInfo);
ToolInfo.uFlags:=TTF_IDISHWND or TTF_SUBCLASS or TTF_TRANSPARENT;
ToolInfo.uId:=hWnd;
ToolInfo.lpszText:=Text;
SendMessage(hWndTip,TTM_ADDTOOL,1,Integer(@ToolInfo));
SendMessage(hWndTip,TTM_SETTITLE,IconType,Integer(Title));
end;
InitCommonControls();
end;procedure THintWin.ActivateHint(Rect: TRect; const AHint: string);
begin
inherited;
if FLastActive <> WindowFromPoint(Mouse.CursorPos) then
AddTipTool(WindowFromPoint(Mouse.CursorPos),1,'Sherry SoftWare', PChar(AHint));//Application.Hint));
FLastActive:=WindowFromPoint(Mouse.CursorPos);
end;initialization
Application.HintPause:=0;
Application.ShowHint:=False;
HintWindowClass:=THintWin;
Application.ShowHint:=True;end.2、调用的代码
//说明:调用之前要引用上面这个类的单元。procedure TForm2.Button1Click(Sender: TObject);
var
a:THintWin;
Rect: TRect;
begin
a := THintWin.Create(Self);
a.ActivateHint(Rect,'测试提示气泡!');
end;
我要的效果:查询关键字输入框,点查询按纽的时候,如果输入框为空,气泡提示不能为空,且气泡指向输入框,当查询有结果的时候,同样气泡提示发现的记录条数。
我用的是Delphi6
img=http://www.bluejacky.com/hinttest.jpg][/img]我发现上面只能跟随鼠标响应,WindowFromPoint(Mouse.CursorPos),怎么把Point固定到combobox中去呢,请高手指点啊 谢谢
例如 换成Edit控件或是其他,那样不太好办,如果不变好办!
我要的效果:查询关键字输入框,点查询按纽的时候,如果输入框为空,气泡提示不能为空,且气泡指向输入框,当查询有结果的时候,同样气泡提示发现的记录条数。
我用的是Delphi6 --------------------------
7楼,你所说的效果非常简单,我写一个过程(代码极短)就可以实现你所要的,加我QQ5555044我发给你。