function NewProc(hWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Case Msg of
WM_QUIT: Exit;
WM_CLOSE: Exit;
end;
Result := CallWindowProc(OldProc, hWnd, Msg, wParam, lParam);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OldProc := Pointer(GetWindowLong(Handle, GWL_WNDPROC));
if Assigned(@OldProc) then
SetWindowLong(Handle, GWL_WNDPROC, Integer(@NewProc));
end;