📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DeviceApplication6
{
public partial class Form1 : Form
{
//对系统动态库的引用
//相关函数的声明
[DllImport("coredll.Dll")]
public static extern IntPtr FindWindow(string strclassName, string strWindowName);
[DllImport("coredll.Dll")]
public static extern int SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport("coredll.Dll")]
public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow);
public const int WM_CLOSE = 0x10;
[DllImport("coredll.Dll")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("coredll.Dll", EntryPoint = "CreateProcess", SetLastError = true)]
extern static int CreateProcess(string strImageName, string strCmdLine, IntPtr pProcessAttributes, IntPtr pThreadAttributes, int bInheritsHandle, int dwCreationFlags, IntPtr pEnvironment, IntPtr pCurrentDir, IntPtr bArray, ProcessInfo oProc);
public class ProcessInfo
{
public Int32 hProcess;
public Int32 hThread;
public Int32 ProcessID;
public Int32 ThreadID;
}
[DllImport("coredll.Dll")]
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, bool bRePaint);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
switch (listBox1.SelectedItem.ToString())
{
//判断选择的节目,初始化播放器
case "JAY":
ProcessInfo pi = new ProcessInfo();
CreateProcess("ceplayer.exe", @"\Window\List.mp3", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pi);
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
//窗体的关闭
IntPtr hwndce;
hwndce = FindWindow(null, "Media player");
SendMessage(hwndce, WM_CLOSE, 0, 0);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
//对播放器窗体的显示控制
IntPtr hwndce;
hwndce = FindWindow(null, "Media player");
SetWindowPos(hwndce, -1, 400, 0, 1024, 768, 0x1);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -