
function AppIsResponding(const
ClassName: string; const
TimeOut: Cardinal): Boolean;
var
Res: DWORD;
h: HWND;
bClassFound,
bSendMessage: Boolean;
begin
bSendMessage := FALSE;
h := FindWindow(PChar(ClassName), nil);
bClassFound := (h <> 0);
if bClassFound then
bSendMessage := (SendMessageTimeout(H,
WM_NULL,
0,
0,
SMTO_NORMAL or SMTO_ABORTIFHUNG,
TIMEOUT,
Res) <> 0);
result := (bClassFound and bSendMessage);
end;
procedure AppRestart;
begin
AppExec(ParamStr(0),
'', SW_SHOW); // <<-- Function AppExec is
here
TerminateProcess(GetCurrentProcess, 0);
end;
uses ShellAPI;
procedure ExecAndWait(const FileName, Params:
string; const
CmdShow: Integer);
var
exInfo: TShellExecuteInfo;
Ph: DWORD;
begin
FillChar(exInfo, SizeOf(exInfo), 0);
with
exInfo do
begin
cbSize :=
SizeOf(exInfo);
fMask :=
SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd :=
GetActiveWindow();
ExInfo.lpVerb
:= 'open';
ExInfo.lpParameters := PChar(Params);
lpFile :=
PChar(FileName);
nShow :=
CmdShow;
end;
if ShellExecuteEx(@exInfo)
then
Ph := exInfo.HProcess
else
begin
ShowMessage(SysErrorMessage(GetLastError));
Exit;
end;
while WaitForSingleObject(ExInfo.hProcess,
50) <> WAIT_OBJECT_0 do
ProcessMessages;
CloseHandle(Ph);
end;
procedure AppMaximize(hWin: HWND);
begin
SendMessage(hWin, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
end;
procedure
AppMinimize(hWin: HWND);
begin
SendMessage(hWin, WM_SYSCOMMAND,
SC_MINIMIZE, 0);
end;