//关闭window窗体 public static void CloseWindow() { //获取开票软件主窗体 var kprjBar = HxShengQing.GetKprjMainPageBar(); if (kprjBar == IntPtr.Zero) { return; } //前置主窗体 ShowForm(kprjBar); var list = WinApi.EnumChildWindowsCallback(kprjBar); var bar = list.Find(b => b.szWindowName == "红字发票信息表查询导出").hWnd; var barMation = AutomationElement.FromHandle(bar); barMation.TryGetCurrentPattern(WindowPattern.Pattern, out var obj); ((WindowPattern)obj).Close(); }