Hello all!
Does anyone know how to get notification, when cd-rom tray opens'?
I need to write a programm which closes cd-rom tray if it's open for a certain period of time, but I can't determine when cd-rom tray opens...
Posted on 2003-10-30 11:48:01 by InfraRed
It seem's to me that it isn't possible to get such notification if no media was present in drive:(
Posted on 2003-11-04 08:58:19 by InfraRed
Afternoon, InfraRed.

I think it's quite dangerous to automatically close the cdrom tray. If a user is currently in the process of putting a cd on it, the cd would end up scratched quite deeply:( .

If you *really* wanted to have this feature though, you could just have your program count the time and close the tray. If the tray was already closed, nothing would happen. If the tray was already opened, then the set period of time would've elapsed.

The only two scenarios I can see where this would be useful is:
1) as a fun "trick" to freak out the user (i.e. open/close the tray randomly), or
2) you've got a robotic arm and want a program to automatically change the music cd.:alright:

Cheers,
Scronty
Posted on 2003-11-04 15:30:53 by Scronty
I see a third: for setups, ejecting Cd when next CD is to be changed (iirc some games and setups use it, it's god since oyu then know you wont crash it when opening the CD tray).

what happens when a CD "get's caught" by the tray is that the tray stops with the CD half in, you panik and by instingct pushes the open button -- based on a real life experience, the CD survied (w/o scratches, my fingers got a litte scratch thought).
Posted on 2003-11-04 17:03:24 by scientica
I have also seen some apps that automatically close the CD tray when shutting down the system. I wouldn't use such thing, but some people does it seems. :grin:
Posted on 2003-11-04 17:09:26 by QvasiModo
But how can I know when someone insert a cd in the cdrom drive?
Posted on 2003-11-19 14:02:50 by greenant
greenant
...

.const
szArrived db 'Arrived', 0
szRemoved db 'Removed', 0

DBT_DEVICEARRIVAL = 8000h
DBT_DEVICEREMOVECOMPLETE = 8004h
DBT_DEVTYP_VOLUME = 2

DEV_BROADCAST_HDR struc
dbch_size DWORD ?
dbch_devicetype DWORD ?
dbch_reserved DWORD ?
DEV_BROADCAST_HDR ends

DEV_BROADCAST_VOLUME struc
dbcv_size DWORD ?
dbcv_devicetype DWORD ?
dbcv_reserved DWORD ?
dbcv_unitmask DWORD ?
dbcv_flags WORD ?
WORD ? ; __alignmentDummy
DEV_BROADCAST_VOLUME ends

.code
even
DriveFromMask proc dwMask:DWORD
mov ecx,dwMask
xor eax,eax
mov al,'A'
.while (al <= 'Z') && (ecx != 0)
.break .if (ecx & 1)
shr ecx,1
inc al
.endw
.if al > 'Z'
xor al,al
.else
mov ah,':'
.endif
ret
DriveFromMask endp


even
wndproc proc uses ebx edi esi, hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL buf:DWORD
...
.elseif uMsg == WM_DEVICECHANGE
mov eax,lParam
mov eax,(DEV_BROADCAST_HDR ptr [eax]).dbch_devicetype
.if (wParam == DBT_DEVICEARRIVAL) && (eax == DBT_DEVTYP_VOLUME)
mov eax,lParam
invoke DriveFromMask, (DEV_BROADCAST_VOLUME ptr [eax]).dbcv_unitmask
.if eax != 0
mov buf,eax
invoke GetDriveType, addr buf
.if eax == DRIVE_CDROM
invoke MessageBox, hWnd, addr buf, offset szArrived, MB_OK
.endif
.endif
.elseif (wParam == DBT_DEVICEREMOVECOMPLETE) && (eax == DBT_DEVTYP_VOLUME)
mov eax,lParam
invoke DriveFromMask, (DEV_BROADCAST_VOLUME ptr [eax]).dbcv_unitmask
.if eax != 0
mov buf,eax
invoke GetDriveType, addr buf
.if eax == DRIVE_CDROM
invoke MessageBox, hWnd, addr buf, offset szRemoved, MB_OK
.endif
.endif
.endif
mov eax,TRUE

.elseif uMsg == ...
Posted on 2003-11-20 00:26:32 by P2M
I will try
Posted on 2003-11-20 05:25:22 by greenant