分享

dll得到主窗体的handle

 独孤求财 2012-03-20

dll得到主窗体的handle

时间:2011-5-26来源:yang 作者: peng点击: 13次

function TForm1.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;  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多