Code
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;
wi.dwProcessId = dwProcessId;
wi.hWnd = NULL;
EnumWindows(YourEnumProc,(LPARAM)&wi);
return wi.hWnd;
}
//用的时候
DWORD ProcessID;
HWND hExe=GetProcessMainWnd(ProcessID);//获取最上层窗口,并不一定是CMainFrame,
HWND hPartent=GetParent(hExe);
while (hPartent!=NULL)
{
hExe=hPartent;
hPartent=GetParent(hExe);
}
return hExe;
//此时hExe即为CMainFrame句柄
posted @
2009-05-23 17:43
凌点
阅读(
497)
评论()
编辑
收藏
举报