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, // handle to window LPDWORD lpdwProcessId // address of variable for process identifier );
HWND hWnd, // handle to window
LPDWORD lpdwProcessId // address of variable for process identifier
);
DWORD dwProcessId;
HANDLE hProcess;
HWND hwnd = FindWindow(NULL, “计算器”);
GetWindowThreadProcessId(hwnd, &dwProcessId);
hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);