Arsip: Melarang "Tutup" Aplikasi, kecuali shutdown/restart


by delphy in Articles more 15 years ago 1187
Kita semua tahu, bagaimana cara melarang user menutup aplikasi kita, cukup dengan:
procedure TDelphiID.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
CanClose := False;
end;

tapi cara ini membuat aplikasi tidak bisa ditutup, ketika kita ingin shutdown atau restart
antisipasi-nya: manfaatkan WM_QUERYENDSESSION

WM_QUERYENDSESSION dihasilkan oleh Windows ketika OS akan restart/shutdown.
coba perhatikan kode berikut:

unit uDelphiID;
interface
uses
Windows, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs;
type
TfDelphiID = class(TForm)
procedure FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
private
procedure WMQueryEndSession(var Message :
TWMQueryEndSession);
message WM_QUERYENDSESSION;
public
WindowsClosing : Boolean;
end;
var
fDelphiID: TfDelphiID;
implementation
{$R *.DFM}
{ TfDelphiID }
procedure TfDelphiID.FormCreate(Sender: TObject);
begin
WindowsClosing := False;
end;
procedure TfDelphiID.WMQueryEndSession(var Message:
TWMQUERYENDSESSION);
begin
WindowsClosing := True;
end;
procedure TfDelphiID.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
CanClose := WindowsClosing;
end;
end.

Silahkan dicoba.

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com