Close application by window name

Posted in System

Use FindWindow function, which returns handle of window, which you want to close. And after that, send WM_CLOSE message to this window.

procedure TForm1.Button1Click(Sender: TObject);
var
  MyHandle: THandle;
begin
  MyHandle:=FindWindow(nil, 'Delphi Help');
  SendMessage(MyHandle, WM_CLOSE, 0, 0);
end;