public void ExcelAppConverter_CanGetAppFromMainWindowHandleIfWorkbookIsOpen() { var processId = StartExcelWithWorkbook(); try { var process = Process.GetProcessById(processId); Assert.NotNull(process); var fetcher = new Fetcher <int>( getValue: () => process.MainWindowHandle.ToInt32(), valueFilter: x => (x != 0) && ExcelAppConverter.GetClassNameFromWindowHandle(x) == "XLMAIN", timeoutSeconds: 5); var handle = fetcher.Fetch(); Assert.AreNotEqual(0, handle); var app = ExcelAppConverter.AppFromMainWindowHandle(handle); Assert.NotNull(app); } finally { KillProcess(processId); } }
public void PrintProcessMainWindowHandles() { var id = StartExcelWithWorkbook(); var process = Process.GetProcessById(id); try { Task.Run(() => { while (true) { foreach (var handle in process.WindowHandles()) { var className = ExcelAppConverter.GetClassNameFromWindowHandle(handle.ToInt32()); Debug.WriteLine($"Process: {id}, Hwnd: {handle}, ClassName: {className}"); } Thread.Sleep(100); } }); Thread.Sleep(10000); } finally { KillProcess(id); } }