using System.Runtime.InteropServices; namespace AudioWallpaper { using System; using System.Runtime.InteropServices; public static class Win32 { /// /// 查找指定类名和窗口名的窗口句柄。 /// /// 窗口类名 /// 窗口名称 /// 窗口句柄 [DllImport("user32.dll")] public static extern IntPtr FindWindow(string className, string winName); /// /// 向指定窗口发送消息。 /// /// 窗口句柄 /// 消息类型 /// 消息的附加信息 /// 消息的附加信息 /// 消息处理结果 [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hwnd, uint Msg, IntPtr wParam, IntPtr lParam); /// /// 向指定窗口发送消息,并设置超时。 /// /// 窗口句柄 /// 消息类型 /// 消息的附加信息 /// 消息的附加信息 /// 标志 /// 超时(毫秒) /// 结果指针 /// 消息处理结果 [DllImport("user32.dll")] public static extern IntPtr SendMessageTimeout(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam, uint fuFlage, uint timeout, IntPtr result); /// /// 枚举所有顶级窗口。 /// /// 回调函数,用于处理每个窗口 /// 用户自定义参数 /// 是否成功 [DllImport("user32.dll")] public static extern bool EnumWindows(EnumWindowsProc proc, IntPtr lParam); /// /// 窗口枚举回调委托。 /// /// 窗口句柄 /// 用户自定义参数 /// 是否继续枚举 public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam); /// /// 查找指定父窗口下的子窗口。 /// /// 父窗口句柄 /// 在此窗口之后查找 /// 窗口类名 /// 窗口名称 /// 子窗口句柄 [DllImport("user32.dll")] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string className, string winName); /// /// 显示或隐藏指定窗口。 /// /// 窗口句柄 /// 显示状态 /// 是否成功 [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow); /// /// 设置窗口的位置和大小。 /// /// 窗口句柄 /// 窗口在 Z 顺序中的位置 /// 新的 X 坐标 /// 新的 Y 坐标 /// 新的宽度 /// 新的高度 /// 标志 /// 是否成功 [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hwnd, IntPtr hhWndInserAfter, int x, int y, int cx, int cy, uint uFlags); /// /// 设置指定窗口的父窗口。 /// /// 窗口句柄 /// 新父窗口句柄 /// 新的窗口句柄 [DllImport("user32.dll")] public static extern IntPtr SetParent(IntPtr hwnd, IntPtr parentHwnd); /// /// 发送 APPBAR 消息。 /// /// 消息类型 /// APPBARDATA 结构的引用 /// 结果 [DllImport("shell32.dll")] public static extern uint SHAppBarMessage(uint dwMessage, ref APPBARDATA pData); /// /// 注册窗口消息。 /// /// 消息字符串 /// 消息标识 [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern uint RegisterWindowMessage(string lpString); /// /// APPBARDATA 结构用于 APPBAR 功能。 /// [StructLayout(LayoutKind.Sequential)] public struct APPBARDATA { public int cbSize; // 结构大小 public IntPtr hWnd; // APPBAR 窗口句柄 public uint uCallbackMessage; // 回调消息 public uint uEdge; // 边缘位置 public RECT rc; // 矩形区域 public int lParam; // 用户自定义参数 } /// /// 矩形结构。 /// [StructLayout(LayoutKind.Sequential)] public struct RECT { public int left; // 左边界 public int top; // 上边界 public int right; // 右边界 public int bottom; // 下边界 } } }