VC已知程序实例句柄,如何获取其对应的框架窗口句柄?

请高手帮解答一下,谢谢!
2024-12-02 07:09:27
推荐回答(3个)
回答1:

用EnumThreadWindows。
或者EnumWindows,再用GetWindowThreadProcessId比较句柄。

回答2:

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

回答3:

CWnd *pWnd = GetDlgItem(IDC_VIDEO); //IDC_VIDEO 控件ID
是这意思吗