1、基本没有区别,都是 LongWord 类型的,窗口句柄一般用 HWND,而进程 ID 一般用 THandle,仅此而已。楼上的答案有点小错误。<br>2、你的问题提的不太清楚,通过进程 ID 获得窗口句柄还没有尝试过。不过我写过一个创建进程并取得主窗口句柄的例子,你可以看看:<br>(*<br> 将外部程序主窗口嵌入到我的程序中<br> lpApplicationName: 外部程序名;<br> lpClassName: 嵌入窗口类名(可选 nil);<br> lpWindowName: 嵌入窗口标题(可选 nil);<br> hWndParent: 容器句柄;<br>*)<br>function EmbedWindow(lpApplicationName, lpClassName, lpWindowName: PChar;<br> hWndParent: HWND): THandle;<br>const<br> XSPACE = 5;<br> YSPACE = 5;<br>var<br> lpStartupInfo: _STARTUPINFOA;<br> lpProcessInfo: _PROCESS_INFORMATION;<br> hWndChild: HWND;<br> lpRect: TRect;<br>begin<br> FillChar(lpStartupInfo, SizeOf(lpStartupInfo), 0);<br> lpStartupInfo.cb := SizeOf(StartupInfo);<br> CreateProcess(lpApplicationName, nil, nil, nil, False, DETACHED_PROCESS,<br> nil, nil, lpStartupInfo, lpProcessInfo);<br> Result := lpProcessInfo.hProcess;<br> if Result <> 0 then<br> begin<br> WaitForInputIdle(Result, INFINITE);<br> hWndChild := 0;<br> while hWndChild = 0 do<br> begin<br> hWndChild := FindWindow(lpClassName, lpWindowName);<br> Application.ProcessMessages;<br> end;<br> Windows.SetParent(hWndChild, hWndParent);<br> SetWindowLong(hWndChild, GWL_STYLE, GetWindowLong(hWndChild, GWL_STYLE) and<br> not WS_CAPTION and not WS_BORDER);<br> SetWindowPos(hWndChild, HWND_TOP, XSPACE, YSPACE, 0, 0, SWP_NOSIZE);<br> GetWindowRect(hWndChild, lpRect);<br> SetWindowPos(hWndParent, HWND_TOP, 0, 0,<br> lpRect.Right - lpRect.Left + XSPACE * 2,<br> lpRect.Bottom - lpRect.Top + YSPACE * 2, SWP_NOMOVE);<br> end;<br>end;