枫
枫
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个托盘程序,现在可以把图标放入托盘里,图标也可以响应鼠标点击了<br>可是就差最后一关:把程序的窗口在任务栏上去掉不行了,我在程序里的加入<br>applictionevers组件,在最小化事件里写入:ShowWindow(form1.Handle,SW_HIDE);<br>然后在图标的响应程序里加入一行:ShowWindow(form1.Handle,SW_SHOW);<br>,当我点击程序窗口的最小化按键的时候,窗口只是和平时一样最小化在任务栏上,并没有从<br>任务上消息,我点击托盘里的图标,窗口给还原到原来大小,但我再点最小化按键的时候,发现<br>这个按键不起作用了,怎么按窗口也不最小化了,请教各位,这是怎么回事??<br><br>源代码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> Menus,shellapi, AppEvnts;<br>const<br> ICON_ID=1; //ICON的ID标志<br> MI_ICONEVENT=WM_USER+1; //自定义ICON事件消息<br><br>type<br> TForm1 = class(TForm)<br> PopupMenu1: TPopupMenu;<br> ok1: TMenuItem;<br> ApplicationEvents1: TApplicationEvents;<br> procedure FormShow(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure IconOnClick(var message:TMessage); message MI_ICONEVENT;<br> procedure ok1Click(Sender: TObject);<br> procedure ApplicationEvents1Minimize(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormShow(Sender: TObject);<br>var<br> NormalIcon:TIcon;<br> IconData:TNotifyIconData;<br>begin<br> NormalIcon:=TIcon.Create;<br> NormalIcon.LoadFromFile('d:/08.ico');<br> IconData.cbSize:=SizeOf(IconData);<br> IconData.Wnd:=Handle;<br> IconData.uID:=ICON_ID;<br> IconData.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;<br> IconData.uCallBackMessage:=MI_ICONEVENT;<br> IconData.hIcon:=NormalIcon.Handle;<br><br> IconData.szTip:='hello!!'; //鼠标悬在状态指示栏对应的图标上时的提示信息<br><br> Shell_NotifyIcon(NIM_ADD,@IconData);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br> IconData:TNotifyIconData;<br>begin<br> IconData.cbSize:=SizeOf(IconData);<br> IconData.Wnd:=Handle;<br> IconData.uID:=ICON_ID;<br> Shell_NotifyIcon(NIM_DELETE,@IconData);<br>end;<br><br>procedure TForm1.IconOnClick(var message: TMessage);<br>var<br> p:TPoint;<br>begin<br> if(message.lParam=WM_LBUTTONDOWN) then<br> begin<br> GetCursorPos(p);<br> PopupMenu1.Popup(p.x,p.y);<br> end;<br>end;<br><br>procedure TForm1.ok1Click(Sender: TObject);<br>begin<br>ShowWindow(form1.Handle,SW_SHOW);<br>end;<br><br>procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);<br>begin<br>ShowWindow(form1.Handle,SW_HIDE);<br>end;<br><br>end.<br><br><br>