éjecter un lecteur cd à partir d'un programme

mat85fcna Messages postés 3 Date d'inscription samedi 5 février 2005 Statut Membre Dernière intervention 6 avril 2005 - 5 févr. 2005 à 11:33
mat85fcna Messages postés 3 Date d'inscription samedi 5 février 2005 Statut Membre Dernière intervention 6 avril 2005 - 6 avril 2005 à 20:51
J'aimerai bien avoir la ligne de code permettant d'ejecter un lecteur cd, svp c pour l'école

9 réponses

cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 20
5 févr. 2005 à 11:53
Salut,

Dans un form avec 2 boutons (Ouvrir_CD et Fermer_CD, tu colles ça :

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Private Sub Ouvrir_CD_Click()
mciSendString "set CDAudio door open", 0, 0, Me.hWnd
End Sub

Private Sub Fermer_CD_Click()
mciSendString "set CDAudio door closed", 0, 0, Me.hWnd
End Sub

Cordialement, CanisLupus
0
cs_algori Messages postés 868 Date d'inscription dimanche 26 décembre 2004 Statut Membre Dernière intervention 26 février 2008 1
5 févr. 2005 à 14:36
Si tu veux en VBScript :

Set cd = CreateObject("WMPlayer.OCX.7")
Set cds = cd.cdromCollection
cds.Item(0).Eject //Tu peux choisir quel lecteur tu veux sortir : 0,1...
WScript.Sleep 1000
MsgBox "Une fois le CD-Rom mis, veuillez cliquer sur OK pour une fermeture automatique.",vbOkOnly,"MISE CD-ROM"
cds.Item(0).Eject

Tchao !
@++
0
cqui789 Messages postés 261 Date d'inscription jeudi 13 janvier 2005 Statut Membre Dernière intervention 18 mai 2009 3
5 févr. 2005 à 19:45
Tres bonnes reponses, qui vont trouver une bonne place dans ma bibliotheque perso, mais...



CanisLupus: comment fait-on avec ton code pour choisir le lecteur si on en a plusieur?

algori : Comment tu fait si tu veux un bouton pour ouvrir et un pour fermer
0
cqui789 Messages postés 261 Date d'inscription jeudi 13 janvier 2005 Statut Membre Dernière intervention 18 mai 2009 3
5 févr. 2005 à 19:54
J'ai presque repondu a ma question:

Reste a connetre l'etat du lecteur (ouvert, ferme, en cours de travail...) quelqu'un connet ca?




Option Explicit

Private cd As Object, cds As Object



Private Sub Command1_Click(Index As Integer)

cds.Item(Index).eject

End Sub



Private Sub Form_Load()

Set cd = CreateObject("WMPlayer.OCX.7")

Set cds = cd.cdromCollection

End Sub




P.S. mat85fcna : merci de poser une question que je voulait aussi poser...
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
6 févr. 2005 à 13:27
Exemple en C, vous vous debrouillerez pour le passer en VB, pas mon rayon:
void CdOpenCloseDrive()
{
MCI_OPEN_PARMS op;
DWORD flags = MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE | MCI_OPEN_ELEMENT; op.dwCallback 0; op.lpstrAlias 0;
szCdName[0] = chCds[lPos];
op.wDeviceID = 0;
op.lpstrDeviceType = (LPCSTR) MCI_DEVTYPE_CD_AUDIO;
op.lpstrElementName = szCdName;
if(!mciSendCommand(0,MCI_OPEN,flags,(unsigned long)&op)) {
if(bOpenDrive) mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0);
else mciSendCommand(op.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
mciSendCommand(op.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
}
}

la fonction peut ouvrir ou fermer le lecteur choisi.

ciao...
BruNews, MVP VC++
0
cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 20
6 févr. 2005 à 14:14
cqui789, avec "mon" code, our ouvrir u fermer un lecteur de ton choix c'est :

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Public Sub Ouvrir_CD(LettreCD As srting)


mciSendString "open " & LettreCD & " type cdaudio alias cdaudio", vbNullString, 0, 0
mciSendString "set CDAudio door open", 0, 0, 0
mciSendString "close cdaudio", vbNullString, 0, 0


End Sub
Public Sub Fermer_CD(LettreCD As srting)


mciSendString "open " & LettreCD & " type cdaudio alias cdaudio", vbNullString, 0, 0
mciSendString "set CDAudio door closed", 0, 0, 0
mciSendString "close cdaudio", vbNullString, 0, 0


End Sub

Et même, pour tester s'il y a un cd dans le lecteur :


Public Function CD_Present(LettreCD As String) As Boolean
Dim r As String * 6

mciSendString "open " & LettreCD & " type cdaudio alias cdaudio", vbNullString, 0, 0
mciSendString "status cdaudio media present", r, Len(r), 0
mciSendString "close cdaudio", vbNullString, 0, 0

CD_Present = Split(r, Chr$(0))(0)

End Function

Sinon, tu as une api à voir à cette adresse :

http://www.mentalis.org/apilist/DeviceIoControl.shtml

Cordialement, CanisLupus
0
cs_CanisLupus Messages postés 3757 Date d'inscription mardi 23 septembre 2003 Statut Membre Dernière intervention 13 mars 2006 20
6 févr. 2005 à 14:19
Ou alors un code ici-même :

http://www.vbfrance.com/code.aspx?id=16978

Cordialement, CanisLupus
0
cqui789 Messages postés 261 Date d'inscription jeudi 13 janvier 2005 Statut Membre Dernière intervention 18 mai 2009 3
6 févr. 2005 à 23:13
Merci pour les renseignements
0
mat85fcna Messages postés 3 Date d'inscription samedi 5 février 2005 Statut Membre Dernière intervention 6 avril 2005
6 avril 2005 à 20:51
merci pour tout
0
Rejoignez-nous