VC根据进程ID获得主窗口句柄(不是进程句柄)

typedef struct
{ 
	HWND hWnd; 
	DWORD dwPid; 
}WNDINFO; 

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) 
{ 
	WNDINFO* pInfo = (WNDINFO*)lParam; 
	DWORD dwProcessId = 0; 
	GetWindowThreadProcessId(hWnd, &dwProcessId); 

	if(dwProcessId == pInfo->dwPid) 
	{ 
		pInfo->hWnd = hWnd; 
		return FALSE; 
	} 
	return TRUE; 
} 

HWND GetHwndByProcessId(DWORD dwProcessId) 
{ 
	WNDINFO info = {0}; 
	info.hWnd = NULL; 
	info.dwPid = dwProcessId; 
	EnumWindows(EnumWindowsProc, (LPARAM)&info); 
	return info.hWnd; 
}


转自http://www.cnblogs.com/pswzone/archive/2012/07/25/2609121.html

你可能感兴趣的:(VC根据进程ID获得主窗口句柄(不是进程句柄))