A
Arkane
Guest
This is a really old source to my first Visual Basic program, it opens and closes the CD drive.
That is just the code to my first program, a more simple way is to use Visual Basic's MMControl. Put one on to a form, add a command button and set these properties:
Do not change the controls' names.
Set MMControl1's DeviceType to CDAudio.
Set MMControl1's EjectEnabled to True
Feedback is welcomed (as always), suggestions will NOT be taken into consideration since this is old and a un-used program, this obviously cant be used on laptops by the way.
Code:
Option Base 1
Public 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
Sub main()
' CD Open/Close Program
' -Arkane
' [email protected]
Dim Now As String
Dim a(2) As String
a(1) = "set cdaudio door open"
a(2) = "set cdaudio door closed"
total = 1 'Set this to the number of cycles you want it to undergo
For i = 1 To (total * 2)
If Int(i / 2) = i / 2 Then
Now = vbString(a(2), 0)
Else
Now = vbString(a(1), 0)
End If
Next i
End Sub
Function vbString(ByVal Command As String, ByVal hWnd As Long) As String
Dim Buff As String
Dim dwR As Long
Buff = Space$(100) ' Create a buffer
dwR = mciSendString(Command, ByVal Buff, Len(Buff), hWnd)
vbString = Buff
End Function
That is just the code to my first program, a more simple way is to use Visual Basic's MMControl. Put one on to a form, add a command button and set these properties:
Do not change the controls' names.
Set MMControl1's DeviceType to CDAudio.
Set MMControl1's EjectEnabled to True
Code:
Private Sub Command1_Click()
MMControl1.Command = "Eject"
End Sub
Private Sub Form_Load()
MMControl1.Command = "Open"
End Sub
Feedback is welcomed (as always), suggestions will NOT be taken into consideration since this is old and a un-used program, this obviously cant be used on laptops by the way.


