高手请进——自动气泡窗口 ( 积分: 100 )

  • 主题发起人 主题发起人 gotiger
  • 开始时间 开始时间
G

gotiger

Unregistered / Unconfirmed
GUEST, unregistred user!
我用下面的方法实现的气泡窗口,但是只能在鼠标移动到控件上才会显示气泡窗口。请问怎么实现自动显示。比如5秒显示一次。<br><br>unit&nbsp;BalloonToolTips;<br><br>interface<br><br>&nbsp;uses<br>&nbsp;&nbsp;Windows,&nbsp;Messages,&nbsp;SysUtils,&nbsp;Variants,&nbsp;Classes,&nbsp;Graphics,&nbsp;Controls,&nbsp;Forms,<br>&nbsp;&nbsp;Dialogs,commctrl,&nbsp;StdCtrls;<br>const<br>&nbsp;TTS_BALLOON&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;$40;<br>&nbsp;TTM_SETTITLE&nbsp;=&nbsp;(WM_USER&nbsp;+&nbsp;32);<br><br>var<br>&nbsp;hTooltip:&nbsp;Cardinal;<br>&nbsp;ti:&nbsp;TToolInfo;<br>&nbsp;buffer&nbsp;:&nbsp;array[0..255]&nbsp;of&nbsp;char;<br><br><br>implementation<br><br>procedure&nbsp;CreateToolTips(hWnd:&nbsp;Cardinal);<br>begin<br>&nbsp;hToolTip&nbsp;:=&nbsp;CreateWindowEx(0,&nbsp;'Tooltips_Class32',&nbsp;nil,&nbsp;TTS_ALWAYSTIP&nbsp;or&nbsp;TTS_BALLOON,<br>&nbsp;&nbsp;&nbsp;Integer(CW_USEDEFAULT),&nbsp;Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),<br>&nbsp;&nbsp;&nbsp;Integer(CW_USEDEFAULT),&nbsp;hWnd,&nbsp;0,&nbsp;hInstance,&nbsp;nil);<br>&nbsp;if&nbsp;hToolTip&nbsp;&lt;&gt;&nbsp;0&nbsp;then<br>&nbsp;begin<br>&nbsp;&nbsp;&nbsp;SetWindowPos(hToolTip,&nbsp;HWND_TOPMOST,&nbsp;0,0,&nbsp;0,&nbsp;0,&nbsp;SWP_NOMOVE&nbsp;or<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SWP_NOSIZE&nbsp;or&nbsp;SWP_NOACTIVATE);<br>&nbsp;&nbsp;&nbsp;ti.cbSize&nbsp;:=&nbsp;SizeOf(TToolInfo);<br>&nbsp;&nbsp;&nbsp;ti.uFlags&nbsp;:=&nbsp;TTF_SUBCLASS&nbsp;or&nbsp;TTF_TRANSPARENT;<br>&nbsp;&nbsp;&nbsp;ti.hInst&nbsp;:=&nbsp;hInstance;<br>&nbsp;end;<br>end;<br><br>procedure&nbsp;AddToolTip(hwnd:&nbsp;dword;&nbsp;lpti:&nbsp;PToolInfo;&nbsp;IconType:&nbsp;Integer;&nbsp;Text,&nbsp;Title:&nbsp;PChar;<br>&nbsp;BackColor,TextColor:TColor);<br>var<br>&nbsp;Rect:&nbsp;TRect;<br>begin<br>&nbsp;if&nbsp;(hwnd&nbsp;&lt;&gt;&nbsp;0)&nbsp;AND&nbsp;(GetClientRect(hwnd,&nbsp;Rect))&nbsp;then<br>&nbsp;begin<br>&nbsp;&nbsp;&nbsp;lpti.hwnd&nbsp;:=&nbsp;hwnd;<br>&nbsp;&nbsp;&nbsp;lpti.Rect&nbsp;:=&nbsp;Rect;<br>&nbsp;&nbsp;&nbsp;lpti.lpszText&nbsp;:=&nbsp;Text;<br>&nbsp;&nbsp;&nbsp;SendMessage(hToolTip,&nbsp;TTM_ADDTOOL,&nbsp;0,&nbsp;Integer(lpti));<br>&nbsp;&nbsp;&nbsp;FillChar(buffer,&nbsp;sizeof(buffer),&nbsp;#0);<br>&nbsp;&nbsp;&nbsp;lstrcpy(buffer,&nbsp;Title);<br>&nbsp;&nbsp;&nbsp;if&nbsp;(IconType&nbsp;&gt;&nbsp;3)&nbsp;or&nbsp;(IconType&nbsp;&lt;&nbsp;0)&nbsp;then&nbsp;IconType&nbsp;:=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;if&nbsp;BackColor&lt;&gt;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;SendMessage(hToolTip,&nbsp;TTM_SETTIPBKCOLOR,&nbsp;BackColor,&nbsp;0);<br>&nbsp;&nbsp;&nbsp;if&nbsp;TextColor&lt;&gt;0&nbsp;then<br>&nbsp;&nbsp;&nbsp;SendMessage(hToolTip,&nbsp;TTM_SETTIPTEXTCOLOR,&nbsp;TextColor,&nbsp;0);<br>&nbsp;&nbsp;&nbsp;SendMessage(hToolTip,&nbsp;TTM_SETTITLE,&nbsp;IconType,&nbsp;Integer(@buffer));<br>&nbsp;end;<br>end;<br><br>end.
 
建议:你的弹出式窗体可以照着THintWindow写,这个类在Controls单元,触发事件可以拦截可以参考TApplication.ActivateHint的方法,或者直接拦截OnShowHint。
 
捕捉鼠标移入移出的消息
 
一只没有缺点的狼&nbsp;的方法我试下。<br>&nbsp;Mlssyy的方法会影响用户操作。<br><br>大家还有什么方法没?
 
你的问题也是我想提的,<br>不过是2年前的事了,<br>我的显示如下:<br>&nbsp;____________<br>|&nbsp;&nbsp;泡泡提示!&nbsp;|<br>|________&nbsp;&nbsp;&nbsp;&nbsp;|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//<br><br>下载我的程序,你可以点击登录一下看看结果.<br>http://202.130.158.81:1980/showhint.exe&nbsp;&nbsp;<br>转贴.<br>procedure&nbsp;TForm1.Button1Click(Sender:&nbsp;TObject);&nbsp;<br>var&nbsp;<br>rect&nbsp;:TRect;&nbsp;<br>p&nbsp;:Pointer;&nbsp;<br>MaxWidth,width,height:Integer;&nbsp;<br>point:TPoint;&nbsp;<br>x:THintWindow;&nbsp;<br>i:Integer;&nbsp;<br>begin&nbsp;<br>x&nbsp;:=&nbsp;THintWindow.Create(self);&nbsp;<br>p&nbsp;:=&nbsp;nil;&nbsp;<br>rect&nbsp;:=&nbsp;x.CalcHintRect(MaxWidth,Button2.hint,p);&nbsp;<br>width:=rect.Bottom-rect.Top;&nbsp;<br>height:=rect.Right-rect.Left;&nbsp;<br>point.x:=Button2.Left+Button2.Width;&nbsp;<br>point.y:=Button2.Top+Button2.Height;&nbsp;<br>Point:=ClientToScreen(Point);&nbsp;<br>rect.Left:=point.x;&nbsp;<br>rect.Top:=point.y;&nbsp;<br>rect.Right:=point.x+height;&nbsp;<br>rect.Bottom:=point.y+width;&nbsp;<br>x.Color&nbsp;:=&nbsp;clWhite;&nbsp;<br>x.ActivateHint(rect,Button2.Hint);&nbsp;<br>for&nbsp;i:=1&nbsp;to&nbsp;10&nbsp;do&nbsp;<br>begin&nbsp;<br>&nbsp;Application.ProcessMessages;&nbsp;<br>&nbsp;sleep(100);&nbsp;<br>end;&nbsp;<br>x.Free;&nbsp;<br>end;
 
楼上的,没密码啊.,我也想看看效果
 
jey的方法固然可以&nbsp;但是没有标题栏。<br>最好能在我的方法的基础上,自动显示气泡窗口的??
 
to&nbsp;jey&nbsp;:<br>&nbsp;&nbsp;&nbsp;刚刚看了你的程序``不错```可以交流下不?
 
To:dennyshao001<br>是的,没有密码,会提示一个泡泡框,现在讨论的是泡泡提示.<br>TO:gotiger<br>是的,没有标题栏,我一直苦恼做不了,除非<br>1,画图,但我数学不好.完成不了.<br>2,用位图做成泡泡提示的样子,再显示,但我美工没什么天分.<br>TO:eloveme<br>你要交流什么?请加QQ:344430663.
 
经过数十个小时苦试.终于有点眉目.<br>现在时间20070603午夜3:10<br>显示如下:<br>&nbsp;_________________<br>|&nbsp;{*}&nbsp;&nbsp;标题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<br>|&nbsp;泡泡提示!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<br>|________&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;____&nbsp;|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;/<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//<br><br>下载我的程序,你可以点击登录一下看看结果.<br>http://202.130.158.81:1980/showhint.exe
 
恩&nbsp;很好。能否共享??
 
我已经制作把DLL.调用以下DLL就可以提示了.<br>procedure&nbsp;ShowTip(WinControl:TWinControl;&nbsp;&nbsp;Title:&nbsp;PChar;Msg:&nbsp;PWideChar;&nbsp;IconType:Integer=1;&nbsp;TimeoutSecs:&nbsp;Integer=1000&nbsp;);stdcall;external&nbsp;'ShowHint.dll';<br>//解释:&nbsp;ShowTip&nbsp;控件,标题,内容,图标(提示,警告,错误),显示时间.<br>例子:&nbsp;ShowTip&nbsp;(Edit1,'提示','请输入时间有误!',2,2000);<br>明天或后天测试完就提供下载.
 
好啊,没习一下
 
支持..支持...可以继续完善...
 
测试到这里看看<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3731993
 
貌似错了,着是本贴地址。
 
?頂一下。關注中。
 
五年前我就做过了,不过只能处理有句柄的控件
 
多人接受答案了。
 
后退
顶部