#NoEnv
#Persistent
#SingleInstance Force
SetBatchLines -1

OnMessage(0x0219, "WM_DEVICECHANGE")

WM_DEVICECHANGE(wParam, lParam) {
    static init := OnMessage(0x0219, "WM_DEVICECHANGE")
    if (wParam = 0x8000) || (wParam = 0x8004) && ((NumGet(lParam+4, "uint")) = 0x2) {
        i := 0, mask := NumGet(lParam+12, "uint")
        while (mask > 1) && (++i < 0x1A)
            mask >>= 1
        DeviceChangeInfo(Chr(0x41 + i) ":\", wParam)
    }
}

DeviceChangeInfo(device, state) {
    MsgBox, 0x40, % "Device Change", % device " " ((state = 0x8000) ? "plugged in" : (state = 0x8004) ? "is removed" : ""), 2
}

/*
https://msdn.microsoft.com/en-us/library/aa363480(v=vs.85).aspx    WM_DEVICECHANGE message
https://msdn.microsoft.com/en-us/library/aa363205(v=vs.85).aspx    DBT_DEVICEARRIVAL event
https://msdn.microsoft.com/en-us/library/aa363208(v=vs.85).aspx    DBT_DEVICEREMOVECOMPLETE event
https://msdn.microsoft.com/en-us/library/aa363246(v=vs.85).aspx    DEV_BROADCAST_HDR structure
https://msdn.microsoft.com/en-us/library/aa363249(v=vs.85).aspx    DEV_BROADCAST_VOLUME structure
*/

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。