用EnumThreadWindows。
或者EnumWindows,再用GetWindowThreadProcessId比较句柄。
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)
{
bool isWindowVisible = IsWindowVisible(hWnd);
if(isWindowVisible == true)
{
pInfo->hWnd = hWnd;
return FALSE;
}
}
return TRUE;
}
HWND GetProcessMainWnd(DWORD
dwProcessId)
{
WNDINFO wi;
wi.dwProcessId = dwProcessId;
wi.hWnd =
NULL;
EnumWindows(YourEnumProc,(LPARAM)&wi);
return wi.hWnd;
}
如果这个进程没有窗口,函数返回NULL
CWnd *pWnd = GetDlgItem(IDC_VIDEO); //IDC_VIDEO 控件ID
是这意思吗