dll得到主窗體的handle
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;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/archive/2008/04/05/2941039.html