1.根据窗口ID,获得创建该窗口的线程ID和进程ID
The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window.
DWORD GetWindowThreadProcessId(
HWND hWnd, //
LPDWORD lpdwProcessId //进程ID
);
The return value is the identifier of the thread that created the window.
2.定义一个CALLBACK函数作为EnumWindows函数的参数来枚举屏幕上的top-level窗口,该窗口句柄会传给CALLBACK函数作为参数
The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.
BOOL EnumWindows(
WNDENUMPROC lpEnumFunc,
LPARAM lParam //枚举窗口时的判断依据,至于如何根据此参数来得到所需的窗口,在
//CALLBACK函数中进行。该参数直接传给CALLBACK函数。
);
If the function succeeds, the return value is nonzero.
BOOL CALLBACK EnumWindowsProc(
HWND hwnd /*top-level窗口句柄*/,
LPARAM lParam /*EnumWindows的第二个参数*/
)
To continue enumeration, the callback function must return TRUE; to stop enumeration, it must return FALSE.