管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-09-25 85b05ad7bc5ba6d7755957e4c6b1ba10c031c23b
TEWin/FrmWin.cs
@@ -9,6 +9,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using TerraExplorerX;
using TETree;
@@ -33,9 +34,17 @@
        public SGWorld71 SG;
        System.Timers.Timer timer;
        ITerrainLabel71 angleLabel;
        ITerrainLabel71 aLabel;
        ITerrainLabel71 bLabel;
        ITerrainPolyline71 angleLine;
        string startName = "OnStart";
        string angleGroupName = "角量算";
@@ -43,17 +52,15 @@
        string mainUrl = Application.StartupPath;
        System.Timers.Timer timer;
        public FrmWin()
        {
            InitializeComponent();
            //this.KeyPreview = true;
            this.Load += FrmWeb_Load;
            //this.KeyDown += FrmWin_KeyDown;
            this.FormClosed += FrmWin_FormClosed;
            this.Load += FrmWeb_Load;
            this.FormClosing += FrmWin_FormClosing;
            timer = new System.Timers.Timer(1500);
            timer = new System.Timers.Timer(1000);
            timer.Elapsed += timer_Elapsed;
        }
@@ -77,13 +84,14 @@
                LogOut.Info("开始运行..");
                bool isTest = "1" == ConfigurationManager.AppSettings["isTest"];
                this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"];
                this.fly = getFly();
                /*this.fly = ConfigurationManager.AppSettings["fly"] ?? ConfigurationManager.AppSettings["testFly"];
                if (!this.fly.Contains(":\\")) this.fly = Path.Combine(Application.StartupPath, this.fly);
                if (!File.Exists(this.fly))
                {
                    LogOut.Error("Fly文件不存在:" + this.fly);
                    return;
                }
                }*/
                SG = new SGWorld71();
                SG.OnLoadFinished += SG_OnLoadFinished;
@@ -98,14 +106,13 @@
                    tool = new FrmTool(this);
                    tool.Show();
                    SG.Open(this.fly);
                    //SG.Open(this.fly);
                }
                //else
                //{
                //    this.WindowState = FormWindowState.Maximized;
                //    tree.WindowState = FormWindowState.Maximized;
                //}
            }
            catch (Exception ex)
            {
@@ -115,15 +122,31 @@
        void SG_OnLoadFinished(bool bSuccess)
        {
            this.SG.OnLoadFinished -= SG_OnLoadFinished;
            try
            {
                //this.SG.OnLoadFinished -= SG_OnLoadFinished;
                string id = this.SG.ProjectTree.FindItem(startName);
                if (string.IsNullOrEmpty(id)) return;
                var obj = this.SG.ProjectTree.GetObject(id);
                if (obj.ObjectType == ObjectTypeCode.OT_LOCATION)
                {
                    this.SG.Navigate.FlyTo(id);
                }
            }
            catch { }
        }
        void FrmWin_FormClosed(object sender, FormClosedEventArgs e)
        void FrmWin_FormClosing(object sender, FormClosingEventArgs e)
        {
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" });
            LogOut.Info("关闭程序.");
        }
        #endregion
        #region invoke
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
@@ -148,6 +171,7 @@
        public void InvokeByCode(int code)
        {
            LogOut.Info("InvokeByCode > 0x" + code.ToString("x"));
            switch (code)
            {
                case 0xc0: // 重置鼠标模式
@@ -155,7 +179,7 @@
                case 0xc1: // 打开数据方案/打开显示场景
                    SG.Command.Execute(1001, null); break;
                case 0xc2: // 保存数据方案/保存显示场景
                    SG.Command.Execute(1003, null); break;
                    Save(); break;
                case 0xc3: // 矢量数据(默认为*.shp,支持Excel)
                    SG.Command.Execute(1013, 5); break;
                case 0xc4: // 影像数据(默认为*.tif)
@@ -163,12 +187,7 @@
                case 0xc5: // 地形数据(默认为*.tif)
                    SG.Command.Execute(1014, 26); break;
                case 0xc6: // 模型数据(*.osgb)
                    ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); // SG.Command.Execute(2342, null);
                    //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
                    RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
                    timer.Stop();
                    timer.Start();
                    break;
                    ExportOsgb(); break;
                case 0xc7: // 模型数据(*.obj)
                    SG.Command.Execute(1012, 13); break;
                case 0xc8: // 编辑数据(选择对象,开启编辑)
@@ -212,8 +231,47 @@
                    DisplayByAttribute(0, "按照属性显示"); break;
                case 0xdb: // 按照属性设置颜色
                    DisplayByAttribute(1, "按照属性设置颜色"); break;
                case 0xdc: // 打开数据方案
                    Open(); break;
                case 0xdd: // 另存为
                    SaveAs(); break;
                case 0xde: // 选择对象
                    SG.Command.Execute(1021, 0); break;
                case 0xdf: // 导出模型(其它)
                    ExportOther(); break;
                case 0xe0: // 刷新图层
                    SG.Command.Execute(1087, 0); break;
                case 0xe1: // 保存图层
                    SG.Command.Execute(1088, 0); break;
                case 0xe2: // 复制
                    SG.Command.Execute(1031, 0); break;
                case 0xe3: // 剪切
                    SG.Command.Execute(1032, 0); break;
                case 0xe4: // 删除
                    SG.Command.Execute(1033, 0); break;
                case 0xe5: // 粘贴至屏幕中心
                    SG.Command.Execute(1030, 0); break;
            }
        }
        private void ExportOsgb()
        {
            ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" }); // SG.Command.Execute(2342, null);
            //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
            RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ImportMeshLayer -Type osgb", false); // -RunApp TerraExplorer
            timer.Stop();
            timer.Start();
        }
        private void ExportOther()
        {
            ExecCmd(new List<string> { "taskkill /f /t /im MeshLayerTool.exe" });
            //RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "slmeshconverter.exe"), " -cmd convert -in \"D:/SEM/osgb/xizhan.3dml\" -f 3dml -out \"C:/Export.3dml\" -vdat convert_z -wktout -ui 1", false);
            RunExe(Path.Combine(ConfigurationManager.AppSettings["tePath"], "MeshLayerTool.exe"), " -RunApp TerraExplorer -RunConvertor -Mode ExportMeshLayer", false);
            timer.Stop();
            timer.Start();
        }
        #endregion
        #region user32.dll
        public const int SWP_NOSIZE = 0x0001;
