Mon programme doit savoir quand un utilisateur éjecte un disque CD. Y at-il une sorte de notification pour cela dans Windows?Notification d'éjection de CD sous Windows
2
A
Répondre
5
Pour les langues non-.NET, vous ajoutez un gestionnaire de messages pour le message WM_DEVICECHANGE et pour identifier un wParam DBT_DEVICEREMOVECOMPLETE. La partition LPARAM pointe vers une structure DEV_BROADCAST_HDR; c'est membre dbch_devicetype donne le devicetype.
3
Voici un code VB qui vous montre comment cela est fait.
Shared Sub Main(ByVal args() As String)
Dim we As New WMIEvent
Dim w As ManagementEventWatcher = Nothing
Dim q As WqlEventQuery
Dim observer As New ManagementOperationObserver
' Bind to local machine
Dim opt As New ConnectionOptions
opt.EnablePrivileges = True 'sets required privilege
Dim scope As New ManagementScope("root\CIMV2", opt)
Try
q = New WqlEventQuery
q.EventClassName = "__InstanceModificationEvent"
q.WithinInterval = New TimeSpan(0, 0, 1)
' DriveType - 5: CDROM
q.Condition = "TargetInstance ISA 'Win32_LogicalDisk'" & _
" and TargetInstance.DriveType = 5"
w = New ManagementEventWatcher(scope, q)
' register async. event handler
AddHandler w.EventArrived, AddressOf we.CDREventArrived
w.Start()
' Do something usefull,block thread for testing
Console.ReadLine()
Catch e As Exception
Console.WriteLine(e.Message)
Finally
w.Stop()
End Try
End Sub 'Main
' Dump all properties
Public Sub CDREventArrived(ByVal sender As Object, ByVal e As EventArrivedEventArgs)
' Get the Event object and display it
Dim pd As PropertyData = e.NewEvent.Properties("TargetInstance")
If Not (pd Is Nothing) Then
Dim mbo As ManagementBaseObject = pd.Value '
' if CD removed VolumeName == null
If Not (mbo.Properties("VolumeName").Value Is Nothing) Then
Console.WriteLine("CD has been inserted")
Else
Console.WriteLine("CD has been ejected")
End If
End If
End Sub 'CDREventArrived
Questions connexes
- 1. Windows CD Burning API
- 2. Bibliothèque de notification pour Windows
- 3. Evier de notification de socket Windows
- 4. Notification de suppression de glisser-déposer dans Windows
- 5. Création d'un double CD Mac/Win Autorun
- 6. Icône de notification numérique Windows Forms 1..2..3
- 7. Windows Server 2003 notification de vidange NLB à l'arrêt
- 8. Autorun un CD de Process.Start
- 9. CD Ripping in Delphi
- 10. Installation de Starling sous Windows
- 11. Débogage de xsp sous Windows
- 12. Barres de notification non modales?
- 13. Comment graver un CD audio par programme sous Mac OS X
- 14. Performances QtCreator sous Windows
- 15. Mono-service sous Windows
- 16. IIS sous Windows XP
- 17. Communication interprocessus sous Windows
- 18. Liaison libsox sous Windows
- 19. GHC + wxHaskell sous Windows
- 20. Avertissements fatals sous Windows
- 21. Mono IDE sous Windows
- 22. Comment générer un GUID sous Windows Mobile?
- 23. Icône de notification iPhone
- 24. Modèles de notification mutuelle
- 25. Clé cd SQL Server 2005
- 26. C# FTP avec CD désactivé
- 27. Comment spécifier un éditeur pour setup.exe lors de l'exécution automatique d'un CD d'installation dans Windows
- 28. Comment afficher une icône lors de l'exécution automatique d'un CD d'installation dans Windows
- 29. Notification lorsqu'un thread est détruit
- 30. Vista - Notification de panne de programme