Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.2 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. #include <stdafx.h>
  3. #include <winuser.h>
  4. #include <windows.h>
  5. #include "mswebdvd.h"
  6. #include "msdvd.h"
  7. #include "MediaHndlr.h"
  8. #include <dbt.h> // device broadcast structure
  9. //
  10. // Ejection event handler
  11. //
  12. CMediaHandler::CMediaHandler()
  13. : m_driveMask( 0 )
  14. , m_ejected( false )
  15. , m_inserted( false )
  16. {
  17. m_pDVD = NULL;
  18. }
  19. CMediaHandler::~CMediaHandler()
  20. {
  21. }
  22. void CMediaHandler::ClearFlags()
  23. {
  24. m_ejected = false;
  25. m_inserted = false;
  26. }
  27. bool CMediaHandler::SetDrive( TCHAR tcDriveLetter )
  28. {
  29. if( TEXT('A') <= tcDriveLetter && tcDriveLetter <= TEXT('Z') ) {
  30. m_driveMask = 1<< (tcDriveLetter-TEXT('A'));
  31. } else if( TEXT('a') <= tcDriveLetter && tcDriveLetter <= TEXT('z')) {
  32. m_driveMask = 1<< (tcDriveLetter-TEXT('a'));
  33. } else {
  34. return false;
  35. }
  36. ClearFlags();
  37. return true;
  38. }
  39. LRESULT CMediaHandler::WndProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
  40. {
  41. if (m_pDVD == NULL)
  42. return ParentClass::WndProc( uMsg, wParam, lParam);
  43. switch (uMsg) {
  44. case WM_DEVICECHANGE:
  45. {
  46. switch( wParam ) {
  47. case DBT_DEVICEREMOVECOMPLETE:
  48. case DBT_DEVICEARRIVAL:
  49. case DBT_DEVICEQUERYREMOVE:
  50. {
  51. PDEV_BROADCAST_HDR pdbch = (PDEV_BROADCAST_HDR) lParam;
  52. if(pdbch->dbch_devicetype == DBT_DEVTYP_VOLUME ) {
  53. PDEV_BROADCAST_VOLUME pdbcv = (PDEV_BROADCAST_VOLUME) pdbch;
  54. if (pdbcv->dbcv_flags == DBTF_MEDIA || wParam == DBT_DEVICEQUERYREMOVE)
  55. {
  56. // pdbcv->dbcv_unitmask identifies which logical drive
  57. switch( wParam ) {
  58. case DBT_DEVICEARRIVAL:
  59. if( pdbcv->dbcv_unitmask & m_driveMask ) {
  60. // send change event
  61. if( !m_inserted ) {
  62. CComVariant var = 0;
  63. m_pDVD->Fire_DVDNotify(EC_DVD_DISC_INSERTED, var, var);
  64. }
  65. m_inserted = true;
  66. m_ejected = false;
  67. m_pDVD->SetDiscEjected(false);
  68. }
  69. // return TRUE .. see the MSDN docs for DBT_DEVICEQUERYREMOVE
  70. return TRUE;
  71. case DBT_DEVICEQUERYREMOVE:
  72. if( pdbcv->dbcv_unitmask & m_driveMask ) {
  73. if( !m_ejected ) {
  74. CComVariant var = 0;
  75. m_pDVD->Fire_DVDNotify(EC_DVD_DISC_EJECTED, var, var);
  76. }
  77. m_ejected = true;
  78. m_inserted = false;
  79. m_pDVD->SetDiscEjected(true);
  80. }
  81. return TRUE; // grant permission
  82. case DBT_DEVICEREMOVECOMPLETE:
  83. if( pdbcv->dbcv_unitmask & m_driveMask ) {
  84. if( !m_ejected ) {
  85. CComVariant var = 0;
  86. m_pDVD->Fire_DVDNotify(EC_DVD_DISC_EJECTED, var, var);
  87. }
  88. m_ejected = true;
  89. m_inserted = false;
  90. m_pDVD->SetDiscEjected(true);
  91. }
  92. return TRUE; // grant permission
  93. default:
  94. return TRUE;
  95. }
  96. }
  97. }
  98. break;
  99. }
  100. default:
  101. break;
  102. }
  103. break;
  104. }
  105. default:
  106. break;
  107. }
  108. return ParentClass::WndProc( uMsg, wParam, lParam);
  109. }