@@ -265,18 +323,79 @@
                }
            }
        }
        #endregion
        public static void Main()
        #region OSGBLab
        const int GCLP_HICON = -14;
        const int ICON_SMALL = 0;
        const int ICON_BIG = 1;
        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowsName);
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("user32.dll", SetLastError = true)]
        static extern bool SetWindowText(IntPtr hWnd, String lpString);
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr SetClassLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
        public void DealOsgbLab()
        {
            // 获取指定窗体的句柄
            //IntPtr hWnd = // 获取窗体句柄的方法,例如FindWindow或者通过进程名获取
            // 获取窗体的坐标
            //RECT rect;
            //GetWindowRect(hWnd, out rect);
            //Console.WriteLine("窗体坐标: 左上角({0}, {1}), 右下角({2}, {3})", rect.Left, rect.Top, rect.Right, rect.Bottom);
            /*Process[] processes = Process.GetProcessesByName("OSGBLab");
            if (processes.Length > 0)
            {
                IntPtr hWnd = processes[0].MainWindowHandle;
                SetWindowText(hWnd, "OSGB数据处理工具");
            }*/
            IntPtr hWnd = FindWindow(null, "OSGBLab(倾斜伴侣) (Windows) 免费版");
            if (hWnd == IntPtr.Zero) return;
            DealOsgbLab(hWnd);
        }
        public void DealOsgbLab(Process p)
        {
            do
            {
                if (p.MainWindowHandle != IntPtr.Zero)
                {
                    DealOsgbLab(p.MainWindowHandle);
                    break;
                }
                Thread.Sleep(50);
            } while (true);
        }
        [DllImport("user32.dll", EntryPoint = "SetClassLongPtr", SetLastError = true)]
        static extern IntPtr SetClassLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
        [DllImport("user32.dll", EntryPoint = "SetClassLong", SetLastError = true)]
        static extern int SetClassLong32(IntPtr hWnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll")]
        static extern IntPtr LoadIcon(IntPtr hInstance, IntPtr iconName);
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        public void DealOsgbLab(IntPtr hWnd)
        {
            //ShowWindow(hWnd, 0); // 5
            SetWindowText(hWnd, ConfigurationManager.AppSettings["osgbLabTitle"]);
            Icon icon = new Icon(Path.Combine(mainUrl, @"Resources\favicon.ico"));
            SetClassLongPtr(hWnd, GCLP_HICON, icon.Handle);
            //SetClassLongPtr(hWnd, GCLP_HICON + ICON_BIG, icon.Handle);
        }
        #endregion
        #region ShowHtml+RunExe
        public void ShowHtmlByid(int id, int arg)
        {
            switch (id)
@@ -324,7 +443,7 @@
            SG.Window.ShowPopup(popup);
        }
        public void RunExe(string path, string args, bool noWindow = true)
        public Process RunExe(string path, string args, bool noWindow = true)
        {
            Process p = new Process();
            p.StartInfo.FileName = path;
@@ -332,6 +451,8 @@
            p.StartInfo.CreateNoWindow = noWindow;
            p.StartInfo.UseShellExecute = false;
            p.Start();
            return p;
        }
        public static string ExecCmd(List<string> list)
@@ -379,6 +500,7 @@
            return str;
        }
        #endregion
        #region 角量算
        private void AngleMeasurement()
