Form1.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using ControlVolume.Views;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace ControlVolume
  13. {
  14. public partial class Form1 : Form
  15. {
  16. [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  17. static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
  18. const uint WM_APPCOMMAND = 0x319;
  19. const uint APPCOMMAND_VOLUME_UP = 0x0a;
  20. const uint APPCOMMAND_VOLUME_DOWN = 0x09;
  21. const uint APPCOMMAND_VOLUME_MUTE = 0x08;
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. }
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
  29. }
  30. private void button2_Click(object sender, EventArgs e)
  31. {
  32. //减音量
  33. SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
  34. }
  35. private void button3_Click(object sender, EventArgs e)
  36. {
  37. //静音
  38. SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
  39. }
  40. private void button4_Click(object sender, EventArgs e)
  41. {
  42. Method2 method2 = new Method2();
  43. method2.Show();
  44. }
  45. }
  46. }