당신이 승리 API 함수를 사용할 수 있다고 생각
: EnumWindowsProc를 창 핸들을 반복하고 GetWindowThreadProcessId는
가 확인하시기 바랍니다 처리 주어진 윈도우와 관련된 스레드 ID 및 프로세스 ID를 얻을 수 있습니다 예를 들어 아래한다면 당신을 위해 일하십시오 :
이 코드는 System.Diagnostics를 사용하여 프로세스와 스레드를 반복합니다.
...
process chrome b70
thread b78
window 2d04c8
window 10354
...
thread bf8
thread c04
...
: 위의이 같은 콘솔 떨어지게에 덤프해야하는 코드의
private IntPtr[] GetWindowHandlesForThread(int threadHandle)
{
_results.Clear();
EnumWindows(WindowEnum, threadHandle);
return _results.ToArray();
}
private delegate int EnumWindowsProc(IntPtr hwnd, int lParam);
[DllImport("user32.Dll")]
private static extern int EnumWindows(EnumWindowsProc x, int y);
[DllImport("user32.dll")]
public static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
private List<IntPtr> _results = new List<IntPtr>();
private int WindowEnum(IntPtr hWnd, int lParam)
{
int processID = 0;
int threadID = GetWindowThreadProcessId(hWnd, out processID);
if (threadID == lParam) _results.Add(hWnd);
return 1;
}
결과 : 나는 GetWindowHandlesForThread 함수를 호출하고있어 각 스레드 ID를
foreach (Process procesInfo in Process.GetProcesses())
{
Console.WriteLine("process {0} {1:x}", procesInfo.ProcessName, procesInfo.Id);
foreach (ProcessThread threadInfo in procesInfo.Threads)
{
Console.WriteLine("\tthread {0:x}", threadInfo.Id);
IntPtr[] windows = GetWindowHandlesForThread(threadInfo.Id);
if (windows != null && windows.Length > 0)
foreach (IntPtr hWnd in windows)
Console.WriteLine("\t\twindow {0:x}", hWnd.ToInt32());
}
}
GetWindowHandlesForThread 구현 (아래 코드 참조)
많은 감사 !!! 그것이 내가 필요한 것입니다. –