如何隐藏和显示程序在任务栏上的图标??(100分)

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

helloymz

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个程序,要求实现象flashget类似的窗体隐藏功能<br>要求在程序启动的时候先隐藏掉任务栏上的程序按钮<br>last:=getwindowlong(Application.Handle,GWL_EXSTYLE);<br>SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br>在显示窗体的时候恢复:<br>SetWindowLong(Application.Handle,GWL_EXSTYLE,last);<br>在关闭窗体的时候重新隐藏<br>SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br>可是当我重新隐藏的时候,任务栏上面还是留有我的程序的图标按钮,为什么?我应该<br>怎么写?<br><br>
 
showWindow(application.handle,SW_SHOW);<br>showWindow(application.handle,SW_HIDE);
 
重新隐藏的时候这样写试试<br>ShowWindow(Application.handle,SW_HIDE)
 
楼上的,我试过了,用showwindow函数隐藏不了任务栏上的程序图标按钮啊..
 
private<br>&nbsp; &nbsp; procedure WMSYSCOMMAND(var msg: TWMSYSCOMMAND); message WM_SYSCOMMAND;<br>&nbsp; &nbsp; procedure AddTray;<br>&nbsp; &nbsp; procedure RemoveTray;<br>&nbsp; public<br>&nbsp; end;<br><br>var<br>&nbsp; Form1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>//uses ShellApi<br><br>//增加小图标<br>procedure TForm1.AddTray;<br>var<br>&nbsp; Nid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TNotifyIconData;<br>begin<br>&nbsp; FillChar(Nid, SizeOf(TNotifyIconData), 0);<br>&nbsp; Nid.cbSize := SizeOf(TNotifyIconData);<br>&nbsp; Nid.Wnd := Handle; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//窗口句柄<br>&nbsp; Nid.uID := 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //内部标识,可任意指定<br>&nbsp; Nid.hIcon := Application.Icon.Handle; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //要加入的图标句柄<br>&nbsp; Nid.szTip := '图标示例程序'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//提示字符串<br>&nbsp; Nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; &nbsp; &nbsp; &nbsp; &nbsp; //指明哪些字段有效<br>&nbsp; if not Shell_NotifyIcon(NIM_ADD, @nid) then<br>&nbsp; &nbsp; Application.Terminate;<br>end;<br><br>//去除小图标<br>procedure TForm1.RemoveTray;<br>var<br>&nbsp; Nid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : TNotifyIconData;<br>begin<br>&nbsp; FillChar(Nid, SizeOf(TNotifyIconData), 0);<br>&nbsp; Nid.cbSize := SizeOf(TNotifyIconData);<br>&nbsp; Nid.uID := 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //内部标识,与加入小图标时的数一致<br>&nbsp; Nid.Wnd := Handle; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//窗口句柄<br>&nbsp; Shell_NotifyIcon(NIM_DELETE, @nid); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //去掉小图标<br>end;<br><br>procedure TForm1.WMSYSCOMMAND(var msg: TWMSYSCOMMAND);<br>begin<br>&nbsp; if msg.CmdType = SC_MINIMIZE then<br>&nbsp; &nbsp; AddTray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //增加图标<br>&nbsp; else<br>&nbsp; &nbsp; RemoveTray;<br>&nbsp; inherited;<br>end;<br>
 
用showwindow一定可以的,没错,你好好试试,我在我的程序中就这样用的
 
program Project1;<br><br>uses<br>Forms,<br>Unit1 in 'Unit1.pas' {Form1},<br>Windows;<br><br>{$R *.RES}<br><br>var<br>ExtendedStyle : Integer;<br><br>begin<br>Application.Initialize;<br><br>//============================================================== <br>ExtendedStyle := GetWindowLong (Application.Handle, GWL_EXSTYLE);<br><br>SetWindowLong(Application.Handle, GWL_EXSTYLE, ExtendedStyle OR WS_EX_TOOLWINDOW<br>AND NOT WS_EX_APPWINDOW);<br>//=============================================================== <br>Application.CreateForm(TForm1, Form1);<br>Application.Run;<br>end. <br>///////////////////////////////////////////////////////////////<br>  
 
to zxbyh:<br>那我恢复的时候要怎么写?请帮个忙
 
我想一想!!
 
哥们我弄明白啦..<br>具体如下:<br>procedure form1.formcreate(sender:tobject);<br>begin<br>wstyle:=getwindowlong(Application.Handle,GWL_EXSTYLE);<br>SetWindowLong(application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br>end;<br><br>恢复显示按钮:<br>setwindowlong(application.Handle,GWL_EXSTYLE,wstyle); &nbsp; &nbsp;<br>showWindow(application.handle,SW_show);<br><br>再次隐藏:<br>showWindow(application.handle,SW_HIDE);<br>SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br><br>还是谢谢各位.
 
多人接受答案了。
 
后退
顶部