DLL注入某进程后,在DLL内获得主窗口的句柄

在不能使用FindWindow等函数的前提下。

var
  g_hwin:THandle;
function EnumWindowsProc(H:HWND;lParam:LPARAM):Boolean;stdcall;
var
  PID:DWORD;
begin
  Result:=True;
  GetWindowThreadProcessId(H,PID);
  if PID=GetCurrentProcessId then begin
    g_hwin:=H;
    Result:=False;
  end;
end;

procedure TForm1.btn4Click(Sender: TObject);
begin
  EnumWindows(@EnumWindowsProc,0);
  Caption:=IntToStr(g_hwin);
end;

posted on 2011-03-10 18:47  飘啊飘的  阅读(1443)  评论(0编辑  收藏  举报