You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
246 lines
10 KiB
246 lines
10 KiB
using KGIS.Framework.Utils; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using static Kingo.Plugin.EngineEditor.Common.GetAllDesktopWindows; |
|
using System.Runtime.InteropServices; |
|
using KGIS.Framework.Utils.Helper; |
|
|
|
namespace Kingo.Plugin.EngineEditor.Common |
|
{ |
|
public class CloseTheDesktopWindows |
|
{ |
|
[DllImport("coredll.dll", EntryPoint = "FindWindow")] |
|
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); |
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] |
|
public static extern IntPtr GetForegroundWindow(); |
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] |
|
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow); |
|
|
|
//这个外部函数(非托管) 可以向句柄发送消息,关闭事件就是这个 |
|
[DllImport("User32.dll", EntryPoint = "SendMessage")] |
|
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); |
|
|
|
public const int WM_CLOSE = 0x0010; |
|
|
|
public bool bShowJudgeMsg = false; |
|
|
|
public bool ToCloseTheDesktopWindows() |
|
{ |
|
IntPtr intPtrTemp = new IntPtr(0); |
|
string sNeedCloseWindowsNames = ""; |
|
|
|
string sNameT_ = ""; |
|
|
|
//右击图层 |
|
#region 右击图层 |
|
sNeedCloseWindowsNames += ",数据导入"; |
|
sNeedCloseWindowsNames += ",选择导入的数据"; |
|
sNeedCloseWindowsNames += ",SQL"; |
|
sNeedCloseWindowsNames += ",图层属性"; |
|
sNeedCloseWindowsNames += ",选择矢量图层数据"; |
|
sNeedCloseWindowsNames += ",标注表达式"; |
|
sNeedCloseWindowsNames += ",符号选择"; |
|
sNeedCloseWindowsNames += ",标注布局"; |
|
sNeedCloseWindowsNames += ",标注可视比例尺设置"; |
|
sNeedCloseWindowsNames += ",创建查询"; |
|
sNeedCloseWindowsNames += ",导入符号渲染"; |
|
sNeedCloseWindowsNames += ",符号库选择"; |
|
sNeedCloseWindowsNames += ",点符号旋转"; |
|
sNeedCloseWindowsNames += ",字段查找与替换"; |
|
#endregion |
|
|
|
//图形编辑 |
|
#region 数据转换 |
|
sNeedCloseWindowsNames += ",画双线"; |
|
sNeedCloseWindowsNames += ",画线物面"; |
|
#endregion |
|
|
|
//地图操作 |
|
#region 地图操作 |
|
sNeedCloseWindowsNames += ",新建方案"; |
|
sNeedCloseWindowsNames += ",测量"; |
|
sNeedCloseWindowsNames += ",转到XY"; |
|
#endregion |
|
|
|
//数据导入导出 |
|
#region 数据导入导出 |
|
sNeedCloseWindowsNames += ",导入MDB数据"; |
|
sNeedCloseWindowsNames += ",选择导入的数据"; |
|
sNeedCloseWindowsNames += ",提示信息"; |
|
sNeedCloseWindowsNames += ",导入GDB数据"; |
|
sNeedCloseWindowsNames += ",导入Shape数据"; |
|
sNeedCloseWindowsNames += ",导入VCT数据"; |
|
sNeedCloseWindowsNames += ",导入调查数据"; |
|
sNeedCloseWindowsNames += ",选择监测图斑数据"; |
|
sNeedCloseWindowsNames += ",选择行政区数据"; |
|
sNeedCloseWindowsNames += ",选择村级调查区数据"; |
|
sNeedCloseWindowsNames += ",选择地类图斑数据"; |
|
sNeedCloseWindowsNames += ",导入举证数据"; |
|
sNeedCloseWindowsNames += ",VCT任意范围导出"; |
|
sNeedCloseWindowsNames += ",自定义导出MDB数据"; |
|
sNeedCloseWindowsNames += ",自定义导出GDB数据"; |
|
sNeedCloseWindowsNames += ",自定义导出SHAPE数据"; |
|
#endregion |
|
|
|
//数据转换 |
|
#region 数据转换 |
|
sNeedCloseWindowsNames += ",VCT转MDB(Personal Geodatabse)数据"; |
|
sNeedCloseWindowsNames += ",VCT转GDB(File Geodatabase)数据"; |
|
sNeedCloseWindowsNames += ",VCT转SHP数据"; |
|
sNeedCloseWindowsNames += ",MDB转GDB"; |
|
sNeedCloseWindowsNames += ",MDB转SHP"; |
|
sNeedCloseWindowsNames += ",MDB(Personal Geodatabase)转VCT"; |
|
sNeedCloseWindowsNames += ",GDB转MDB"; |
|
sNeedCloseWindowsNames += ",GDB转SHP"; |
|
sNeedCloseWindowsNames += ",GDB(File Geodatabase)转VCT"; |
|
sNeedCloseWindowsNames += ",SHP转MDB"; |
|
sNeedCloseWindowsNames += ",SHP转GDB"; |
|
sNeedCloseWindowsNames += ",Shape转VCT"; |
|
#endregion |
|
|
|
//查询分析(智能查询) |
|
#region 查询分析(智能查询) |
|
sNeedCloseWindowsNames += ",根据属性查询"; |
|
sNeedCloseWindowsNames += ",错误信息"; |
|
sNeedCloseWindowsNames += ",空间查询"; |
|
sNeedCloseWindowsNames += ",自定义统计"; |
|
sNeedCloseWindowsNames += ",空间分析"; |
|
#endregion |
|
|
|
//变更管理 |
|
#region 变更管理 |
|
sNeedCloseWindowsNames += ",浏览文件夹"; |
|
sNeedCloseWindowsNames += ",整层更新数据入库"; |
|
sNeedCloseWindowsNames += ",选择数据"; |
|
sNeedCloseWindowsNames += ",举证信息"; |
|
sNeedCloseWindowsNames += ",导入数据字典"; |
|
sNeedCloseWindowsNames += ",数据字典编辑"; |
|
sNeedCloseWindowsNames += ",编辑字典"; |
|
sNeedCloseWindowsNames += ",新增字典项"; |
|
sNeedCloseWindowsNames += ",导出数据字典"; |
|
#endregion |
|
|
|
//成果管理 |
|
#region 成果管理 |
|
sNeedCloseWindowsNames += ",创建变更成果模板"; |
|
sNeedCloseWindowsNames += ",一键变更成果导出"; |
|
sNeedCloseWindowsNames += ",一键整库成果输出"; |
|
sNeedCloseWindowsNames += ",变更成果更新入库"; |
|
sNeedCloseWindowsNames += ",检查设置"; |
|
#endregion |
|
|
|
//图件制作 |
|
#region 图件制作 |
|
|
|
#endregion |
|
|
|
sNeedCloseWindowsNames += ","; |
|
|
|
GetAllDesktopWindows allDesktopWindows = new GetAllDesktopWindows(); |
|
|
|
List<WindowInfo> windowInfoList = new List<WindowInfo>(); |
|
|
|
List<WindowInfo> windowInfoList_Judge = new List<WindowInfo>(); |
|
|
|
int iWindowxsCount_Now = 0; |
|
|
|
int iCloseWindowsCount_Now = 0; |
|
string sCloseWindowsName = ""; |
|
try |
|
{ |
|
windowInfoList = allDesktopWindows.ToGetAllDesktopWindows(); |
|
if (windowInfoList != null && windowInfoList.Count() > 0) |
|
{ |
|
iWindowxsCount_Now = windowInfoList.Count(); |
|
|
|
foreach (WindowInfo wInfo in windowInfoList) |
|
{ |
|
if (string.IsNullOrWhiteSpace(wInfo.szWindowName) == true) |
|
{ |
|
continue; |
|
} |
|
else |
|
{ |
|
sNameT_ = wInfo.szWindowName; |
|
sNameT_ = sNameT_.Trim(); |
|
|
|
if (sNeedCloseWindowsNames.Contains("," + sNameT_ + ",") == true) |
|
{ |
|
intPtrTemp = wInfo.hWnd; |
|
//ShowWindow(intPtrTemp, 0);//不显示 |
|
SendMessage(intPtrTemp, WM_CLOSE, 0, 0);// 调用了 发送消息 发送关闭窗口的消息 |
|
iCloseWindowsCount_Now += 1; |
|
sCloseWindowsName += sNameT_ + ","; |
|
//LogAPI.Debug("当前关闭窗口名称: " + sNameT_ + " \r\n ; "); |
|
} |
|
else |
|
{ |
|
if (sNameT_.EndsWith("属性表") == true) |
|
{ |
|
intPtrTemp = wInfo.hWnd; |
|
//ShowWindow(intPtrTemp, 0); |
|
SendMessage(intPtrTemp, WM_CLOSE, 0, 0);// 调用了 发送消息 发送关闭窗口的消息 |
|
iCloseWindowsCount_Now += 1; |
|
sCloseWindowsName += sNameT_ + ","; |
|
//LogAPI.Debug("当前关闭窗口名称: " + sNameT_ + " \r\n ; "); |
|
} |
|
else |
|
{ |
|
if (sNameT_.EndsWith("字段统计") == true) |
|
{ |
|
intPtrTemp = wInfo.hWnd; |
|
//ShowWindow(intPtrTemp, 0); |
|
SendMessage(intPtrTemp, WM_CLOSE, 0, 0);// 调用了 发送消息 发送关闭窗口的消息 |
|
iCloseWindowsCount_Now += 1; |
|
sCloseWindowsName += sNameT_ + ","; |
|
//LogAPI.Debug("当前关闭窗口名称: " + sNameT_ + " \r\n ; "); |
|
} |
|
else |
|
{ |
|
continue; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
string sShowMsg = ""; |
|
sShowMsg += "关闭前 窗口数: " + iWindowxsCount_Now + " 个;\r\n"; |
|
sShowMsg += "关闭数: " + iCloseWindowsCount_Now + " 个:\r\n "; |
|
sShowMsg += "关闭窗口名字: " + sCloseWindowsName + " :\r\n "; |
|
|
|
windowInfoList_Judge = allDesktopWindows.ToGetAllDesktopWindows(); |
|
if (windowInfoList_Judge != null && windowInfoList_Judge.Count() > 0) |
|
{ |
|
sShowMsg += "关闭后 窗口数: " + windowInfoList_Judge.Count() + " 个;\r\n"; |
|
} |
|
|
|
if (bShowJudgeMsg == true) |
|
{ |
|
LogAPI.Debug(sShowMsg); |
|
MessageHelper.Show(sShowMsg, false); |
|
} |
|
|
|
return true; |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("关闭其他窗口 时失败,异常原因: " + ex + " ; "); |
|
return false; |
|
} |
|
finally |
|
{ |
|
if (windowInfoList != null && windowInfoList.Count() > 0) |
|
{ |
|
windowInfoList = null; |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
}
|
|
|