@@ -455,26 +577,16 @@
                if (angleCount % 3 == 2)
                {
                    IPoint firstPoint = (IPoint)line.Points[line.Points.Count - 3];
                    IPoint secondPoint = (IPoint)line.Points[line.Points.Count - 2];
                    IPoint nowPoint = (IPoint)line.Points[line.Points.Count - 1];
                    var firstPosition = SG.Creator.CreatePosition(firstPoint.X, firstPoint.Y);
                    var secondPosition = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y);
                    var nowPosition = SG.Creator.CreatePosition(nowPoint.X, nowPoint.Y);
                    IPoint p1 = (IPoint)line.Points[0];
                    IPoint p2 = (IPoint)line.Points[1];
                    IPoint p3 = (IPoint)line.Points[2];
                    var pos1 = SG.Creator.CreatePosition(p1.X, p1.Y);
                    var pos2 = SG.Creator.CreatePosition(p2.X, p2.Y);
                    var pos3 = SG.Creator.CreatePosition(p3.X, p3.Y);
                    nowPosition = SG.CoordServices.GetAimingAngles(nowPosition, secondPosition);
                    secondPosition = SG.CoordServices.GetAimingAngles(firstPosition, secondPosition);
                    if (secondPosition.Yaw > nowPosition.Yaw)
                    {
                        angleSize = secondPosition.Yaw - nowPosition.Yaw;
                        if (angleSize > 180) angleSize = 360 - secondPosition.Yaw + nowPosition.Yaw;
                    }
                    else
                    {
                        angleSize = nowPosition.Yaw - secondPosition.Yaw;
                        if (angleSize > 180) angleSize = 360 + secondPosition.Yaw - nowPosition.Yaw;
                    }
                    angleSize = Math.Round(angleSize, 2);
                    var first = SG.CoordServices.GetAimingAngles(pos1, pos2);
                    var sencod = SG.CoordServices.GetAimingAngles(pos2, pos3);
                    angleSize = getAngle(first, sencod);
                    angleLabel.Text = angleSize.ToString() + "°";
                }
            }
@@ -482,6 +594,25 @@
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        private double getAngle(IPosition71 first, IPosition71 sencod)
        {
            /*double angle = 0;
            if (sencod.Yaw > first.Yaw)
            {
                angle = sencod.Yaw - first.Yaw;
                if (angle > 180) angle = 360 - sencod.Yaw + first.Yaw;
            }
            else
            {
                angle = first.Yaw - sencod.Yaw;
                if (angle > 180) angle = 360 + sencod.Yaw - first.Yaw;
            }*/
            double angle = sencod.Yaw > first.Yaw ? sencod.Yaw - first.Yaw : first.Yaw - sencod.Yaw;
            return Math.Round(angle, 2);
        }
        bool Angle_OnLButtonDown(int Flags, int X, int Y)
