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.

202 lines
6.3 KiB

  1. // PropPage.cpp : Implementation of CPropPage
  2. #include "hdspPCH.h"
  3. #include "MsHDSP.h"
  4. #include "PropPage.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CPropPage
  7. HRESULT CPropPage::Activate(HWND hWndParent, LPCRECT pRect, BOOL bModal )
  8. {
  9. HRESULT hr;
  10. IMDSPDevice* pIDevice = NULL;
  11. UINT uIndex;
  12. // Call the base class implementation
  13. CORg( IPropertyPageImpl<CPropPage>::Activate( hWndParent, pRect, bModal ) );
  14. // Get the IDevice interface that we passed out of GetSpecifyPropertyPages
  15. for( uIndex = 0; uIndex < m_nObjects; uIndex ++ )
  16. {
  17. hr = m_ppUnk[uIndex]->QueryInterface( &pIDevice );
  18. if( SUCCEEDED(hr) ) break;
  19. }
  20. if( !pIDevice ) return E_UNEXPECTED;
  21. // GetUserDefaultLCID() can be used to figure out what language
  22. // the page should be displayed in
  23. // Update property page
  24. CORg( UpdateManufacturer( pIDevice ) );
  25. CORg( UpdateDeviceType( pIDevice ) );
  26. CORg( UpdatePowerSource( pIDevice ) );
  27. CORg( UpdateStatus( pIDevice ) );
  28. Error:
  29. if( pIDevice ) pIDevice->Release();
  30. return hr;
  31. }
  32. // Update manufacturer value
  33. HRESULT CPropPage::UpdateManufacturer( IMDSPDevice* pIDevice )
  34. {
  35. HRESULT hr;
  36. WCHAR pwszWBuffer[MAX_PATH];
  37. CHAR pszCBuffer[MAX_PATH];
  38. CORg( pIDevice->GetManufacturer( pwszWBuffer, MAX_PATH ) );
  39. WideCharToMultiByte(CP_ACP, NULL, pwszWBuffer, -1, pszCBuffer, MAX_PATH, NULL, NULL);
  40. SetDlgItemText( IDC_MANUFACTURER, pszCBuffer );
  41. Error:
  42. return hr;
  43. }
  44. // Update device type value
  45. HRESULT CPropPage::UpdateDeviceType( IMDSPDevice* pIDevice )
  46. {
  47. HRESULT hr = S_OK;
  48. char pszType[MAX_PATH];
  49. DWORD dwType;
  50. int iIndex;
  51. static SType_String sDeviceTypeStringArray[] = {
  52. { WMDM_DEVICE_TYPE_PLAYBACK, "Playback" },
  53. { WMDM_DEVICE_TYPE_RECORD, "Record" },
  54. { WMDM_DEVICE_TYPE_DECODE, "Decode" },
  55. { WMDM_DEVICE_TYPE_ENCODE, "Encode" },
  56. { WMDM_DEVICE_TYPE_STORAGE, "Storage" },
  57. { WMDM_DEVICE_TYPE_VIRTUAL, "Virtual" },
  58. { WMDM_DEVICE_TYPE_SDMI, "Sdmi" },
  59. { WMDM_DEVICE_TYPE_NONSDMI, "non-sdmi" },
  60. { 0, NULL },
  61. };
  62. CORg( pIDevice->GetType( &dwType ) );
  63. // Add all the types reported by the device to the string.
  64. pszType[0] = '\0';
  65. for( iIndex = 0; sDeviceTypeStringArray[iIndex].dwType != 0; iIndex++ )
  66. {
  67. // Is this bit set, if it is then add the type as a string
  68. if( sDeviceTypeStringArray[iIndex].dwType & dwType )
  69. {
  70. if( strlen(pszType) )
  71. {
  72. strcat( pszType, ", " );
  73. }
  74. strcat( pszType, sDeviceTypeStringArray[iIndex].pszString );
  75. }
  76. }
  77. SetDlgItemText( IDC_DEVICE_TYPE, ((strlen(pszType)) ? pszType : "<none>") );
  78. Error:
  79. return hr;
  80. }
  81. // Update device status property in device dialog box
  82. HRESULT CPropPage::UpdatePowerSource( IMDSPDevice* pIDevice )
  83. {
  84. HRESULT hr = S_OK;
  85. char pszPowerSource[MAX_PATH];
  86. char pszPowerIs[MAX_PATH];
  87. DWORD dwPowerSource;
  88. DWORD dwPercentRemaining;
  89. CORg( pIDevice->GetPowerSource( &dwPowerSource, &dwPercentRemaining ) );
  90. // Update capabileties
  91. if( (dwPowerSource & WMDM_POWER_CAP_BATTERY) &&
  92. (dwPowerSource & WMDM_POWER_CAP_EXTERNAL) )
  93. {
  94. SetDlgItemText( IDC_POWER_CAP, "Batteries and external");
  95. }
  96. else if(dwPowerSource & WMDM_POWER_CAP_BATTERY)
  97. {
  98. SetDlgItemText( IDC_POWER_CAP, "Batteries");
  99. }
  100. else if(dwPowerSource & WMDM_POWER_CAP_EXTERNAL)
  101. {
  102. SetDlgItemText( IDC_POWER_CAP, "External");
  103. }
  104. else
  105. {
  106. SetDlgItemText( IDC_POWER_CAP, "<non reported>");
  107. }
  108. // Update current power source string
  109. if( (dwPowerSource & WMDM_POWER_CAP_BATTERY) &&
  110. (dwPowerSource & WMDM_POWER_CAP_EXTERNAL) )
  111. {
  112. strcpy( pszPowerSource, "Batteries and external");
  113. }
  114. else if( dwPowerSource & WMDM_POWER_CAP_BATTERY)
  115. {
  116. strcpy( pszPowerSource, "Batteries");
  117. }
  118. else if(dwPowerSource & WMDM_POWER_CAP_EXTERNAL)
  119. {
  120. strcpy( pszPowerSource, "External");
  121. }
  122. else
  123. {
  124. strcpy( pszPowerSource, "<none reported>");
  125. }
  126. wsprintf( pszPowerIs, "%s (%d%% remaining)", pszPowerSource, dwPercentRemaining );
  127. SetDlgItemText( IDC_POWER_IS, pszPowerIs );
  128. Error:
  129. return hr;
  130. }
  131. // Update status property
  132. HRESULT CPropPage::UpdateStatus( IMDSPDevice* pIDevice )
  133. {
  134. HRESULT hr;
  135. char pszStatus[350];
  136. DWORD dwStatus;
  137. int iIndex;
  138. static SType_String sDeviceTypeStringArray[] = {
  139. { WMDM_STATUS_READY , "Ready" },
  140. { WMDM_STATUS_BUSY , "Busy" },
  141. { WMDM_STATUS_DEVICE_NOTPRESENT , "Device not present" },
  142. { WMDM_STATUS_STORAGE_NOTPRESENT , "Storage not present" },
  143. { WMDM_STATUS_STORAGE_INITIALIZING , "Storage initializing" },
  144. { WMDM_STATUS_STORAGE_BROKEN , "Storage broken" },
  145. { WMDM_STATUS_STORAGE_NOTSUPPORTED , "Storage not supported" },
  146. { WMDM_STATUS_STORAGE_UNFORMATTED , "Storage unformatted" },
  147. { WMDM_STATUS_STORAGECONTROL_INSERTING, "Storagecontrol inserting" },
  148. { WMDM_STATUS_STORAGECONTROL_DELETING , "Storagecontrol deleting" },
  149. { WMDM_STATUS_STORAGECONTROL_MOVING , "Storagecontrol moving" },
  150. { WMDM_STATUS_STORAGECONTROL_READING , "Storagecontrol reading" },
  151. { 0, NULL },
  152. };
  153. CORg( pIDevice->GetStatus( &dwStatus ) );
  154. // Add all the types reported by the device to the string.
  155. pszStatus[0] = '\0';
  156. for( iIndex = 0; sDeviceTypeStringArray[iIndex].dwType != 0; iIndex++ )
  157. {
  158. // Is this bit set, if it is then add the status as a string
  159. if( sDeviceTypeStringArray[iIndex].dwType & dwStatus )
  160. {
  161. if( strlen(pszStatus) )
  162. {
  163. strcat( pszStatus, ", " );
  164. }
  165. strcat( pszStatus, sDeviceTypeStringArray[iIndex].pszString );
  166. }
  167. }
  168. SetDlgItemText( IDC_DEVICE_STATUS, ((strlen(pszStatus)) ? pszStatus : "<none>") );
  169. Error:
  170. return hr;
  171. }