根据process id和窗口名得到窗口句柄

 

 

typedef struct tagWNDINFO { DWORD dwProcessId; HWND hWnd; CString caption; } WNDINFO, *LPWNDINFO;

BOOL CALLBACK MyEnumProc(HWND hWnd,LPARAM lParam) { DWORD dwProcessId; TCHAR strCaption[30]; CString cap; GetWindowThreadProcessId(hWnd, &dwProcessId); TRACE("%d/n", dwProcessId); LPWNDINFO pInfo = (LPWNDINFO)lParam; if(dwProcessId == pInfo->dwProcessId) { pInfo->hWnd = hWnd; GetWindowText(hWnd, strCaption, 30); cap.Format("%s", strCaption); if (pInfo->caption == cap) { return FALSE; } return TRUE; } return TRUE; } HWND GetProcessMainWnd(DWORD dwProcessId) { WNDINFO wi; wi.dwProcessId = dwProcessId; wi.hWnd = NULL; wi.caption = "侠义道II"; EnumWindows(MyEnumProc,(LPARAM)&wi); return wi.hWnd; }

 

光比较pid还不够,程序有子窗口,所以再比较窗口名,呵呵

你可能感兴趣的:(windows学习)