WinCE进程ID获取窗口句柄

HWND hwndFind = NULL;

/*
1、枚举所有顶层窗口(不包括子窗口),并将窗口句柄依次传给回调函数
2、枚举结束条件:枚举完成或回调函数返回FALSE
*/ BOOL bRt = EnumWindows(EnumWindowsProc, dwProcessId); //回调函数 BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { DWORD dwPI; GetWindowThreadProcessId(hwnd, &dwPI); if ( dwPI == (DWORD)lParam ) { hwndFind = hwnd; return FALSE; } return TRUE; }

MSDN说明:

  • The EnumWindows function does not enumerate child windows. 

  • This function is more reliable than calling the GetWindow function in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed

posted @ 2012-11-28 11:41  iThinking  阅读(521)  评论(0编辑  收藏  举报