关于在delphi中怎么样实现在任务栏和状态栏中隐藏应用程序(100分)

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

yuanhong

Unregistered / Unconfirmed
GUEST, unregistred user!
关于在delphi中怎么样实现在任务栏和状态栏中隐藏应用程序
 
showwindow(application.handle,SW_HIDE);<br>showwindow(application.handle,SW_SHOW);
 
我试了一下你的方法在win2000下不行呀
 
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><br>Application.CreateForm(TForm1, Form1);<br>Application.Run;<br>end. <br>///////////////////////////////////////////////////////////////<br>  一般Windows 95运行程序时都会在任务栏上出现按钮,如果你的程序是一个监视程序,那么出现按钮就不是明智之举了。要实现该功能就要在OnCreate事件里利用到API函数SetWindowLong<br>procedure TForm1.FormCreate(sender:TObject);<br>begin<br>SetWindowLong(Application,Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);<br>end;<br>/////////////////////////////////////////////////////////<br>ShowWindow(Application.Handle, SW_HIDE); <br>SetWindowLong(Application.Handle, GWL_EXSTYLE, <br>&nbsp; GetWindowLong(Application.Handle, GWL_EXSTYLE) <br>&nbsp; &nbsp; or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); &nbsp;<br>
 
W2K下呢?<br>GZ
 
具体如下:<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>
 
请问wstyle是什么变量
 
unit Unit1; <br>interface <br>uses <br>Windows, Messages, Forms, Dialogs, Classes, Controls, StdCtrls; <br>type <br>TForm1 = class(TForm) <br>Button1: TButton; <br>Button2: TButton; <br>procedure FormCreate(Sender: TObject); <br>procedure Button1Click(Sender: TObject); <br>procedure Button2Click(Sender: TObject); <br>procedure FormClose(Sender: TObject; var Action: TCloseAction); <br>private <br>{热键标识ID} <br>id: Integer; <br>procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY; <br>{ Privat-Declarations} <br>public <br>{ Public-Declarations} <br>end; <br>var <br>Form1 : TForm1; <br>implementation <br>const RSP_SIMPLE_SERVICE=1; <br>function RegisterServiceProcess (dwProcessID, dwType: DWord) : DWord; stdcall; external ’KERNEL32.DLL’; <br>{$R *.DFM} <br><br>{捕获热键消息} <br>procedure TForm1.WMHotKey (var Msg : TWMHotKey); <br>begin <br>if msg.HotKey = id then <br>ShowMessage(’Ctrl+Alt+R键被按下!’); <br>form1.Visible :=true; <br>end; <br><br>procedure TForm1.FormCreate(Sender: TObject); <br>Const <br>{ALT、CTRL和R键的虚拟键值} <br>MOD_ALT = 1; <br>MOD_CONTROL = 2; <br>VK_R = 82; <br>begin <br>{首先判断程序是否已经运行} <br>if GlobalFindAtom(’MyHotkey’) = 0 then <br>begin <br>{注册全局热键Ctrl + Alt + R} <br>id:=GlobalAddAtom(’MyHotkey’); <br>RegisterHotKey(handle,id,MOD_CONTROL+MOD_Alt,VK_R); <br>end <br>else <br>halt; <br>end; <br><br>{把当前进程变为一个系统服务,从而在任务列表中把程序隐藏起来} <br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br>RegisterServiceProcess(GetCurrentProcessID,RSP_SIMPLE_SERVICE); <br>form1.Hide; <br>end; <br><br>procedure TForm1.Button2Click(Sender: TObject); <br>begin <br>close; <br>end; <br>{退出时释放全局热键} <br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); <br>begin <br>UnRegisterHotKey(handle,id); <br>GlobalDeleteAtom(id); <br>end; <br>end. <br>我上面有一段代码,但是在运行中报无法与KERNEL32.DLL文件建立连接<br>
 
接受答案了.
 
后退
顶部