感谢来如风热心指点!关于托盘显示问题,谁能点化我?在线等待! (220分)

  • 主题发起人 主题发起人 qingrj
  • 开始时间 开始时间
Q

qingrj

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个托盘小程序,用起来效果不错,现在我想让它Hint动态显示所读注册表的键值.<br>我在大富翁论坛研究了一个周的帖子,总是不得其法,先将原码贴上来,请高人点化.<br>在线等待,只UP无分.<br><br>unit acbb;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls, StdCtrls,shellapi, Menus, Registry;<br><br>const IDI_TRAYICON=WM_USER+10;<br>&nbsp; &nbsp; &nbsp; TRAY_CALLBACK=WM_USER+40;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; label1: TPanel;<br>&nbsp; &nbsp; PopupMenu1: TPopupMenu;<br><br>&nbsp; &nbsp; N1: TMenuItem;<br>&nbsp; &nbsp; A1: TMenuItem;<br>&nbsp; &nbsp; N2: TMenuItem;<br>&nbsp; &nbsp; X1: TMenuItem;<br>&nbsp; &nbsp; H1: TMenuItem;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure A1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure X1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure H1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure N1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormPaint(Sender: TObject);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>var<br>&nbsp; MyRegistry:TRegistry;<br>&nbsp; Form1: TForm1;<br>&nbsp; aa:TNotifyIcondata;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var tubiao:THandle;<br>begin<br>&nbsp; tubiao:=application.Icon.handle;<br>&nbsp; aa.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; aa.uID:=uint(IDI_TRAYICON);<br>&nbsp; aa.cbSize:=sizeof(tnotifyicondata);<br>&nbsp; aa.uCallbackMessage:=tray_callback;<br>&nbsp; aa.Wnd:=self.handle;<br>&nbsp; aa.hIcon:=tubiao;<br>&nbsp; //aa.sztip:='请右键选择';<br>&nbsp; shell_notifyicon(nim_add,@aa);<br>&nbsp; showwindow(application.handle,sw_hide);<br>&nbsp; form1.caption:='电脑开机时间为:'+timetostr(now);<br>end;<br>procedure TForm1.A1Click(Sender: TObject);<br>var msg:string;<br>begin<br>&nbsp; msg:='xxxxxxxxxxxxx'; <br>&nbsp; application.MessageBox(pchar(msg),'关于...',mb_ok+mb_iconinformation);<br>end;<br><br><br>procedure TForm1.X1Click(Sender: TObject);<br>begin<br>&nbsp; form1.close;<br>&nbsp; form1.Free;<br>end;<br><br>procedure TForm1.H1Click(Sender: TObject);<br>begin<br>&nbsp;myregistry:=Tregistry.Create;<br>&nbsp;MyRegistry.RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp;try<br>&nbsp;if MyRegistry.OpenKey('/SOFTWARE/d-ok',True)<br>&nbsp; then<br>&nbsp; begin<br>&nbsp; &nbsp;MyRegistry.writebool('xxhg',true);<br>&nbsp; &nbsp;MyRegistry.writestring('jls[0]',datetimetostr(now));<br>&nbsp; &nbsp;end;<br>&nbsp; finally<br>&nbsp; MyRegistry.Free;<br>&nbsp;end;<br>&nbsp;winexec('C:/Program Files/b-d/eye.exe',SW_RESTORE) ;<br>end;<br><br>procedure TForm1.N1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;winexec('C:/Program Files/b-d/b-d.exe',SW_RESTORE) ;<br>end;<br><br>procedure TForm1.FormPaint(Sender: TObject);<br>begin<br>&nbsp; Form1.Hide;<br>end;<br>{procedure TForm1.Timer1Timer(Sender: TObject);<br>var tipinfo,info:string;<br>begin<br>myregistry:=Tregistry.Create;<br>&nbsp;MyRegistry.RootKey:=HKEY_LOCAL_MACHINE;<br>&nbsp;try<br>&nbsp;if MyRegistry.OpenKey('/SOFTWARE/d-ok',True)<br>&nbsp; then tnnd:= '现在数据是:'+inttostr(MyRegistry.Readinteger('tnnd'));<br>&nbsp; finally<br>&nbsp; MyRegistry.Free;<br>&nbsp;end;<br><br>&nbsp;{这里如何显示tnnd值,请高人点化}<br><br>end;}<br><br>end.
 
