关于程消隐程序的标题(100分)

章慧

Unregistered / Unconfirmed
GUEST, unregistred user!
求教各位大侠。
1) 如何将我的程序在TaskBar中的显示去掉,
2) 如何在右边系统栏中显示出来我的程序的图标。
3) 怎样能使用户在按下Ctrl+Alt+Del时见不到我的程序在运行的消息呢。
4) 程序如何把自己删掉呢( 我的一个小程序希望后台运行时能接受远地
指令而自行卸载 )
 
1.showwindows(application.handle,sw_hide);
或SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
或application.showmainform:=false;
2.tray icon

3.var temp: Integer;
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 1, @temp, 0);
SystemParametersInfo(SPI_SCREENSAVERRUNNING, 0, @temp, 0);
4.不可能

2.
unit Unit1;
interface
{ 记住在uses部分中包括 ShellAPI}
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs,
ShellAPI, StdCtrls;
{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
const MY_MESSAGE = WM_USER + 100;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormPaint(Sender: TObject);
private
procedure OnIconNotify(var Message: TMessage);
message MY_MESSAGE;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
{当小图标捕捉到鼠标事件时进入此过程}
procedure TForm1.OnIconNotify(var Message: TMessage);
const
Busy: Boolean = false;
begin

if not Busy then
begin

Busy := true;
if Message.LParam=WM_LBUTTONDOWN then

if Application.MessageBox('Are you sure',
'Exit', MB_YESNO)=IDYES then
Close;
Busy := false;
end;

end;

{当主Form建立时通知Windows加入小图标}
procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;
begin

nid.cbSize := sizeof(nid);
// nid变量的字节数
nid.Wnd := Handle;
// 主窗口句柄
nid.uID := -1;
// 内部标识,可设为任意数
nid.hIcon := Application.Icon.Handle;
// 要加入的图标句柄,可任意指定
nid.szTip := 'This is a test application';
// 提示字符串
nid.uCallbackMessage := MY_MESSAGE;
// 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
// 指明哪些字段有效
if not Shell_NotifyIcon(NIM_ADD, @nid) then
begin

ShowMessage('Failed!');
Application.Terminate;
end;

{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
end;

{程序被关闭时通知Windows去掉小图标}
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
var
nid: TNotifyIconData;
begin

nid.cbSize := sizeof(nid);
// nid变量的字节数
nid.uID := -1;
//内部标识,与加入小图标时的数一致
nid.Wnd := Handle;
//主窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid);
//去掉小图标
end;

{主窗口初始化完毕并显示时将激活Paint重画事件,此时将主窗口隐藏}
procedure TForm1.FormPaint(Sender: TObject);
begin

Hide;
end;

end.

 
  上例中将程序的图标放在任务条右下角,然后隐藏自身,当用户移动鼠标至该图
标上时会看到提示字符串,如果单击该图标会出现一个对话框,选择Yes退出程序并清
除小图标。
 
1, 是 MM 吗?
2, 可惜呀,音同名不同, 知道 huizhang 吗? 张辉,
3, 1, 不明确,
4, 很多问题都有答案,
if Answer of Question 1 = True then
begin
1): Make it Clear, please
2): look at 问题检索 at left bottom, then
click the edit control
and type Shell_Notify, and type enter WOO!, you can find answers
3): same as 2) type Ctrl+Alt+Del or 隐藏
4): cAkk had write a small bat, something like this:
the name is deleteMyself.bat. The content is:

Del MyProgramName
and you can winexec('command /c deleteMyself.bat', SW_HIDE);
in your program when the condition is true
end
else
ShowMessage('自己查去!!');
 
3. 有一个Windows 的API
RegistServiceProcess
好象可以把程序变为服务进程,Ctrl-alt-Del 就看不到了。
2. 使用Shell API,查一下 NotifyIcon 挺简单的。
1. SetWindowLong(hWnd,GWL_EXSTYLE,WS_EX_TOOLWINDOW)
hehe,试试看
 
程序删除自己
procedure TForm1.closeme;
var f:textfile;
begin

assignfile(f,'./delme.bat');
rewrite(f);
writeln(f,'@echo off');
writeln(f,':loop');
writeln(f,'del "'+application.ExeName+'"');
writeln(f,'if exist ./file.exe goto loop');
writeln(f,'del ./delme.bat');
closefile(f);
winexec('./delme.bat', SW_HIDE);
close;
end;


 
自删
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
VAR OUTPUT:TEXTFILE;
begin
AssignFile(Output,PATH+'/TMP.BAT');
Rewrite(Output);
Writeln(Output, 'del '+path+'/PSELF_DEL.exe');//pself_del.exe为本程序的名字。
Writeln(Output, 'del %0');
CloseFile(Output);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
GETDIR(0,PATH);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
winexec('TMP.BAT', SW_HIDE );
end;
定义一个字符型全局变量:PATH。
 
多人接受答案了。
 
顶部