Browse Source

增加 BaseForm.cs

liuyuqi-dellpc 1 year ago
parent
commit
f749ef1fa2

+ 2 - 1
Android/app/src/main/java/me/yoqi/android/wifiqrcode/MainActivity.java

@@ -10,9 +10,10 @@ public class MainActivity extends AppCompatActivity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
+        initView();
     }
     private void initView(){
-
+        findViewById(R.id.btn);
     }
     private void initData(){
 

+ 2 - 1
Python/wifi_qrcode.py

@@ -4,7 +4,8 @@
 @Contact :   liuyuqi.gov@msn.cn
 @Time    :   2021/01/28 20:47:55
 @License :   Copyright © 2021 liuyuqi.gov@msn.cn. All Rights Reserved. Licensed under the Apache 2.0 license.
-@Desc    :   wifi 转化为 QRcode 方便扫码连接wifi。
+@Desc    :   wifi 转化为 QRcode 方便扫码连接wifi+
+
 '''
 
 import re,os,sys

+ 35 - 0
README_ZH.md

@@ -0,0 +1,35 @@
+# WifiQRCode
+
+wifi share with QRCode.
+
+## preview
+
+win:
+
+![](Docs/screenshot/BaiduHi_2021-3-24_11-10-53.png)
+
+android:
+
+![](Docs/screenshot/Android.png)
+
+# Develop
+
+## Python
+
+```
+virtualenv -p /opt/python/3.7.4/bin/python3 venv
+source venv/bin/activate
+pip install -r requirements.txt
+
+python wifi_qrcode.py
+```
+
+## Contributing
+
+If you are interested in fixing issues and contributing directly to the code base, please see the document [How to Contribute](CONTRIBUTING.md).
+
+## License
+
+Copyright (c) 2021 [liuyuqi.gov@msn.cn](mailto:liuyuqi.gov@msn.cn). All rights reserved.
+
+Licensed under the [Apache 2.0](LICENSE.md) license.

+ 0 - 0
Win/ShareWifi/Views/AboutMe.Designer.cs → Win/ShareWifi/Pages/Control/AboutMe.Designer.cs


+ 0 - 0
Win/ShareWifi/Views/AboutMe.cs → Win/ShareWifi/Pages/Control/AboutMe.cs


+ 0 - 0
Win/ShareWifi/Views/AboutMe.resx → Win/ShareWifi/Pages/Control/AboutMe.resx


+ 41 - 3
Win/ShareWifi/Program.cs

@@ -1,6 +1,8 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
+using System.Reflection;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 
@@ -8,15 +10,51 @@ namespace ShareWifi
 {
     static class Program
     {
+        /// <summary>
+        ///  全局窗体List,便于相互跳转
+        /// </summary>
+        public static List<Form> formList = new List<Form>();
+
         /// <summary>
         /// The main entry point for the application.
         /// </summary>
         [STAThread]
         static void Main()
         {
-            Application.EnableVisualStyles();
-            Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new MainForm());
+            Process instance = RunningInstance();
+            if (instance == null)
+            {
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+                Application.Run(new MainForm());
+            }
+            else
+            {
+                // MessageBox.Show("程序已经在运行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
+            }
+        }
+
+
+        public static Process RunningInstance()
+        {
+            // 获取当前活动的进程
+            Process current = Process.GetCurrentProcess();
+            // 获取当前本地计算机上指定的进程名称的所有进程
+            Process[] processes = Process.GetProcessesByName(current.ProcessName);
+            foreach (Process process in processes)
+            {
+                // 忽略当前进程
+                if (process.Id != current.Id)
+                {
+                    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
+                    {
+                        return process;
+                    }
+                }
+            }
+
+            // 如果没有其他同名进程存在,则返回 null
+            return null;
         }
     }
 }

+ 6 - 3
Win/ShareWifi/ShareWifi.csproj

@@ -65,12 +65,15 @@
     <Compile Include="Utils\Net\WifiUtils.cs" />
     <Compile Include="Utils\QRUtils.cs" />
     <Compile Include="Utils\Shell.cs" />
-    <Compile Include="Views\AboutMe.cs">
+    <Compile Include="Pages\Control\AboutMe.cs">
       <SubType>UserControl</SubType>
     </Compile>
-    <Compile Include="Views\AboutMe.Designer.cs">
+    <Compile Include="Pages\Control\AboutMe.Designer.cs">
       <DependentUpon>AboutMe.cs</DependentUpon>
     </Compile>
+    <Compile Include="Views\BaseForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
     <Compile Include="Views\Components\SimpleAlert.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -96,7 +99,7 @@
       <DependentUpon>Resources.resx</DependentUpon>
       <DesignTime>True</DesignTime>
     </Compile>
-    <EmbeddedResource Include="Views\AboutMe.resx">
+    <EmbeddedResource Include="Pages\Control\AboutMe.resx">
       <DependentUpon>AboutMe.cs</DependentUpon>
     </EmbeddedResource>
     <EmbeddedResource Include="Views\Components\SimpleAlert.resx">

+ 95 - 0
Win/ShareWifi/Views/BaseForm.cs

@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ShareWifi.Views
+{
+    /// <summary>
+    /// Form 基类
+    /// </summary>
+    public partial class BaseForm : Form
+    {
+        public BaseForm()
+        {
+            this.Load += new EventHandler(BaseForm_Load);
+            this.FormClosed += new FormClosedEventHandler(BaseForm_FormClosed);
+            InitializeComponent();
+        }
+        public void BaseForm_Load(object sender, EventArgs e)
+        {
+            Program.formList.Add(this);
+        }
+        public void BaseForm_FormClosed(object sender, FormClosedEventArgs e)
+        {
+            Program.formList.Remove(this);
+        }
+
+        private void InitializeComponent()
+        {
+            this.SuspendLayout();
+            // 
+            // BaseForm
+            // 
+            this.ClientSize = new System.Drawing.Size(1350, 729);
+            this.Name = "BaseForm";
+            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
+            this.DoubleClick += new System.EventHandler(this.BaseForm_DoubleClick);
+            this.ResumeLayout(false);
+
+        }
+        /// <summary>
+        /// 双击关闭窗体
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void BaseForm_DoubleClick(object sender, EventArgs e)
+        {
+            Application.Exit();
+        }
+        /// <summary>
+        /// 解决winform刚启动的时候,由于picture 太多闪屏问题
+        /// </summary>
+        protected override CreateParams CreateParams
+        {
+            get
+            {
+                CreateParams cp = base.CreateParams;
+                cp.ExStyle |= 0x02000000;
+                return cp;
+            }
+        }
+
+        /// <summary>
+        /// Form之间跳转
+        /// </summary>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        internal static Form Go(Type type)
+        {
+            Form currentForm = null;
+            foreach (Form formItem in Program.formList)
+            {
+                if (formItem.GetType() == type)
+                {
+                    currentForm = formItem;
+                    currentForm.Activate();
+                    break;
+                }
+
+            }
+            if (currentForm == null)
+            {
+                object obj = Activator.CreateInstance(type);
+                if (obj is Form)
+                {
+                    currentForm = obj as Form;
+                    currentForm.Show();
+                }
+            }
+            return currentForm;
+        }
+    }
+}