VB Mania

Text Box: Previous Example
Text Box: Next Example
Text Box: VB-Mania Core

Eject and close the CD-ROM

Information:

mciSendString, in this example, will order the CD-ROM tray to be ejected or closed only by one click!

Illustration:

 

What You Need?:

One Form named Form1

Two CommandButtons: one named cmdEject (caption: "&Eject CD-ROM") the other named cmdEject (caption: "&Close CD-ROM")

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 cmdEject_Click()

mciSendString "Set CDAudio Door Open Wait", 0&, 0&, 0&

End Sub

 

Private Sub cmdClose_Click()

mciSendString "Set CDAudio Door Closed Wait", 0&, 0&, 0&

End Sub

Code:

 

Explanation:

CommandButton cmdEject will evoke the mciSendString to open the CD-ROM tray by using the string "Set CDAudio Door Open Wait" whereas CommandButton cmdClose will close it using the string "Set CDAudio Door Closed Wait" in its parameter.

Hint:

· To fulfill the widespread use of the useful mciSendString function, I’m planning to dedicate a fully whole section about it.

VB-Pedia:

· Go back to mciSendString section

Wait for the update… Coming Soon...

Sponsored Links

Google
 
Web vbmania2006.brinkster.net
planet-source-code.com support.microsoft.com