private static IntPtr FindDescendantBy(IntPtr parent, string className = null, string text = null) { var matches = new List <IntPtr>(); WindowsApi.EnumChildWindows(parent, (handle, pointer) => { if ( (className == null || WindowsHelpers.GetWindowClassName(handle) == className) && (text == null || WindowsHelpers.GetWindowTextRaw(handle) == text) ) { matches.Add(handle); } return(true); }, IntPtr.Zero); if (matches.Count > 1) { throw new Exception($"Found {matches.Count} matching descendants."); } return(matches.FirstOrDefault()); }
public void Dispose() { if (!WindowsApi.SetThreadDesktop(originalDesktop)) { WindowsHelpers.CheckLastError(); } }
public void Dispose() { if (!WindowsApi.CloseDesktop(Handle)) { WindowsHelpers.CheckLastError(); } }
public int?GetExitCode() { if (!WindowsApi.GetExitCodeProcess(processInformation.hProcess, out var exitCode)) { WindowsHelpers.CheckLastError(); } return(exitCode == 259 /* STILL_ACTIVE */ ? null : (int?)exitCode); }
public Desktop(string baseName) { Name = baseName + " " + DateTime.Now.Ticks.ToString(); //Ensuring this is unique since sometimes a name can't be reused later on Handle = WindowsApi.CreateDesktop(Name, null, null, 0, WindowsApi.ACCESS_MASK.DESKTOP_CREATEWINDOW, null); if (Handle == IntPtr.Zero) { WindowsHelpers.CheckLastError(); } }
public void Dispose() { if (!WindowsApi.CloseHandle(processInformation.hProcess)) { WindowsHelpers.CheckLastError(); } if (!WindowsApi.CloseHandle(processInformation.hThread)) { WindowsHelpers.CheckLastError(); } }
/// <summary> /// Switches to the <paramref name="newDesktopHandle"/> desktop. /// </summary> public DesktopContext(IntPtr newDesktopHandle) { originalDesktop = WindowsApi.GetThreadDesktop(WindowsApi.GetCurrentThreadId()); if (originalDesktop == IntPtr.Zero) { WindowsHelpers.CheckLastError(); } if (!WindowsApi.SetThreadDesktop(newDesktopHandle)) { WindowsHelpers.CheckLastError(); } }
private static List <IntPtr> FindDescendantsBy(IntPtr parent, string className = null, string text = null) { var matches = new List <IntPtr>(); WindowsApi.EnumChildWindows(parent, (handle, pointer) => { if ( (className == null || WindowsHelpers.GetWindowClassName(handle) == className) && (text == null || WindowsHelpers.GetWindowTextRaw(handle) == text) ) { matches.Add(handle); } return(true); }, IntPtr.Zero); return(matches); }
public DesktopProcess(string commandLine, string desktopName) { var startupInfo = new WindowsApi.STARTUPINFO { cb = Marshal.SizeOf <WindowsApi.STARTUPINFO>(), lpDesktop = desktopName, }; if (!WindowsApi.CreateProcess( null, commandLine, null, null, true, 0, IntPtr.Zero, null, ref startupInfo, out processInformation )) { WindowsHelpers.CheckLastError(); } }