unit main;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, jpeg, ExtCtrls,StdCtrls,Menus,ShellAPI;<br><br>const<br>&nbsp; &nbsp;CM_RESTORE = WM_USER + $1000;<br>&nbsp; &nbsp;WZGL_APP_NAME = 'MFun_System';<br><br>const<br>&nbsp; &nbsp;WM_WZGLNOTIFY = WM_USER + 100; &nbsp;//自定义消息<br>&nbsp; &nbsp;strNotifyTip = '常用函数'; //状态区的提示信息<br>//这儿改成从注册表读取就是了<br><br>&nbsp; &nbsp;ID_MAIN = 100; // 定义图标的ID<br>&nbsp; &nbsp; &nbsp;<br>type<br>&nbsp; Tlog = class(TForm)<br>&nbsp; &nbsp; pop: TPopupMenu;<br>&nbsp; &nbsp; N1: TMenuItem;<br>&nbsp; &nbsp; N2: TMenuItem;<br>&nbsp; &nbsp; N3: TMenuItem;<br>&nbsp; &nbsp; Image1: TImage;<br>&nbsp; &nbsp; procedure N1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure N2Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Image1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormDestroy(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; &nbsp; &nbsp; function AddIcon(hwnd: HWND): Boolean; //在状态区添加图标<br>&nbsp; &nbsp; &nbsp; function RemoveIcon(hwnd: HWND): Boolean; //从状态区移去图标<br>&nbsp; &nbsp; &nbsp; procedure Notify(var Msg: TMessage); message WM_WZGLNOTIFY; //自定义消息处理函数<br>&nbsp; &nbsp; &nbsp; procedure minimize(sender: Tobject); //定义最小化过程,赋给Application.OnMinimiz;<br>&nbsp; &nbsp; &nbsp; procedure CreateParams(var Params: TCreateParams); override;<br>&nbsp; &nbsp; &nbsp; procedure RestoreRequest(var message: TMessage); message CM_RESTORE;<br>&nbsp; end;<br><br>var<br>&nbsp; log: Tlog;<br>&nbsp; &nbsp;nid: NOTIFYICONDATA;<br>&nbsp; &nbsp;i: integer;<br><br>implementation<br><br>{$R *.dfm}<br>procedure miniapp(aform:Tform);<br>begin<br>&nbsp; &nbsp; &nbsp;showwindow(application.handle,sw_minimize);<br>end;<br><br>procedure Tlog.CreateParams(var Params: TCreateParams);<br>begin<br>&nbsp; &nbsp;inherited CreateParams(Params);<br>&nbsp; &nbsp;Params.WinClassName := WZGL_APP_NAME;<br>end;<br><br>{处理“恢复”消息}<br><br>procedure Tlog.RestoreRequest(var message: TMessage);<br>begin<br>&nbsp; &nbsp;if IsIconic(Application.Handle) = True then &nbsp;//窗体是否最小化<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; Application.Restore; &nbsp;//恢复窗体<br>&nbsp; &nbsp; &nbsp; Application.BringToFront;<br>&nbsp; &nbsp;end<br>&nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; Application.BringToFront; //提到前面显示<br>&nbsp; &nbsp;end;<br><br><br>//在状态区添加图标<br>function Tlog.AddIcon(hwnd: HWND): Boolean;<br>begin<br>&nbsp; &nbsp;nid.cbSize := sizeof(NOTIFYICONDATA);<br>&nbsp; &nbsp;nid.Wnd := hwnd;<br>&nbsp; &nbsp;nid.uID := ID_MAIN;<br>&nbsp; &nbsp;nid.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;<br>&nbsp; &nbsp;nid.uCallbackMessage := WM_WZGLNOTIFY;<br>&nbsp; &nbsp;nid.hIcon := LoadIcon(hInstance, 'MAINICON');<br>&nbsp; &nbsp;strCopy(nid.szTip, strNotifyTip);<br>&nbsp; &nbsp;AddIcon := Shell_NotifyIcon(NIM_ADD, @nid);<br>end;<br><br>//从状态区移去图标<br>function Tlog.RemoveIcon(hwnd: HWND): Boolean;<br>var<br>&nbsp; &nbsp;nid: NOTIFYICONDATA;<br>begin<br>&nbsp; &nbsp;nid.cbSize := sizeof(NOTIFYICONDATA);<br>&nbsp; &nbsp;nid.Wnd := hwnd;<br>&nbsp; &nbsp;nid.uID := ID_MAIN;<br>&nbsp; &nbsp;nid.uFlags := 0;<br>&nbsp; &nbsp;RemoveIcon := Shell_NotifyIcon(NIM_DELETE, @nid);<br>end;<br><br>//自定义消息处理函数<br>procedure Tlog.Notify(var Msg: TMessage);<br>var<br>&nbsp; &nbsp;Pt: TPoint;<br>begin<br>&nbsp; &nbsp;case msg.LParam of<br>&nbsp; &nbsp; &nbsp; WM_RBUTTONDOWN: &nbsp; &nbsp;//当点击右键时,弹出快捷菜单<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetForeGroundWindow(nid.wnd);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(Pt);<br>// &nbsp; &nbsp; &nbsp; &nbsp; Popupmenu.Popup(pt.x, pt.y);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Pop.Popup(pt.x, pt.y);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; WM_LBUTTONDOWN: &nbsp; &nbsp;//当点击左键时,显示窗体<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RestoreRequest(msg);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;end;<br>end;<br><br>//定义最小化过程,赋给Application.OnMinimize;<br>procedure Tlog.minimize(sender: Tobject);<br>begin<br>&nbsp; &nbsp;AddIcon(handle);<br>&nbsp; &nbsp;ShowWindow(Application.handle, sw_hide)<br>end;<br><br>procedure Tlog.N1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;miniapp(self);<br>end;<br><br>procedure Tlog.N2Click(Sender: TObject);<br>begin<br>close;<br>end;<br><br>procedure Tlog.Image1Click(Sender: TObject);<br>begin<br>minimize(self);<br>end;<br><br>procedure Tlog.FormDestroy(Sender: TObject);<br>begin<br>RemoveIcon(handle);<br>end;<br><br>procedure Tlog.FormCreate(Sender: TObject);<br>begin<br>&nbsp; &nbsp;Application.OnMinimize := minimize;<br>end;<br><br>end.
 
