Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
USB drive
#6
Assign this toolbar hook function to a toolbar that is open all time and it will notify when a drive is inserted and removed. Also works with CD and other. Function name is not important.

Code:
Copy      Help
;/
function# hWnd message wParam lParam

def WM_DEVICECHANGE  0x219
def DBT_DEVICEARRIVAL 0x8000
def DBT_DEVICEREMOVECOMPLETE  0x8004
def DBT_DEVTYP_VOLUME 0x2

type DEV_BROADCAST_VOLUME dbcv_size dbcv_devicetype dbcv_reserved dbcv_unitmask @dbcv_flags

sel message
,case WM_DEVICECHANGE
,sel(wParam) case [DBT_DEVICEARRIVAL,DBT_DEVICEREMOVECOMPLETE] case else ret
,DEV_BROADCAST_VOLUME* v=+lParam
,if(v.dbcv_devicetype!=DBT_DEVTYP_VOLUME) ret
,int i j=v.dbcv_unitmask
,for(i 0 26) if(j&1) break; else j>>1
,i+'A'
,sel wParam
,,case DBT_DEVICEARRIVAL
,,out "inserted %c" i
,,;if(i='E') mac "OnInserted"
,,
,,case DBT_DEVICEREMOVECOMPLETE
,,out "removed %c" i
,,;if(i='E') mac "OnRemoved"
,,


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)