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.

388 lines
13 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // Copyright (C) Microsoft Corporation, 1999 - 2001. All rights reserved.
  4. //
  5. //
  6. // This workspace contains two projects -
  7. // 1. ProgHelp which implements the Progress Interface
  8. // 2. The Sample application WmdmApp.
  9. //
  10. // ProgHelp.dll needs to be registered first for the SampleApp to run.
  11. // Includes
  12. //
  13. #include "appPCH.h"
  14. // Update serial id in device/storage dialog
  15. void UpdateSerialId( HWND hDlg, CItemData* pDevice )
  16. {
  17. char* pszSerial;
  18. char* pszSerialStep;
  19. int iMaxStringLength;
  20. BOOL bSerialIsString = TRUE; // Should we also show the serial id as a string?
  21. if( pDevice == NULL || hDlg == 0 ) return;
  22. // No serial ?
  23. if( pDevice->m_SerialNumber.SerialNumberLength == 0 )
  24. {
  25. SetDlgItemText( hDlg, IDC_SERIALID, "<none>" );
  26. return;
  27. }
  28. // Get serial # of device as a string
  29. iMaxStringLength = pDevice->m_SerialNumber.SerialNumberLength * sizeof("FF ") +1;
  30. pszSerial = new char[iMaxStringLength];
  31. pszSerialStep = pszSerial;
  32. for( UINT uIndex = 0; uIndex < pDevice->m_SerialNumber.SerialNumberLength; uIndex ++ )
  33. {
  34. // Add one byte at the time to the serial id string
  35. pszSerialStep += wsprintf( pszSerialStep, "%X ", pDevice->m_SerialNumber.pID[uIndex] );
  36. if( !isprint( pDevice->m_SerialNumber.pID[uIndex] ) )
  37. {
  38. bSerialIsString = FALSE;
  39. }
  40. }
  41. SetDlgItemText( hDlg, IDC_SERIALID, pszSerial );
  42. // If the serial id is a string show it as a string
  43. if( bSerialIsString && (pDevice->m_SerialNumber.SerialNumberLength > 0) )
  44. {
  45. SetDlgItemText( hDlg, IDC_SERIALID_STRING, (char*)pDevice->m_SerialNumber.pID );
  46. }
  47. delete [] pszSerial;
  48. }
  49. // Update manufacturer value in device dialog
  50. void UpdateManufacturer( HWND hDlg, CItemData* pDevice )
  51. {
  52. SetDlgItemText( hDlg, IDC_MANUFACTURER, pDevice->m_szMfr );
  53. }
  54. // Update device type value in device dialog
  55. void UpdateDeviceType( HWND hDlg, CItemData* pDevice )
  56. {
  57. char pszType[MAX_PATH];
  58. static SType_String sDeviceTypeStringArray[] = {
  59. { WMDM_DEVICE_TYPE_PLAYBACK, "Playback" },
  60. { WMDM_DEVICE_TYPE_RECORD, "Record" },
  61. { WMDM_DEVICE_TYPE_DECODE, "Decode" },
  62. { WMDM_DEVICE_TYPE_ENCODE, "Encode" },
  63. { WMDM_DEVICE_TYPE_STORAGE, "Storage" },
  64. { WMDM_DEVICE_TYPE_VIRTUAL, "Virtual" },
  65. { WMDM_DEVICE_TYPE_SDMI, "Sdmi" },
  66. { WMDM_DEVICE_TYPE_NONSDMI, "non-sdmi" },
  67. { 0, NULL },
  68. };
  69. // Add all the types reported by the device to the string.
  70. pszType[0] = '\0';
  71. for( int iIndex = 0; sDeviceTypeStringArray[iIndex].dwType != 0; iIndex++ )
  72. {
  73. // Is this bit set, if it is then add the type as a string
  74. if( sDeviceTypeStringArray[iIndex].dwType & pDevice->m_dwType )
  75. {
  76. if( strlen(pszType) )
  77. {
  78. strcat( pszType, ", " );
  79. }
  80. strcat( pszType, sDeviceTypeStringArray[iIndex].pszString );
  81. }
  82. }
  83. SetDlgItemText( hDlg, IDC_DEVICE_TYPE, ((strlen(pszType)) ? pszType : "<none>") );
  84. }
  85. // Update icon in device dialog
  86. void UpdateDeviceIcon( HWND hDlg, CItemData* pDevice )
  87. {
  88. HICON hIcon;
  89. hIcon = LoadIcon( g_hInst, MAKEINTRESOURCE( IDI_DEVICE ) );
  90. ::SendMessage(hDlg, WM_SETICON, FALSE, (LPARAM)hIcon );
  91. }
  92. // Update status property in device/storage dialog box
  93. void UpdateStatus( HWND hDlg, CItemData* pDevice )
  94. {
  95. char pszStatus[MAX_PATH];
  96. static SType_String sDeviceTypeStringArray[] = {
  97. { WMDM_STATUS_READY , "Ready" },
  98. { WMDM_STATUS_BUSY , "Busy" },
  99. { WMDM_STATUS_DEVICE_NOTPRESENT , "Device not present" },
  100. { WMDM_STATUS_STORAGE_NOTPRESENT , "Storage not present" },
  101. { WMDM_STATUS_STORAGE_INITIALIZING , "Storage initializing" },
  102. { WMDM_STATUS_STORAGE_BROKEN , "Storage broken" },
  103. { WMDM_STATUS_STORAGE_NOTSUPPORTED , "Storage not supported" },
  104. { WMDM_STATUS_STORAGE_UNFORMATTED , "Storage unformatted" },
  105. { WMDM_STATUS_STORAGECONTROL_INSERTING, "Storagecontrol inserting" },
  106. { WMDM_STATUS_STORAGECONTROL_DELETING , "Storagecontrol deleting" },
  107. { WMDM_STATUS_STORAGECONTROL_MOVING , "Storagecontrol moving" },
  108. { WMDM_STATUS_STORAGECONTROL_READING , "Storagecontrol reading" },
  109. { 0, NULL },
  110. };
  111. // Add all the types reported by the device to the string.
  112. pszStatus[0] = '\0';
  113. for( int iIndex = 0; sDeviceTypeStringArray[iIndex].dwType != 0; iIndex++ )
  114. {
  115. // Is this bit set, if it is then add the type as a string
  116. if( sDeviceTypeStringArray[iIndex].dwType & pDevice->m_dwType )
  117. {
  118. if( strlen(pszStatus) )
  119. {
  120. strcat( pszStatus, ", " );
  121. }
  122. strcat( pszStatus, sDeviceTypeStringArray[iIndex].pszString );
  123. }
  124. }
  125. SetDlgItemText( hDlg, IDC_DEVICE_STATUS, ((strlen(pszStatus)) ? pszStatus : "<none>") );
  126. }
  127. // Update device status property in device dialog box
  128. void UpdateDeviceVersion( HWND hDlg, CItemData* pDevice )
  129. {
  130. if( pDevice->m_dwVersion == (DWORD)-1 )
  131. {
  132. SetDlgItemText( hDlg, IDC_VERSION, "<not supported>");
  133. }
  134. else
  135. {
  136. SetDlgItemInt( hDlg, IDC_VERSION, pDevice->m_dwVersion, FALSE );
  137. }
  138. }
  139. // Update device status property in device dialog box
  140. void UpdatePowerSource( HWND hDlg, CItemData* pDevice )
  141. {
  142. char pszPowerSource[MAX_PATH];
  143. char pszPowerIs[MAX_PATH];
  144. // Update capabileties
  145. if( (pDevice->m_dwPowerSource & WMDM_POWER_CAP_BATTERY) &&
  146. (pDevice->m_dwPowerSource & WMDM_POWER_CAP_EXTERNAL) )
  147. {
  148. SetDlgItemText( hDlg, IDC_POWER_CAP, "Bateries and external");
  149. }
  150. else if(pDevice->m_dwPowerSource & WMDM_POWER_CAP_BATTERY)
  151. {
  152. SetDlgItemText( hDlg, IDC_POWER_CAP, "Bateries");
  153. }
  154. else if(pDevice->m_dwPowerSource & WMDM_POWER_CAP_EXTERNAL)
  155. {
  156. SetDlgItemText( hDlg, IDC_POWER_CAP, "External");
  157. }
  158. else
  159. {
  160. SetDlgItemText( hDlg, IDC_POWER_CAP, "<non reported>");
  161. }
  162. // Update current power source string
  163. if( (pDevice->m_dwPowerSource & WMDM_POWER_CAP_BATTERY) &&
  164. (pDevice->m_dwPowerSource & WMDM_POWER_CAP_EXTERNAL) )
  165. {
  166. strcpy( pszPowerSource, "Bateries and external");
  167. }
  168. else if(pDevice->m_dwPowerSource & WMDM_POWER_CAP_BATTERY)
  169. {
  170. strcpy( pszPowerSource, "Bateries");
  171. }
  172. else if(pDevice->m_dwPowerSource & WMDM_POWER_CAP_EXTERNAL)
  173. {
  174. strcpy( pszPowerSource, "External");
  175. }
  176. else
  177. {
  178. strcpy( pszPowerSource, "<non reported>");
  179. }
  180. wsprintf( pszPowerIs, "%s (%d%% remaning)", pszPowerSource, pDevice->m_dwPercentRemaining );
  181. SetDlgItemText( hDlg, IDC_POWER_IS, pszPowerIs );
  182. }
  183. // Update dialog caption
  184. void UpdateCaption( HWND hDlg, CItemData* pDevice )
  185. {
  186. char pszWndCaption[2*MAX_PATH];
  187. char pszFormat[MAX_PATH];
  188. // Set window caption
  189. LoadString( g_hInst, IDS_PROPERTIES_CAPTION, pszFormat, sizeof(pszFormat) );
  190. if (SUCCEEDED(StringCbPrintf(pszWndCaption, sizeof(pszWndCaption), pszFormat, pDevice->m_szName)))
  191. {
  192. SetWindowText( hDlg, pszWndCaption );
  193. }
  194. }
  195. // Procedure for device property dialog box
  196. INT_PTR CALLBACK DeviceProp_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  197. {
  198. switch (msg)
  199. {
  200. case WM_INITDIALOG:
  201. {
  202. CItemData* pItem = (CItemData*)lParam;
  203. if( pItem == NULL ) return FALSE;
  204. UpdateSerialId( hDlg, pItem );
  205. UpdateManufacturer( hDlg, pItem );
  206. UpdateDeviceType( hDlg, pItem );
  207. UpdateDeviceIcon( hDlg, pItem );
  208. UpdateDeviceVersion( hDlg, pItem );
  209. UpdatePowerSource( hDlg, pItem );
  210. UpdateStatus( hDlg, pItem );
  211. UpdateCaption( hDlg, pItem );
  212. CenterWindow(hDlg, g_hwndMain );
  213. return TRUE;
  214. }
  215. case WM_COMMAND:
  216. if( GET_WM_COMMAND_ID(wParam, lParam) == IDOK ||
  217. GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL)
  218. {
  219. EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  220. return TRUE;
  221. }
  222. break;
  223. default:
  224. return FALSE;
  225. }
  226. return FALSE;
  227. }
  228. // Storage properties
  229. //
  230. // Update storage attributes values in storage properties dialog
  231. void UpdateAttributes( HWND hDlg, CItemData* pDevice )
  232. {
  233. char pszAttr[MAX_PATH];
  234. static SType_String sTypeStringArray[] = {
  235. { WMDM_STORAGE_ATTR_FILESYSTEM , "Filesystem" },
  236. { WMDM_STORAGE_ATTR_REMOVABLE , "Removable" },
  237. { WMDM_STORAGE_ATTR_NONREMOVABLE , "Nonremovable" },
  238. { WMDM_STORAGE_ATTR_FOLDERS , "Folders" },
  239. { WMDM_STORAGE_ATTR_HAS_FOLDERS , "Has folders" },
  240. { WMDM_STORAGE_ATTR_HAS_FILES , "Has files" },
  241. { WMDM_FILE_ATTR_FOLDER , "Folder" },
  242. { WMDM_FILE_ATTR_LINK , "Link" },
  243. { WMDM_FILE_ATTR_FILE , "File" },
  244. { WMDM_FILE_ATTR_AUDIO , "Audio" },
  245. { WMDM_FILE_ATTR_DATA , "Data" },
  246. { WMDM_FILE_ATTR_MUSIC , "Music" },
  247. { WMDM_FILE_ATTR_AUDIOBOOK , "Audiobook" },
  248. { WMDM_FILE_ATTR_HIDDEN , "Hidden" },
  249. { WMDM_FILE_ATTR_SYSTEM , "System" },
  250. { WMDM_FILE_ATTR_READONLY , "Readonly" },
  251. { 0, NULL },
  252. };
  253. // Add all the attributes reported by the device as to the string.
  254. pszAttr[0] = '\0';
  255. for( int iIndex = 0; sTypeStringArray[iIndex].dwType != 0; iIndex++ )
  256. {
  257. // Is this bit set, if it is then add the attribute as a string
  258. if( sTypeStringArray[iIndex].dwType & pDevice->m_dwAttributes )
  259. {
  260. if( strlen(pszAttr) )
  261. {
  262. strcat( pszAttr, ", " );
  263. }
  264. strcat( pszAttr, sTypeStringArray[iIndex].pszString );
  265. }
  266. }
  267. SetDlgItemText( hDlg, IDC_ATTRIBUTES, (strlen(pszAttr) ? pszAttr : "<none>") );
  268. }
  269. // Update storage capabilities values in storage properties dialog
  270. void UpdateCapabilities( HWND hDlg, CItemData* pDevice )
  271. {
  272. char pszCap[MAX_PATH];
  273. static SType_String sTypeStringArray[] = {
  274. { WMDM_FILE_ATTR_CANPLAY , "Play" },
  275. { WMDM_FILE_ATTR_CANDELETE , "Delete" },
  276. { WMDM_FILE_ATTR_CANMOVE , "Move" },
  277. { WMDM_FILE_ATTR_CANRENAME , "Rename" },
  278. { WMDM_FILE_ATTR_CANREAD , "Read" },
  279. { 0, NULL },
  280. };
  281. // Add all the attributes reported by the device as to the string.
  282. pszCap[0] = '\0';
  283. for( int iIndex = 0; sTypeStringArray[iIndex].dwType != 0; iIndex++ )
  284. {
  285. // Is this bit set, if it is then add the capability as a string
  286. if( sTypeStringArray[iIndex].dwType & pDevice->m_dwAttributes )
  287. {
  288. if( strlen(pszCap) )
  289. {
  290. strcat( pszCap, ", " );
  291. }
  292. strcat( pszCap, sTypeStringArray[iIndex].pszString );
  293. }
  294. }
  295. SetDlgItemText( hDlg, IDC_CAPABILITIES, (strlen(pszCap) ? pszCap : "<none>") );
  296. }
  297. // Add the storage icon to the storage properties dialog
  298. void UpdateStorageIcon( HWND hDlg, CItemData* pDevice )
  299. {
  300. HICON hIcon;
  301. BOOL bIsDirectory;
  302. bIsDirectory = pDevice->m_dwAttributes & WMDM_FILE_ATTR_FOLDER;
  303. hIcon = GetShellIcon( pDevice->m_szName, bIsDirectory );
  304. ::SendMessage(hDlg, WM_SETICON, FALSE, (LPARAM)hIcon );
  305. }
  306. // Procedure for storage property dialog box
  307. INT_PTR CALLBACK StorageProp_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  308. {
  309. switch (msg)
  310. {
  311. case WM_INITDIALOG:
  312. {
  313. CItemData* pItem = (CItemData*)lParam;
  314. if( pItem == NULL ) return FALSE;
  315. UpdateSerialId( hDlg, pItem );
  316. UpdateAttributes( hDlg, (CItemData*)lParam );
  317. UpdateCapabilities( hDlg, (CItemData*)lParam );
  318. UpdateStorageIcon( hDlg, (CItemData*)lParam );
  319. UpdateStatus( hDlg, pItem );
  320. UpdateCaption( hDlg, pItem );
  321. CenterWindow(hDlg, g_hwndMain );
  322. return TRUE;
  323. }
  324. case WM_COMMAND:
  325. if( GET_WM_COMMAND_ID(wParam, lParam) == IDOK ||
  326. GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL)
  327. {
  328. EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  329. return TRUE;
  330. }
  331. break;
  332. default:
  333. return FALSE;
  334. }
  335. return FALSE;
  336. }