2010-12-30

Anti WM_QUIT Message di Delphi 7

1. Copy unit Forms.pas milik Delphi yang berada di dalam folder [DRIVE]:\Program Files\Borland\Delphi7\Source\ Vcl, kemudian Paste ke dalam folder Project anda.

2. Edit function TApplication.ProcessMessage(var Msg: TMsg): Boolean; yang ada di baris ke 6856.

function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
  Handled: Boolean;
begin
  Result := False;
  if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
  begin
    Result := True;
    if Msg.Message <> WM_QUIT then
    begin
      Handled := False;
      if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
      if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
        not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    end
    else
      FTerminate := False; { dari True menjadi False }
  end;
end;

3. Masih bersama Forms.pas Buat atau Tambahkan Private Message baru sebagai pengganti WM_QUIT pada procedure TApplication.WndProc(var Message: TMessage);

Contoh nya seperti di bawah ini:

6532: with Message do
6533:  case Msg of
6534:    WM_SYSCOMMAND:
[.....]
6669:    WM_NULL:
6670:      CheckSynchronize;
6671:    WM_USER+666: { Ini Private Message Aplikasi Anda }
6672:      FTerminate := True;
6673:  else
6674:    Default;
6675:  end;


4. Dengan demikian perintah Application.Terminate sudah tidak bisa digunakan lagi, oleh karena itu anda perlu membuat procedure sendiri untuk menutup aplikasi anda.

Contoh:

procedure TForm1.CloseMe;
begin
  PostMessage(Application.Handle, WM_USER+666, 0, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CloseMe;
end;


Sekian.
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 komentar: on "Anti WM_QUIT Message di Delphi 7"