@@ -494,45 +625,41 @@
                var gid = GetGroupId(angleGroupName);
                if (angleLine == null)
                {
                    IList<double> lineVertex = new List<double>();
                    lineVertex.Add(CursorCoord.Position.X);
                    lineVertex.Add(CursorCoord.Position.Y);
                    lineVertex.Add(0);
                    lineVertex.Add(CursorCoord.Position.X);
                    lineVertex.Add(CursorCoord.Position.Y);
                    lineVertex.Add(0);
                    double[] px = new double[lineVertex.Count];
                    lineVertex.CopyTo(px, 0);
                    var myGeometry = SG.Creator.GeometryCreator.CreateLineStringGeometry(px);
                    angleLine = SG.Creator.CreatePolyline(myGeometry, SG.Creator.CreateColor(255, 255, 0, 255), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, gid, angleCount.ToString());
                    angleLine.LineStyle.Width = -2;
                    angleLine = CreateLine(CursorCoord.Position, gid);
                    angleLine.Geometry.StartEdit();
                    angleCount++;
                    return true;
                }
                ILineString line = (ILineString)(angleLine.Geometry);
                if (angleCount % 3 == 1)
                {
                    angleLabel = SG.Creator.CreateLabel(CursorCoord.Position, angleSize.ToString(), "", null, gid, angleCount.ToString());
                    var LableColor = SG.Creator.CreateColor();
                    LableColor.FromHTMLColor("#FFFF00");
                    LableColor.SetAlpha(0.6);
                    angleLabel.Style.TextColor = LableColor;
                    angleLabel.Style.Bold = true;
                    angleLabel.Style.FontName = "黑体";
                    angleLabel.Style.FontSize = 12;
                    // angleLabel.Style.LineToGround = true;
                    angleLabel.Style.LineToGroundType = LineType.LINE_TYPE_TO_GROUND;
                    angleLabel.Style.Scale = 5000;
                    angleLabel = CreateLabel(CursorCoord.Position, gid, "#FFFF00");
                    IPoint firstPoint = (IPoint)line.Points[0];
                    IPoint secondPoint = (IPoint)line.Points[1];
                    var firstPos = SG.Creator.CreatePosition(firstPoint.X, firstPoint.Y);
                    var secondPos = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y);
                    aLabel = CreateLabel(firstPos, gid, "#00FFFF");
                    aLabel.Text = Math.Round(SG.CoordServices.GetAimingAngles(firstPos, secondPos).Yaw, 2) + "°";
                }
                if (angleCount % 3 == 2) angleLabel.Text = angleSize.ToString() + "°";
                if (angleCount % 3 == 2)
                {
                    IPoint secondPoint = (IPoint)line.Points[line.Points.Count - 2];
                    IPoint nowPoint = (IPoint)line.Points[line.Points.Count - 1];
                    var secondPos = SG.Creator.CreatePosition(secondPoint.X, secondPoint.Y);
                    var newPos = SG.Creator.CreatePosition(nowPoint.X, nowPoint.Y);
                    bLabel = CreateLabel(newPos, GetGroupId(angleGroupName), "#00FFFF");
                    bLabel.Text = Math.Round(SG.CoordServices.GetAimingAngles(secondPos, newPos).Yaw, 2) + "°";
                    angleLabel.Text = angleSize.ToString() + "°";
                }
                angleCount++;
                ILineString line = (ILineString)(angleLine.Geometry);
                IPoint p = (IPoint)line.Points[line.Points.Count - 1];
                p.X = CursorCoord.Position.X; ;
                p.Y = CursorCoord.Position.Y;
@@ -544,6 +671,8 @@
                    angleCount = 0;
                    angleLine = null;
                    angleLabel = null;
                    aLabel = null;
                    bLabel = null;
                }
            }
            catch (Exception ex)
@@ -552,6 +681,44 @@
            }
            return true;
        }
        private ITerrainPolyline71 CreateLine(IPosition71 pos, String gid)
        {
            IList<double> lineVertex = new List<double>();
            lineVertex.Add(pos.X);
            lineVertex.Add(pos.Y);
            lineVertex.Add(0);
            lineVertex.Add(pos.X);
            lineVertex.Add(pos.Y);
            lineVertex.Add(0);
            double[] px = new double[lineVertex.Count];
            lineVertex.CopyTo(px, 0);
            var myGeometry = SG.Creator.GeometryCreator.CreateLineStringGeometry(px);
            var line = SG.Creator.CreatePolyline(myGeometry, SG.Creator.CreateColor(255, 255, 0, 255), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, gid, angleCount.ToString());
            line.LineStyle.Width = -2;
            return line;
        }
        private ITerrainLabel71 CreateLabel(IPosition71 pos, String gid, String color)
        {
            var lableColor = SG.Creator.CreateColor();
            lableColor.FromHTMLColor(color);
            lableColor.SetAlpha(0.6);
            var label = SG.Creator.CreateLabel(pos, "0", "", null, gid, "");
            label.Style.TextColor = lableColor;
            label.Style.Bold = true;
            label.Style.FontName = "黑体";
            label.Style.FontSize = 12;
            // label.Style.LineToGround = true;
            label.Style.LineToGroundType = LineType.LINE_TYPE_TO_GROUND;
            label.Style.Scale = 5000;
            return label;
        }
        bool Angle_OnRButtonUp(int Flags, int X, int Y)
