您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi获得一个进程的主窗体

时间:2011/9/3 15:38:35 点击:

  核心提示:type TMainWindow = packed record ProcessID: THandle; MainWindow: THandle; end; PMainWindow =^ TMainW...

type
  TMainWindow = packed record
    ProcessID: THandle;
    MainWindow: THandle;
  end;
  PMainWindow =^ TMainWindow;

function IsMainWindow(AHandle: THandle): Boolean; begin   Result :=(GetWindow(AHandle, GW_OWNER) = 0) and (IsWindowVisible(AHandle)); end;{ IsMainWindow }   function fFindMainWindow(hWnd: THandle; lParam: PMainWindow): BOOL; stdcall; var   vProcessID: THandle; begin   GetWindowThreadProcessId(hWnd, vProcessID);   if (lParam^.ProcessID = vProcessID) and IsMainWindow(hWnd) then   begin     lParam^.MainWindow := hWnd;     Result := False;   end else Result := True; end;   function FindMainWindow(AProcessID: THandle): THandle; var   vMainWindow: TMainWindow; begin   vMainWindow.ProcessID := AProcessID;   vMainWindow.MainWindow := 0;   EnumWindows(@fFindMainWindow, Integer(@vMainWindow));   Result := vMainWindow.MainWindow; end;{ FindMainWindow }   procedure TForm1.Button1Click(Sender: TObject); begin   Caption := Format('Application.Handle: %d, FindMainWindow(): %d',[     Application.Handle, FindMainWindow(GetCurrentProcessId)]); end;

作者:网络 来源:转载
共有评论 1相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2017 版权所有 All Rights Reserved.
  • 沪ICP备05001939号