Browse Source

优化项目

liuyuqi-dellpc 7 months ago
parent
commit
8c6637d9f4

+ 6 - 5
ControlVolume/ControlVolume.csproj

@@ -46,11 +46,12 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Form1.cs">
+    <Compile Include="NativeMethods\User32.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" />
@@ -60,8 +61,8 @@
     <Compile Include="Views\Method2.Designer.cs">
       <DependentUpon>Method2.cs</DependentUpon>
     </Compile>
-    <EmbeddedResource Include="Form1.resx">
-      <DependentUpon>Form1.cs</DependentUpon>
+    <EmbeddedResource Include="Pages\frmMain.resx">
+      <DependentUpon>frmMain.cs</DependentUpon>
     </EmbeddedResource>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>

+ 16 - 0
ControlVolume/NativeMethods/User32.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ControlVolume.NativeMethods
+{
+    class User32
+    {
+        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
+
+    }
+}

+ 3 - 3
ControlVolume/Form1.Designer.cs → ControlVolume/Pages/frmMain.Designer.cs

@@ -1,6 +1,6 @@
 namespace ControlVolume
 {
-    partial class Form1
+    partial class frmMain
     {
         /// <summary>
         /// Required designer variable.
@@ -95,7 +95,7 @@
             this.button4.UseVisualStyleBackColor = true;
             this.button4.Click += new System.EventHandler(this.button4_Click);
             // 
-            // Form1
+            // frmMain
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@@ -106,7 +106,7 @@
             this.Controls.Add(this.lb_volume);
             this.Controls.Add(this.label1);
             this.Controls.Add(this.button1);
-            this.Name = "Form1";
+            this.Name = "frmMain";
             this.Text = "Form1";
             this.ResumeLayout(false);
             this.PerformLayout();

+ 7 - 16
ControlVolume/Form1.cs → ControlVolume/Pages/frmMain.cs

@@ -1,47 +1,38 @@
 using ControlVolume.Views;
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows.Forms;
+using ControlVolume.NativeMethods;
 
 namespace ControlVolume
 {
-    public partial class Form1 : Form
+    public partial class frmMain : Form
     {
-        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
-        static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
+
         const uint WM_APPCOMMAND = 0x319;
         const uint APPCOMMAND_VOLUME_UP = 0x0a;
         const uint APPCOMMAND_VOLUME_DOWN = 0x09;
         const uint APPCOMMAND_VOLUME_MUTE = 0x08;
 
-
-        public Form1()
+        public frmMain()
         {
             InitializeComponent();
         }
 
         private void button1_Click(object sender, EventArgs e)
         {
-            SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
+            User32.SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
         }
 
         private void button2_Click(object sender, EventArgs e)
         {
             //减音量
-            SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
+            User32.SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
         }
 
         private void button3_Click(object sender, EventArgs e)
         {
             //静音
-            SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
+            User32.SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
         }
 
         private void button4_Click(object sender, EventArgs e)

+ 0 - 0
ControlVolume/Form1.resx → ControlVolume/Pages/frmMain.resx


+ 1 - 1
ControlVolume/Program.cs

@@ -16,7 +16,7 @@ namespace ControlVolume
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new Form1());
+            Application.Run(new frmMain());
         }
     }
 }