Ver código fonte

微课打开状态时再次启动自动提示和激活窗口

master
张剑 1 ano atrás
pai
commit
6d8e6c8c18

+ 3
- 3
XHWK.WKTool/App.config Ver arquivo

@@ -5,12 +5,12 @@
5 5
   </startup>
6 6
   <appSettings>
7 7
     <!--0正式 1测试-->
8
-    <add key="IsDebug" value="1" />
8
+    <add key="IsDebug" value="0" />
9 9
     <!--参数是否加密 0不加密 1加密-->
10 10
     <add key="IsParameterEncryption" value="0" />
11 11
     <!--版本号-->
12
-    <add key="VersionCode" value="124" />
13
-    <add key="VersionName" value="3.9.7" />
12
+    <add key="VersionCode" value="125" />
13
+    <add key="VersionName" value="3.9.8" />
14 14
     <!--皮肤样式 0白 1蓝 2黑色 -->
15 15
     <add key="SkinStyle" value="0" />
16 16
     <!--是否输出视频记录日志:0否-->

+ 23
- 21
XHWK.WKTool/App.xaml.cs Ver arquivo

@@ -15,6 +15,7 @@ using XHWK.WKTool.Skin;
15 15
 
16 16
 namespace XHWK.WKTool
17 17
 {
18
+    using System.Runtime.InteropServices;
18 19
     using system;
19 20
 
20 21
     public partial class App
@@ -316,7 +317,6 @@ namespace XHWK.WKTool
316 317
             Console.WriteLine(@"初始化APP");
317 318
             LogHelper.InitLog4Net();
318 319
             myloading = new LoadDialog();
319
-            StopSameProcess();
320 320
             Killffmpeg();
321 321
             try
322 322
             {
@@ -379,30 +379,31 @@ namespace XHWK.WKTool
379 379
 
380 380
         #region 杀死已存在的进程
381 381
 
382
-        /// <summary>
383
-        /// 结束已运行的程序
384
-        /// </summary>
385
-        private static void StopSameProcess()
382
+        [DllImport("User32.dll")]
383
+        private static extern int FindWindow(string className, string windowName);
384
+
385
+        [DllImport("user32.dll")]
386
+        public static extern bool SetForegroundWindow(int hWnd);
387
+
388
+        private static void CheckProcess()
386 389
         {
390
+            Console.WriteLine(@"程序启动");
387 391
             Process current = Process.GetCurrentProcess();
388
-            Process[] processList = Process.GetProcesses();
389
-            foreach (Process process in processList)
392
+            //获取欲启动进程名
393
+            string strProcessName = Process.GetCurrentProcess().ProcessName;
394
+            var processList = Process.GetProcessesByName(strProcessName);
395
+            if (processList.Length <= 1)
390 396
             {
391
-                if (process.ProcessName.ToUpper() == "星火微课")
392
-                {
393
-                    if (process.Id != current.Id) //忽略当前进程
394
-                    {
395
-                        try
396
-                        {
397
-                            process.Kill(); //结束进程
398
-                        }
399
-                        catch (Exception)
400
-                        {
401
-                            // ignored
402
-                        }
403
-                    }
404
-                }
397
+                return;
398
+            }
399
+            MessageWindow.Show("当前程序已在运行,请勿重复运行。");
400
+            foreach (var process in processList)
401
+            {
402
+                if (process.Id == current.Id) continue;
403
+                int hWnd = FindWindow(null, process.MainWindowTitle);
404
+                SetForegroundWindow(hWnd);
405 405
             }
406
+            Environment.Exit(1); //退出新打开的程序
406 407
         }
407 408
 
408 409
         /// <summary>
@@ -693,6 +694,7 @@ namespace XHWK.WKTool
693 694
         {
694 695
             RegisterEvents();
695 696
             base.OnStartup(e);
697
+            CheckProcess();
696 698
         }
697 699
     }
698 700
 }

+ 1
- 1
星火微课/星火微课-正式.iss Ver arquivo

@@ -3,7 +3,7 @@
3 3
 
4 4
 #define MyAppName "星火微课"  
5 5
 #define MyAppDir "xhwk"
6
-#define MyAppVersion "3.9.7"
6
+#define MyAppVersion "3.9.8"
7 7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8 8
 #define MyAppURL "http://www.xhkjedu.com/"
9 9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

+ 1
- 1
星火微课/星火微课-测试.iss Ver arquivo

@@ -3,7 +3,7 @@
3 3
 
4 4
 #define MyAppName "星火微课测试版"  
5 5
 #define MyAppDir "xhwk_test"
6
-#define MyAppVersion "3.9.7"
6
+#define MyAppVersion "3.9.8"
7 7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8 8
 #define MyAppURL "http://www.xhkjedu.com/"
9 9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

Carregando…
Cancelar
Salvar