Browse Source

add baseform

liuyuqi-dellpc 7 months ago
parent
commit
ba52e296a0

+ 14 - 0
README.md

@@ -0,0 +1,14 @@
+# TaskbarGroups
+
+任务栏分组
+
+## Develop
+
+```
+
+```
+
+## Reference
+
+[TaskbarGroups](https://github.com/chimuelo872/TaskbarGroups)
+

+ 10 - 2
TaskbarGroups/Form1.Designer.cs → TaskbarGroups/Pages/frmMain.Designer.cs

@@ -1,7 +1,7 @@
 
 namespace TaskbarGroups
 {
-    partial class Form1
+    partial class frmMain
     {
         /// <summary>
         /// Required designer variable.
@@ -29,10 +29,18 @@ namespace TaskbarGroups
         /// </summary>
         private void InitializeComponent()
         {
-            this.components = new System.ComponentModel.Container();
+            this.SuspendLayout();
+            // 
+            // frmMain
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(800, 450);
+            this.Name = "frmMain";
             this.Text = "Form1";
+            this.Load += new System.EventHandler(this.frmMain_Load);
+            this.ResumeLayout(false);
+
         }
 
         #endregion

+ 10 - 2
TaskbarGroups/Form1.cs → TaskbarGroups/Pages/frmMain.cs

@@ -10,11 +10,19 @@ using System.Windows.Forms;
 
 namespace TaskbarGroups
 {
-    public partial class Form1 : Form
+    public partial class frmMain : Form
     {
-        public Form1()
+        private readonly string passedDirec;
+        //public List<ucShortcut> ControlList;
+        
+        public frmMain()
         {
             InitializeComponent();
         }
+
+        private void frmMain_Load(object sender, EventArgs e)
+        {
+
+        }
     }
 }

+ 120 - 0
TaskbarGroups/Pages/frmMain.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 48 - 3
TaskbarGroups/Program.cs

@@ -3,20 +3,65 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using System.Runtime.InteropServices;
+using System.Reflection;
+using System.Diagnostics;
+using System.Threading;
 
 namespace TaskbarGroups
 {
     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 Form1());
+            // 只运行一个实例
+            Process instance = RunningInstance();
+            if ( instance ==null){
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+                Application.Run(new frmMain());
+            }else
+            {
+                // todo 已启动则打开form
+                //Application.EnableVisualStyles();
+            }
+        }
+
+        /// <summary>
+        /// 检测是否已经启动了一个Application实例
+        /// </summary>
+        /// <returns>返回进程id,没有启动返回null</returns>
+        private static Process RunningInstance()
+        {
+            Process current = Process.GetCurrentProcess();
+            Process[] processes = Process.GetProcessesByName(current.ProcessName);
+            // 遍历正在有相同名字运行的例程 
+            foreach (Process process in processes)
+            {
+                // 忽略现有的例程 
+                if (process.Id != current.Id)
+                {
+                    // 确保例程从EXE文件运行 
+                    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
+                    {
+                        // 返回另一个例程实例 
+                        return process;
+                    }
+                }
+            }
+            // 没有其它的例程,返回null 
+            return null;
         }
     }
 }

+ 17 - 3
TaskbarGroups/TaskbarGroups.csproj

@@ -46,14 +46,23 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Form1.cs">
+    <Compile Include="Pages\frmMain.cs">
       <SubType>Form</SubType>
     </Compile>
-    <Compile Include="Form1.Designer.cs">
-      <DependentUpon>Form1.cs</DependentUpon>
+    <Compile Include="Pages\frmMain.Designer.cs">
+      <DependentUpon>frmMain.cs</DependentUpon>
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Views\BaseControl.cs">
+      <SubType>UserControl</SubType>
+    </Compile>
+    <Compile Include="Views\BaseForm.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <EmbeddedResource Include="Pages\frmMain.resx">
+      <DependentUpon>frmMain.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -76,5 +85,10 @@
   <ItemGroup>
     <None Include="App.config" />
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Models\" />
+    <Folder Include="NativeMethods\" />
+    <Folder Include="Utils\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 62 - 0
TaskbarGroups/Views/BaseControl.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace TaskbarGroups.Views
+{
+    public partial class BaseControl : UserControl
+    {
+        public BaseControl()
+        {
+            InitializeComponent();
+        }
+
+
+        private void InitializeComponent()
+        {
+
+        }
+
+
+        private void BaseControl_Load(object sender, EventArgs e)
+        {
+
+        }
+
+        /// <summary>
+        /// Control 之间跳转
+        /// </summary>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        internal static Form Go(Type type)
+        {
+            Form currentControl = null;
+            foreach (Form controlItem in Program.formList)
+            {
+                if (controlItem.GetType() == type)
+                {
+                    currentControl = controlItem;
+                    currentControl.Activate();
+                    break;
+                }
+
+            }
+            if (currentControl == null)
+            {
+                object obj = Activator.CreateInstance(type);
+                if (obj is Form)
+                {
+                    currentControl = obj as Form;
+                    currentControl.Show();
+                }
+            }
+            return currentControl;
+        }
+    }
+}

+ 93 - 0
TaskbarGroups/Views/BaseForm.cs

@@ -0,0 +1,93 @@
+using System;
+using System.Windows.Forms;
+
+namespace TaskbarGroups.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;
+        }
+    }
+}