I have a handle to a control that belongs to another process in the system.
How can I get the process it belongs to? I've tried looking up a suitable function but haven't found much.
I suppose that by "handle to a control", you mean a HWND.
Then, use GetWindowThreadProcessId
HWND hWndToSomeControl;
[...]
DWORD dwPid;
GetWindowThreadProcessId( hWndToSomeControl, &dwPid );
Edit: error control (Tested on Windows 7):
HWND hWndToSomeControl;
[...]
DWORD dwPid;
DWORD dwTid = GetWindowThreadProcessId( hWndToSomeControl, &dwPid );
if ( dwTid == 0 ) {
DWORD dwLE = GetLastError(); // may be 1400 ERROR_INVALID_WINDOW_HANDLE
[...]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.