Open/close CD tray

within MywebBrowser

Page 1 of 1

4 Replies - 12602 Views - Last Post: 14 April 2010 - 11:43 AM Rate Topic: -----

#4 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Re: Open/close CD tray

Post icon  Posted 04 December 2008 - 05:07 PM

Hi,
I added two buttons the ToolStrip of myBrowser to be able to open and close the CD tray, it works great, but now I would like to be able to open and close the CD tray by using only one button, to open and close it, can be done?
Thanks!

Public Class Browser
	'this is declaration to open and close the cdrom tray
	Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
	   (ByVal lpszCommand As String, ByVal lpszReturnString As String, _
	   ByVal cchReturnLength As Long, ByVal hwndCallback As Long) As Long

 'To open cdrom tray'
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
		mciSendString("set CDAudio door open", 0, 0, 0)
	End Sub

'To close the cdrom tray'
	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
		mciSendString("set CDAudio door closed", 0, 0, 0)
	End Sub


Was This Post Helpful? 1

#5 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Open/close CD tray

Posted 04 December 2008 - 06:21 PM

An easy way is just to create a global boolean variable that will say if the cd tray is open (true) of if it is closed (false). Then, you could use a simple if statement
Dim CDTrayOpen As Boolean = False 'this is global

'this is in the click event
If CDTrayOpen Then
    'Close CD tray
    mciSendString("set CDAudio door closed", 0, 0, 0)
    CDTrayOpen = False
Else
    'Open CD tray
    mciSendString("set CDAudio door open", 0, 0, 0)
    CDTrayOpen = True
End If


Was This Post Helpful? 1

#6 KJc  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 11-November 08

Re: Open/close CD tray

Posted 05 December 2008 - 02:13 AM

View Postjacobjordan, on 4 Dec, 2008 - 05:21 PM, said:

An easy way is just to create a global boolean variable that will say if the cd tray is open (true) of if it is closed (false). Then, you could use a simple if statement


Thanks for your help, it works like a charm :-)
now I understan the If then Else statement much better.
Was This Post Helpful? 0
  • +
  • -

#7 newbie_doloobie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-April 10

Re: Open/close CD tray

Posted 14 April 2010 - 11:31 AM

View PostKJc, on 04 December 2008 - 04:07 PM, said:

Hi,
I added two buttons the ToolStrip of myBrowser to be able to open and close the CD tray, it works great, but now I would like to be able to open and close the CD tray by using only one button, to open and close it, can be done?
Thanks!

Public Class Browser
	'this is declaration to open and close the cdrom tray
	Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
	   (ByVal lpszCommand As String, ByVal lpszReturnString As String, _
	   ByVal cchReturnLength As Long, ByVal hwndCallback As Long) As Long

 'To open cdrom tray'
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
		mciSendString("set CDAudio door open", 0, 0, 0)
	End Sub

'To close the cdrom tray'
	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
		mciSendString("set CDAudio door closed", 0, 0, 0)
	End Sub



Couldnt get to work! using vis studio 2008 just throws errors!
Was This Post Helpful? 0
  • +
  • -

#8 ZRonZ  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 206
  • Joined: 09-January 09

Re: Open/close CD tray

Posted 14 April 2010 - 11:43 AM

The code doesn't work, that's why KJc posted it. Look at the response from jacobjordan. It tells you how to fix it. I tried it in VS 2008 and it works.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1