function MainApplicationHandle: HWND;
var
  MainModule: HMODULE;
  CurrentPID: DWORD;
  WindowsPID: DWORD;
begin
  MainModule := GetModuleHandle(nil);
  CurrentPID := GetCurrentProcessID();

  Result := 0;
  while True do
  begin
    Result := FindWindowEx(0, Result, 'TApplication', nil);
    if (Result = 0) then Exit; // 未找到

    GetWindowThreadProcessID(Result, WindowsPID);
    if (WindowsPID = CurrentPID) and
       (HMODULE(GetWindowLong(Result, GWL_HINSTANCE)) = MainModule)
    then Exit; // 找到!!
  end;
end;

 

相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2021-06-28
  • 2022-02-17
  • 2022-12-23
  • 2021-11-15
猜你喜欢
  • 2021-12-29
  • 2021-07-14
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案