Toon posts:

[VB6] Handle maken naar event?

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb een probleem waar ikzelf niet goed uitkom, ik wil dat mijn vb6 programma doorheeft als er een andere cd/dvd in de pc word gedaan. Nou vind ik genoeg dingen over autorun, maar die wil ik niet gebruiken, bijvoorbeeld omdat veel mensen die uit hebben staan.
De MS SysInfo-component heeft een DeviceArrival event die ook getriggerd word bij een nieuwe cd.
Ik wil dat event gebruiken, maar is het mogelijk een handle naar dat event te krijgen? Ik heb hierzelf totaal geen ervaring mee.
Die handle kan ik dan controleren met WaitForMultipleObjects.

Als ik in het DeviceArrival-event een message-box zet, en de time-out van waitForMultipleObjects op 10ms instel, dan krjig ik pas na een halve minuut de messagebox te zien, dat is dus geen optie.

  • Woudloper
  • Registratie: November 2001
  • Niet online

Woudloper

« - _ - »

Het enige antwoord wat ik vond op jouw vraag was dit in combinatie met deze search bij Google Groups. Verder kan je ook nog even kijken bij VBNet, daar staan namelijk ook nog wat voorbeelden voor het gebruikt van de CD Informatie...

Verwijderd

Topicstarter
Bedankt voor je reactie! De TS is misgien wat onduidelijk, maar ik bedoel dus: hoe kan ik de event van de SysInfo-component detecteren terwijl ik WaitForMultipleObjects gebruik?
WaitForMultipleObjects kan toch ook handles naar events bevatten? Hoe zit dit?

  • sopsop
  • Registratie: Januari 2002
  • Laatst online: 19:12

sopsop

[v] [;,,;] [v]

SysInfo Control: Constants Not Supported
The reference topics for the following events have lists of constants that identify devices and device data.:
DeviceArrival Event
• DeviceOtherEvent Event
• DeviceQueryRemove Event
• DeviceQueryRemoveFailed Event
• DeviceRemoveComplete Event
• DeviceRemovePending Event
Contrary to the documentation, however, these constants are not supported by the events or the SysInfo control. The values associated with the constants listed in the help topics are valid, but the constant names are not.
bron: http://support.microsoft.com/kb/170162/EN-US/

[ Voor 7% gewijzigd door sopsop op 28-12-2004 15:55 ]


  • sopsop
  • Registratie: Januari 2002
  • Laatst online: 19:12

sopsop

[v] [;,,;] [v]

Ik heb wat gevonden, 't is wel russisch :)

Maak een module aan, met daarin deze code:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Public Declare Function CallWindowProc Lib "user32" _
  Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
                           ByVal hwnd As Long, _
                           ByVal Msg As Long, _
                           ByVal wParam As Long, _
                           ByVal lParam As Long) As Long

Public Declare Function GetWindowLong Lib "user32" _
  Alias "GetWindowLongA" (ByVal hwnd As Long, _
                          ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib "user32" _
  Alias "SetWindowLongA" (ByVal hwnd As Long, _
                          ByVal nIndex As Long, _
                          ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = (-4)
Public Const WM_DEVICECHANGE = &H219

Public glngPrevWndProc As Long
 
Public Function MyWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  If Msg = WM_DEVICECHANGE Then
    Select Case wParam
     
     ' If device (CD-ROM) arrive...
      Case &H8000&
        ' je actie die je wilt doen...
        Call Form1.DeviceArrival
     
     ' If CD-ROM has ejected...
      Case &H8004&
        ' je actie die je wilt doen...
        Call Form1.DeviceRemoveComplete
    End Select
    MyWindowProc = 0
    Exit Function
  End If
 
 ' pass the rest messages onto VB's own Window Procedure
  MyWindowProc = CallWindowProc(glngPrevWndProc, hwnd, Msg, wParam, lParam)
End Function


En een formpje met twee labels, en deze code, met name de form_load en unload:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Private Sub Form_Load()
  glngPrevWndProc = GetWindowLong(hwnd, GWL_WNDPROC)
  SetWindowLong hwnd, GWL_WNDPROC, AddressOf MyWindowProc
End Sub

Private Sub Form_Unload(Cancel As Integer)
  SetWindowLong hwnd, GWL_WNDPROC, glngPrevWndProc
End Sub

Sub DeviceArrival()
  Label2.Caption = "Device Arrived"
End Sub

 
Sub DeviceRemoveComplete()
  Label2.Caption = "Device Removed"
End Sub