delphi写的程序不知道用什么了,开着这个程序关不了计算机??就这些分了,麻烦大虾给看一眼
我的delphi7写的一个程序a,不知道怎么回事,开着这个程序a的时候,点关机,qq、浏览器之类的都关了,但是就这个a没关。且电脑也关闭不了。如果不打开a,或者退出a,,...
我的delphi7 写的一个程序a,不知道怎么回事,开着这个程序a的时候,点关机,qq、浏览器之类的都关了,但是就这个 a没关。且电脑也关闭不了。如果不打开a,或者退出a,,电脑就可以关闭了。
代码如下:
procedure TMainForm.FormActivate(Sender: TObject);
begin
RzTrayIcon1.MinimizeApp;
end;
procedure TMainForm.StopUploadThread;
begin
if Assigned(upt) then
upt.Terminate;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
StopUploadThread;
//HotKeyManager1.RemoveHotKey(FHotKey);
UpLoadData.Free;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Application.Minimize;
CanClose := FCanClose;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
HotKeyId:=GlobalAddAtom('MyHotKey') - $C000;
RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F8);
InitUI;
FCanClose := False;
SetAutorun;
UpLoadData := TUpLoadData.Create(nil);
BeginUploadThread;
end;
procedure TMainForm.SetAutorun;
var
r: TRegistry;
FileName: string;
begin
FileName := ChangeFileExt(ExtractFileName(ParamStr(0)), '');
r := TRegistry.Create;
try
r.RootKey := HKEY_LOCAL_MACHINE;
if r.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True) then
begin
if r.ValueExists(FileName) then
r.DeleteValue(FileName);
if Config.AutoRun then
r.WriteString(FileName, '"' + ParamStr(0) + '"');
r.CloseKey;
end;
finally
r.Free;
end;
end; 展开
代码如下:
procedure TMainForm.FormActivate(Sender: TObject);
begin
RzTrayIcon1.MinimizeApp;
end;
procedure TMainForm.StopUploadThread;
begin
if Assigned(upt) then
upt.Terminate;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
StopUploadThread;
//HotKeyManager1.RemoveHotKey(FHotKey);
UpLoadData.Free;
end;
procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Application.Minimize;
CanClose := FCanClose;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
HotKeyId:=GlobalAddAtom('MyHotKey') - $C000;
RegisterHotKey(Handle, hotkeyid, MOD_ALT, VK_F8);
InitUI;
FCanClose := False;
SetAutorun;
UpLoadData := TUpLoadData.Create(nil);
BeginUploadThread;
end;
procedure TMainForm.SetAutorun;
var
r: TRegistry;
FileName: string;
begin
FileName := ChangeFileExt(ExtractFileName(ParamStr(0)), '');
r := TRegistry.Create;
try
r.RootKey := HKEY_LOCAL_MACHINE;
if r.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True) then
begin
if r.ValueExists(FileName) then
r.DeleteValue(FileName);
if Config.AutoRun then
r.WriteString(FileName, '"' + ParamStr(0) + '"');
r.CloseKey;
end;
finally
r.Free;
end;
end; 展开
2个回答
展开全部
你在窗体create的时候不是已经将FCanClose := False;
这样当然关不了机,要么就把FormCloseQuery中的代码去掉
如果你是想让程序点X的时候不关闭,但又想不影响系统的关机,可以这样
声明中加
procedure EndMsg(var nMsg: TWMQueryEndSession); Message WM_QUERYENDSESSION;
然后
procedure TMainForm.EndMsg(var nMsg: TWMQueryEndSession);
begin
//0 可以取消关机操作
FCanClose := True;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询