Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 149,025 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,086 people online right now. Registration is fast and FREE... Join Now!





Open/Close your CD-Drive door.

Shows a Simple way to Open and Close your CD-Drive.

Submitted By: born2c0de
Actions:
Rating:
Views: 16,893

Language: Visual Basic

Last Modified: July 1, 2008

Snippet


  1. 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
  2.  
  3. Function CDDriveOperation(ByVal Command As String, ByVal hWnd As Long) As String
  4.     Dim Buff As String
  5.     Dim dwR As Long
  6.     Buff = Space$(100) ' Create a buffer
  7.     dwR = mciSendString(Command, ByVal Buff, Len(Buff), hWnd)
  8.     CDDriveOperation = Buff
  9. End Function
  10.  
  11. 'Call this Sub to Close the CD Door
  12. Private Sub CloseCDDoor()
  13.     Dim ret As String
  14.     ret = CDDriveOperation("set cdaudio door closed", 0)
  15. End Sub
  16.  
  17. ' Call this Sub to Open the CD Door
  18. Private Sub OpenCDDoor()
  19.     Dim ret As String
  20.     ret = CDDriveOperation("set cdaudio door open", 0)
  21. End Sub
  22.  
  23.  

Copy & Paste


Comments


carissamae 2008-02-14 00:57:25

can u pls ellaborate plsss

ronzam2002 2008-07-01 20:09:09

Can you give us an instuction how to use your program..!

born2c0de 2008-07-01 23:34:47

I guess it was a bit difficult to grasp and so I have simplified the code. All you have to do now is call CloseCDDoor() or OpenCDDoor() to close and open the CD drive door respectively.

ronzam2002 2008-09-06 02:39:43

What are tools did you use?


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month