请教,托盘程序的问题(100分)

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

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>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; Menus,shellapi, AppEvnts;<br>const<br>&nbsp; ICON_ID=1; &nbsp;//ICON的ID标志<br>&nbsp; MI_ICONEVENT=WM_USER+1; //自定义ICON事件消息<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; PopupMenu1: TPopupMenu;<br>&nbsp; &nbsp; ok1: TMenuItem;<br>&nbsp; &nbsp; ApplicationEvents1: TApplicationEvents;<br>&nbsp; &nbsp; procedure FormShow(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure IconOnClick(var message:TMessage); message MI_ICONEVENT;<br>&nbsp; &nbsp; procedure ok1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure ApplicationEvents1Minimize(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormShow(Sender: TObject);<br>var<br>&nbsp; NormalIcon:TIcon;<br>&nbsp; IconData:TNotifyIconData;<br>begin<br>&nbsp; NormalIcon:=TIcon.Create;<br>&nbsp; NormalIcon.LoadFromFile('d:/08.ico');<br>&nbsp; IconData.cbSize:=SizeOf(IconData);<br>&nbsp; IconData.Wnd:=Handle;<br>&nbsp; IconData.uID:=ICON_ID;<br>&nbsp; IconData.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;<br>&nbsp; IconData.uCallBackMessage:=MI_ICONEVENT;<br>&nbsp; IconData.hIcon:=NormalIcon.Handle;<br><br>&nbsp; IconData.szTip:='hello!!'; &nbsp;//鼠标悬在状态指示栏对应的图标上时的提示信息<br><br>&nbsp; Shell_NotifyIcon(NIM_ADD,@IconData);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>var<br>&nbsp; &nbsp; IconData:TNotifyIconData;<br>begin<br>&nbsp; &nbsp; IconData.cbSize:=SizeOf(IconData);<br>&nbsp; &nbsp; IconData.Wnd:=Handle;<br>&nbsp; &nbsp; IconData.uID:=ICON_ID;<br>&nbsp; &nbsp; Shell_NotifyIcon(NIM_DELETE,@IconData);<br>end;<br><br>procedure TForm1.IconOnClick(var message: TMessage);<br>var<br>&nbsp; p:TPoint;<br>begin<br>&nbsp; if(message.lParam=WM_LBUTTONDOWN) then<br>&nbsp; begin<br>&nbsp; &nbsp; GetCursorPos(p);<br>&nbsp; &nbsp; PopupMenu1.Popup(p.x,p.y);<br>&nbsp; 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>
 
你可以把代码换成 &nbsp;<br>procedure TForm1.ok1Click(Sender: TObject);<br>begin<br>&nbsp; ShowWindow(Application.Handle,SW_SHOW);<br>&nbsp; SetFocus;<br>&nbsp; Application.BringToFront;<br>end;<br>和<br>procedure TForm1.ApplicationEvents1Minimize(Sender: TObject);<br>begin<br>&nbsp; ShowWindow(Application.Handle,SW_HIDE);<br>end;
 
试试把程序在任务栏上的显示直接去掉,不知可不可以?
 
to window<br>改了程序之后,任务栏上的窗口不见,<br>但我还原来的窗口的时候,那窗口只在任务栏上出现,并没有在桌面上显示出来<br>另:<br>ShowWindow(Application.Handle,SW_SHOW);和<br>ShowWindow(form1.Handle,SW_SHOW);<br>有什么分别??我看说明是控制一个窗口,你怎么会一个应用程序放在里面了呢??是否可解释一下,谢谢!!<br><br>
 
OK,,谢谢各位了,我的问题解决了,把SW_SHOW改为SW_RESTORE就行了<br>但我有事不明,为什么用SW_RESTORE而不是用SW_SHOW呢??
 
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.<br>SW_SHOW Activates the window and displays it in its current size and position. <br>详细请参考WINDWS SDK编程(MSDN 或delphi自带的帮助Win32 SDK Reference) &nbsp;
 
谢谢各位了,
 
后退
顶部