@@ -566,6 +733,7 @@
        }
        #endregion
        #region 调用Html
        private string GetAbsolutePath(string key)
        {
            string str = ConfigurationManager.AppSettings[key];
@@ -586,13 +754,15 @@
        private void InvokeOsgbLab()
        {
            ExecCmd(new List<string> { "taskkill /f /t /im OSGBLab.exe" });
            RunExe(GetAbsolutePath("osgblabPath"), null, false);
            Process p = RunExe(GetAbsolutePath("osgblabPath"), null, false);
            DealOsgbLab(p);
        }
        private void DisplayByAttribute(int type, String name)
        {
            this.ShowHtml(name, mainUrl + @"\Resources\DisplayByAttribute\DisplayByAttribute.html?Type=" + type + "&lang=2052", 20, 20, 365, 355);
        }
        #endregion
        #region 加载shp + 读取shp
        private void LoadShp()
@@ -695,5 +865,136 @@
            return shpTxtPath;
        }
        #endregion
        #region 方案管理
        private void Save()
        {
            string emptyFly = Path.Combine(Application.StartupPath, "Resources", "empty.fly");
            if (emptyFly.Equals(this.fly))
            {
                SaveAs();
                return;
            }
            SaveLocation();
            this.SG.Command.Execute(1019, 0); // Capture Tree State
            SG.Command.Execute(1003, 0); // this.SG.Project.Save(); //
        }
        private void SaveLocation()
        {
            try
            {
                string id = this.SG.ProjectTree.FindItem(startName);
                if (!string.IsNullOrEmpty(id)) this.SG.ProjectTree.DeleteItem(id);
                var pos = this.SG.Navigate.GetPosition();
                var loc = this.SG.Creator.CreateLocationHere(this.SG.ProjectTree.RootID, startName);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        private void Open()
        {
            this.fly = getFly();
            this.SG.Open(this.fly);
        }
        private String getFly()
        {
            string flyPath = ReadPrjPath();
            if (String.IsNullOrEmpty(flyPath)) flyPath = "empty.fly";
            if (!flyPath.Contains(":\\")) flyPath = Path.Combine(Application.StartupPath, "Resources", flyPath);
            return flyPath;
        }
        private String ReadPrjPath()
        {
            try
            {
                String txt = Path.Combine(mainUrl, "Resources", "fly.txt");
                if (!File.Exists(txt)) return null;
                using (StreamReader sr = new StreamReader(txt))
                {
                    return sr.ReadLine();
                }
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
        private void SaveAs()
        {
            string flyPath = ReadPrjPath();
            string fileName = String.IsNullOrEmpty(flyPath) ? null : Path.GetFileName(flyPath);
            string dest = SaveAs(fileName);
            if (string.IsNullOrEmpty(dest)) return;
            this.fly = dest;
            string sourcePath = Path.Combine(mainUrl, "Resources");
            if (string.IsNullOrEmpty(flyPath) || (dest.Contains(sourcePath) && dest.IndexOf("\\", sourcePath.Length + 1) == -1)) return;
            CreateShortcut(flyPath, this.fly);
            //ExecCmd(new List<string> { string.Format("mklink \"{0}\" \"{1}\"", flyPath, this.fly) });
        }
        private String SaveAs(String fileName)
        {
            try
            {
                if (String.IsNullOrEmpty(fileName)) fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".fly";
                SaveLocation();
                this.SG.Command.Execute(1019, 0); // Capture Tree State
                this.SG.Project.SaveAs(fileName);
                string source = Path.Combine(GetSavePath(), fileName);
                if (!File.Exists(source))
                {
                    LogOut.Error(fileName + ",找不到");
                }
                string dest = Path.Combine(Application.StartupPath, "Resources", fileName);
                if (File.Exists(dest)) File.Delete(dest);
                File.Move(source, dest);
                return dest;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
        private String GetSavePath()
        {
            string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string tePathName = ConfigurationManager.AppSettings["tePath"].Contains("SmartEarth") ? "SmartEarth" : "Skyline";
            return Path.Combine(appData, tePathName, "TerraExplorer");
        }
        public static void CreateShortcut(string shortcutPath, string targetPath, string description = null, string iconLocation = null)
        {
            var shell = new IWshRuntimeLibrary.WshShell();
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath + ".lnk"); // 创建快捷方式对象
            shortcut.TargetPath = targetPath; // 指定目标路径
            shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); // 设置起始位置
            shortcut.WindowStyle = 1; // 设置运行方式,默认为常规窗口
            shortcut.Description = description; // 设置备注
            shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; // 设置图标路径
            shortcut.Save(); // 保存快捷方式
        }
        #endregion
    }
}