您说的:这儿改成从注册表读取就是了,但我不明白,那不是主程序代码写入地方,如何改?<br>请再讲细些,我很菜,分不够可以加!!
 
在{这里如何显示tnnd值,请高人点化}处加上下面的<br>aa.sztip := tnnd;<br>Shell_NotifyIcon(NIM_MODIFY, @aa);
 
编译出现错误.提示:<br>&nbsp; [Error] acbb.pas(163): Incompatible types: 'Array' and 'String'<br><br>我对Array不懂,谁能指点一下!<br>
 
array 是一个数组啊<br>代码太长了,不知道出错的是那一行
 
就是aa.sztip := tnnd;这一行,估计是变量类型不兼容问题;<br>是不是sztip 必须要求数组变量,该如何改!!
 
你的tnnd是什么类型的啊?没有看到什么地方有定义嘛<br>你自己可以转换一下<br>sztip:=‘sdfjl'可以的,<br>strCopy(nid.szTip, strNotifyTip);//也行,copy 楼上的一位兄弟的<br>
 
tnnd在前面定义是sting,不能将其用单括弧括起来,要显示它的动态值!<br>第二种办法我试试!谢谢!!!
 
&nbsp; tnnd:= MyRegistry.Readinteger('tnnd');<br>////这读出来的是整型的值吧<br>
 
是整型,这一句我为了显示已变为:<br>&nbsp; tnnd:= '现在数据是:'+inttostr(MyRegistry.Readinteger('tnnd'));<br>
 
那你tnnd定义不应该是整形啊,<br>是整型,这一句我为了显示已变为:<br>&nbsp; tnnd:= '现在数据是:'+inttostr(MyRegistry.Readinteger('tnnd'));<br>这样tnnd还是string型的,这时copy应该可以了吧<br>
 
是不是这样转换:<br>sztip:=strCopy(nid.szTip, strNotifyTip);
 
不是的;<br>tipinfo:= '现在数据是:'+inttostr(MyRegistry.Readinteger('tnnd'));<br>直接<br>strcopy(nid.sztip,pchar(tipinfo));//这 是一个字符串拷贝函数,<br>就可以了
 
谢谢你,不过这些已超过我的知识理解范围,<br>tipinfo该如何定义,不然编译又出错?<br>能不能请你把:<br>&nbsp; &nbsp;procedure TForm1.Timer1Timer(Sender: TObject);<br>这一段帮我改一下,编译通过后我再好好琢磨!
 
tipinfo:string;<br>暂时没有时间,我要下了,晚上看看吧
 
晚上等你,有qq吗?
 
153920396,你的我没记住,再说一遍好吗
 
_NOTIFYICONDATAA = record<br>&nbsp; &nbsp; cbSize: DWORD;<br>&nbsp; &nbsp; Wnd: HWND;<br>&nbsp; &nbsp; uID: UINT;<br>&nbsp; &nbsp; uFlags: UINT;<br>&nbsp; &nbsp; uCallbackMessage: UINT;<br>&nbsp; &nbsp; hIcon: HICON;<br>&nbsp; &nbsp; [red]szTip: array [0..63] of AnsiChar;[/red]<br>&nbsp; end;<br><br>szTip是个数组<br>
 
zjan521:<br>&nbsp; &nbsp; 这一句是定义结构么?放在什么地方合适?
 
后退
顶部