FindWindowEx

procedure CloseGameSver();
var
  H1, h2: HWND;
begin
  H1 := FindWindow('TForm1', nil);
  h2 := FindWindowEx(H1, 0, 'ConsoleWindowClass', nil);
  // ShowMessage(Inttostr(h2));
  SendMessage(h2, WM_CLOSE, 0, 0);
end;
原文地址:https://www.cnblogs.com/xe2011/p/3528854.html