public static IntPtr FindProcessWindow(int processId, string className, string windowName)
{
var result = new Future<IntPtr>();
EnumWindowsProc callback = (hWnd, lParam) => {
int windowProcessId;
GetWindowThreadProcessId(hWnd, out windowProcessId);
if (windowProcessId != processId)
return true;
if ((windowName != null) && (GetWindowTextString(hWnd) != windowName))
return true;
if ((className != null) && (GetWindowClassString(hWnd) != className))
return true;
result.SetResult(hWnd, null);
return false;
};
EnumWindows(callback, IntPtr.Zero);
if (result.Completed)
return result.Result;
else
return IntPtr.Zero;
}