GetProcessMainWnd(获取进程窗口句柄)
程序员文章站
2022-07-13 22:32:49
...
typedef struct tagWNDINFO
{
DWORD dwProcessId;
HWND hWnd;
} WNDINFO, *LPWNDINFO;
BOOL CALLBACK YourEnumProc(HWND hWnd, LPARAM lParam)
{
DWORD dwProcessId;
GetWindowThreadProcessId(hWnd, &dwProcessId);
LPWNDINFO pInfo = (LPWNDINFO)lParam;
if( (dwProcessId == pInfo->dwProcessId))
{
pInfo->hWnd = hWnd;
return FALSE;
}
return TRUE;
}
//获取进程窗口句柄
HWND GetProcessMainWnd(DWORD dwProcessId)
{
WNDINFO wi={0};
wi.dwProcessId = dwProcessId;
EnumWindows(YourEnumProc,(LPARAM)&wi);
HWND re_hwnd = wi.hWnd;
while( GetParent(re_hwnd) != NULL )
{
re_hwnd = GetParent( re_hwnd );
}
return re_hwnd;
}
上一篇: python获取窗口句柄
下一篇: WPF如何获取控件句柄