• 16 odgovora
  • 8.247 pregleda
VB kod za eject cd? 03.11.2004. u 09:18 · pre 267 meseci #1
moze li mi neko reci kod kojim se otvaraju vratanca cd odnosno kojim se cd ejectuje?
potreban mi je VB kod
Potpis
_-=amateur=-_
Re: VB kod za eject cd? 03.11.2004. u 09:27 · pre 267 meseci #2
Evo ti ovaj način:


Code:

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 Command1_Click()
On Error Resume Next
retvalue = mciSendString("set CDAudio door open", returnstring, 127, 0)
End Sub

Private Sub Command2_Click()
On Error Resume Next
retvalue = mciSendString("set CDAudio door closed", returnstring, 127, 0)
End Sub


[Ovu poruku je menjao VRKY dana 03.11.2004. u 13:04 GMT+1]
Re: VB kod za eject cd? 03.11.2004. u 09:40 · pre 267 meseci #3
Code:

'Example by Howard Henry Schlunder
' This example requires one command button (Command1)
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" (ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, _
ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const INVALID_HANDLE_VALUE = -1
Private Const OPEN_EXISTING = 3
Private Const FILE_FLAG_DELETE_ON_CLOSE = 67108864
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const IOCTL_STORAGE_EJECT_MEDIA = 2967560
Private Const VWIN32_DIOC_DOS_IOCTL = 1
 
Private Type DIOC_REGISTERS
  reg_EBX As Long
  reg_EDX As Long
  reg_ECX As Long
  reg_EAX As Long
  reg_EDI As Long
  reg_ESI As Long
  reg_Flags As Long
End Type
 
Private Sub Command1_Click()
Dim hDrive As Long, DummyReturnedBytes As Long
Dim EjectDrive As String, DriveLetterAndColon As String
Dim RawStuff As DIOC_REGISTERS
  EjectDrive = InputBox("Which drive shall we try to eject the media from?", "Eject Media")
  If Len(EjectDrive) Then 'Confirm the user didn't cancel
    DriveLetterAndColon = UCase(Left$(EjectDrive & ":", 2)) 'Make it all caps for easy interpretation
    If GetVersion >= 0 Then 'We are running Windows NT/2000
      hDrive = CreateFile("\\.\" & DriveLetterAndColon, GENERIC_READ Or GENERIC_WRITE, 0, ByVal 0, OPEN_EXISTING, 0, 0)
      If hDrive <> INVALID_HANDLE_VALUE Then
        'Eject media!
        Call DeviceIoControl(hDrive, IOCTL_STORAGE_EJECT_MEDIA, 0, 0, 0, 0, DummyReturnedBytes, ByVal 0)
        Call CloseHandle(hDrive)  'Clean up after ourselves
      End If
    Else  'We are running Win9x/Me
      hDrive = CreateFile("\\.\VWIN32", 0, 0, ByVal 0, 0, FILE_FLAG_DELETE_ON_CLOSE, 0)
      If hDrive <> INVALID_HANDLE_VALUE Then
        'Setup our raw registers to use Interrupt 21h Function 440Dh Minor Code 49h
        RawStuff.reg_EAX = &H440D   'The function to use
        RawStuff.reg_EBX = Asc(DriveLetterAndColon) - Asc("A") + 1 'The drive to do it on
        RawStuff.reg_ECX = &H49 Or &H800    
        'The minor code of the function in the low byte of the low word and the device category of 8 in the high byte of the low word
        'Eject media!
        Call DeviceIoControl(hDrive, VWIN32_DIOC_DOS_IOCTL, RawStuff, LenB(RawStuff), RawStuff, LenB(RawStuff), DummyReturnedBytes, ByVal 0)
        Call CloseHandle(hDrive)  'Clean up after ourselves
      End If
    End If
  End If
End Sub

Potpis
Blue Man Group
Re: VB kod za eject cd? 03.11.2004. u 09:47 · pre 267 meseci #4
ovo radi!
Hvala...
Potpis
_-=amateur=-_
Re: VB kod za eject cd? 03.11.2004. u 10:01 · pre 267 meseci #5
A što onaj moj kod ne radi? Možda ne radi zbog deklaracije jer sam ju razlamao da stane...
Re: VB kod za eject cd? 03.11.2004. u 10:23 · pre 267 meseci #6
Kada stavljas _ moras da stavis jedan space pre.
Potpis
Blue Man Group
Re: VB kod za eject cd? 03.11.2004. u 12:05 · pre 267 meseci #7
OK, izmjenjeno, sad bi onda trebalo šljakati...
Re: VB kod za eject cd? 11.11.2004. u 10:50 · pre 267 meseci #8
VRKY sto se tice tvog koda... on radi kod mene ali kada sam ga hteo poslati.... pali mi se antivirus koji kaze da je potencionaly unsafe...
postoji li kod koji to nece da pali av?
Potpis
_-=amateur=-_
Re: VB kod za eject cd? 23.01.2005. u 20:40 · pre 264 meseci #9
Mozda jos jedno malo pitanjce...

Ovaj prvi kod radi kada ga pokrenem iz VB6,
ali kada pokusam i napravim .exe tada ne radi!

Zasto?????
Potpis
Gogy
Re: VB kod za eject cd? 28.01.2005. u 21:38 · pre 264 meseci #13
Evo, ponovno pokušavam i radi... zašto kod tebe ne? Piše li kaki error
Re: VB kod za eject cd? 29.01.2005. u 13:16 · pre 264 meseci #14
meni radi vrkijev kod, ne znam zasto nece kod tebe, pokusaj ovako:
Code:

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 CDRom(onoff As Boolean)
    Dim lReturn As Long
    Dim state As String
    
    If onoff Then state = " open" Else state = " close"
    
    mciSendString "set CDAudio door" & state, lReturn, 127, 0

End Sub


bacis ovo u modul i samo negde u kodu dodas CDRom True/False
meni radi
Potpis
rafforum.rs - Forum Računarskog Fakulteta
Re: VB kod za eject cd? 05.06.2006. u 00:37 · pre 248 meseci #15
ma samo napravi dva buttona i modul

U form:

Code:
Private Sub Command1_Click()
lngReturn = mciSendString("set CDAudio door open", strReturn, 127, 0)
End Sub

Private Sub Command2_Click()
lngReturn = mciSendString("set CDAudio door closed", strReturn, 127, 0)
End Sub


U Modul:

Code:
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


[Ovu poruku je menjao Shadowed dana 05.06.2006. u 15:11 GMT+1]
Potpis
PeecO Undead cooler...
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme