DriveDetector.cs

(开头部分) 9KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Test.TestCase
{
    class DriveDetector
    {
        /// <summary>
        /// 设备插入事件
        /// </summary>
        public event EventHandler<DriveDectctorEventArgs> DeviceArrived = null;
        /// <summary>
        /// 设备拔出事件
        /// </summary>
        public event EventHandler<DriveDectctorEventArgs> DeviceRemoved = null;
        /// <summary>
        /// 消息处理(HwndSourceHook委托的签名)
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="msg"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <param name="handled"></param>
        /// <returns></returns>
        public IntPtr WndProc(
            IntPtr hwnd,
            int msg,
            IntPtr wParam,
            IntPtr lParam)
        {
            if (msg == NativeConstants.WM_DEVICECHANGE)
            {
#warning USB设备检测目前只支持32位系统)
                switch (wParam.ToInt32())
                {
                    case NativeConstants.DBT_DEVICEARRIVAL:
                        {
                            var devType = Marshal.ReadInt32(lParam, 4);
                            if (devType == NativeConstants.DBT_DEVTYP_VOLUME)
                            {
                                var drive = GetDrive(lParam);
                                if (DeviceArrived != null)
                                {
                                    var args = new DriveDectctorEventArgs(drive);
                                    DeviceArrived(this, args); //触发设备插入事件
                                }
                            }
                        }
                        break;
                    case NativeConstants.DBT_DEVICEREMOVECOMPLETE:
                        {
                            var devType = Marshal.ReadInt32(lParam, 4);
                            if (devType == NativeConstants.DBT_DEVTYP_VOLUME)
                            {
                                var drive = GetDrive(lParam);
后面还有 203 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。