/// <summary> /// 程序中所有图表的窗口的句柄值,用来对窗口进行禁用或者启用窗口 /// </summary> /// <param name="AllDrawings"></param> /// <returns></returns> /// <remarks></remarks> public static IntPtr[] GetWindwosHandles(AmeDrawings AllDrawings) { IntPtr[] arrHandles = new IntPtr[AllDrawings.Count() - 1 + 1]; try { int index = 0; AmeDrawings with_1 = AllDrawings; if (with_1.PlanView != null) { arrHandles[index] = with_1.PlanView.Application.Window.WindowHandle32; index++; } if (with_1.SectionalView != null) { arrHandles[index] = with_1.SectionalView.Application.Hwnd; index++; } foreach (ClsDrawing_Mnt_Base mnt in with_1.MonitorData) { arrHandles[index] = mnt.Application.Hwnd; index++; } } catch (Exception ex) { MessageBox.Show("获取窗口句柄出错" + "\r\n" + ex.Message + "\r\n" + "报错位置:" + ex.TargetSite.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(arrHandles); }
/// <summary> /// Showdialog式加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> public void frm_Output_Word_Load(object sender, EventArgs e) { //刷新时间 dateThisday = APPLICATION_MAINFORM.MainForm.Form_Rolling.Rollingday; //设置初始界面 LabelDate.Text = dateThisday.ToString("yyyy/MM/dd"); ChkBxSelect.CheckState = CheckState.Unchecked; CheckBox_PlanView.Checked = false; CheckBox_SectionalView.Checked = false; btnExport.Enabled = false; //为数组中的每一个元素赋值,以便于后面的统一操作:清空内容、全部选择,取消全选 F_arrListBoxes[0] = ListBoxMonitor_Dynamic; F_arrListBoxes[1] = ListBoxMonitor_Static; // F_SelectedDrawings = new Drawings_For_Output(this); //刷新主程序与界面 AmeDrawings AllDrawing = GlobalApplication.Application.ExposeAllDrawings(); // ---------- 禁用所有绘图窗口 WindowHandles = GlobalApplication.GetWindwosHandles(AllDrawing); foreach (IntPtr H in WindowHandles) { APIWindows.EnableWindow(H, false); } // RefreshUI(AllDrawing); }
/// <summary> /// 从主程序中提取所有的图表,以进行输出之用。同时刷新窗口中的可供输出的图形 /// </summary> /// <param name="AllDrawing">主程序对象中所有的图表</param> /// <remarks>在此方法中,将提取主程序中的所有图表对象,而且将其显示在输入窗口的列表框中</remarks> private void RefreshUI(AmeDrawings AllDrawing) { //-------------------------1、剖面图--------------------------------------------- ClsDrawing_ExcavationElevation Sectional = AllDrawing.SectionalView; CheckBox_SectionalView.Tag = Sectional; if (Sectional != null) { CheckBox_SectionalView.Enabled = true; } else { CheckBox_SectionalView.Checked = false; CheckBox_SectionalView.Enabled = false; } //--------------------------2、开挖平面图---------------------------------------------- ClsDrawing_PlanView Plan = AllDrawing.PlanView; CheckBox_PlanView.Tag = Plan; if (Plan != null) { CheckBox_PlanView.Enabled = true; } else { CheckBox_PlanView.Checked = false; CheckBox_PlanView.Enabled = false; } //---------------------------------3、监测曲线图--------------------------------------- //清空两个列表框中的所有项目 foreach (ListBox lstbox in F_arrListBoxes) { lstbox.Items.Clear(); lstbox.DisplayMember = LstbxDisplayAndItem.DisplayMember; } foreach (ClsDrawing_Mnt_Base sht in AllDrawing.MonitorData) { switch (sht.Type) { case DrawingType.Monitor_Incline_Dynamic: case DrawingType.Monitor_Dynamic: ListBoxMonitor_Dynamic.Items.Add(new LstbxDisplayAndItem(sht.Chart_App_Title, sht)); break; case DrawingType.Monitor_Static: case DrawingType.Monitor_Incline_MaxMinDepth: ListBoxMonitor_Static.Items.Add(new LstbxDisplayAndItem(sht.Chart_App_Title, sht)); break; } } }
/// <summary> /// 关闭程序中的所有绘图所在的程序,如Excel或者Visio的程序 /// </summary> /// <remarks></remarks> private void QuitDrawingApplications(AmeDrawings AllDrawing) { AmeDrawings with_1 = AllDrawing; //开挖剖面图 if (with_1.SectionalView != null) { with_1.SectionalView.Close(false); } //Visio开挖平面图 if (with_1.PlanView != null) { with_1.PlanView.Close(false); } //监测曲线图 foreach (ClsDrawing_Mnt_Base MntDrawing in with_1.MonitorData) { MntDrawing.Close(false); } }
/// <summary> /// 主程序中所有的绘图,包括不能进行滚动的图形。比如开挖平面图,监测曲线图,开挖剖面图。 /// </summary> /// <returns></returns> /// <remarks></remarks> public AmeDrawings ExposeAllDrawings() { Dictionary_AutoKey <Cls_ExcelForMonitorDrawing> Excel_Monitor = default(Dictionary_AutoKey <Cls_ExcelForMonitorDrawing>); // ClsDrawing_PlanView Visio_PlanView = null; ClsDrawing_ExcavationElevation Elevation = default(ClsDrawing_ExcavationElevation); List <ClsDrawing_Mnt_Base> MonitorData = new List <ClsDrawing_Mnt_Base>(); // Elevation = GlobalApplication.Application.ElevationDrawing; Excel_Monitor = GlobalApplication.Application.MntDrawing_ExcelApps; // //Me.F_AllDrawingsCount = 0 // //对象名称与对象 try { //剖面图 Elevation = GlobalApplication.Application.ElevationDrawing; if (Elevation != null) { //Me.F_AllDrawingsCount += 1 } } catch (Exception) { } try { //平面图 Visio_PlanView = GlobalApplication.Application.PlanView_VisioWindow; if (Visio_PlanView != null) { //Me.F_AllDrawingsCount += 1 } } catch (Exception) { } try { //监测曲线图 foreach (Cls_ExcelForMonitorDrawing MonitorSheets in Excel_Monitor.Values) { foreach (ClsDrawing_Mnt_Base sht in MonitorSheets.Mnt_Drawings.Values) { MonitorData.Add(sht); //Me.F_AllDrawingsCount += 1 } } } catch (Exception) { } AmeDrawings AllDrawings = new AmeDrawings(Elevation, Visio_PlanView, MonitorData); return(AllDrawings); }
/// <summary> /// 退出主程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// 这里用FormClosing事件来控制主程序的退出,而不用Dispose事件来控制, /// 是为了解决其子窗口在各自的FormClosing事件中只是将其进行隐藏并取消了默认的关闭操作, /// 所以这里在主程序最先触发的FormClosing事件中就直接执行Me.Dispose()方法,这样就可以 /// 跳过子窗口的FormClosing事件,而直接退出主程序了。 /// </remarks> public void mainForm_FormClosing(object sender, FormClosingEventArgs e) { AmeDrawings AllDrawing = GlbApp.ExposeAllDrawings(); if (AllDrawing.Count() > 0) { DialogResult result = MessageBox.Show("还有图表未处理,是否要关闭所有绘图并退出程序", "tip", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3); if (result == DialogResult.Yes) //关闭AME主程序,同时也关闭所有的绘图程序。 { Hide(); //' --- 通过新的工作线程来执行绘图程序的关闭。 //Dim thd As New Thread(AddressOf Me.QuitDrawingApplications) //With thd // .Name = "关闭所有绘图程序" // .Start(AllDrawing) // thd.Join() //End With // --- //通过Main Thread来执行绘图程序的关闭。 QuitDrawingApplications(AllDrawing); } //不关闭图表,但关闭程序 else if (result == DialogResult.No) { } //图表与程序都不关闭 else if (result == DialogResult.Cancel) { e.Cancel = true; return; } } // ---------------------- 先隐藏主界面,以达到更好的UI效果。 Hide(); //--------------------------- 断后工作 try { //关闭隐藏的Excel数据库中的所有工作簿 foreach (Workbook wkbk in GlbApp.ExcelApplication_DB.Workbooks) { wkbk.Close(false); } GlbApp.ExcelApplication_DB.Quit(); //这一步非常重要哟 GlbApp.ExcelApplication_DB = null; } catch (Exception) { //有可能会出现数据库文件已经被关闭的情况 } //保存主程序窗口关闭时的界面位置与大小 APPLICATION_MAINFORM with_1 = this; mySettings_UI mysetting = new mySettings_UI(); mysetting.WindowLocation = with_1.Location; mysetting.WindowSize = with_1.Size; mysetting.WindowState = with_1.WindowState; mysetting.Save(); //--------------------------- //这里在主程序最先触发的FormClosing事件中就直接执行Me.Dispose()方法, //这样就可以跳过子窗口的FormClosing事件,而直接退出主程序了。 Dispose(); }