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.

502 lines
15 KiB

  1. /** FILE: volprop.cpp ********** Module Header ********************************
  2. *
  3. * Property page for volume info on disk.
  4. *
  5. * History:
  6. * 30-Jan-1998 HLiu Initial coding
  7. *
  8. * Copyright (C) Microsoft Corporation, 1998 - 1999
  9. *
  10. *************************************************************************/
  11. #include "propp.h"
  12. #include "volprop.h"
  13. // next 2 are shell headers
  14. #include "shlobj.h"
  15. #include "shlobjp.h"
  16. // context identifier
  17. #define HIDC_DISK 0x815c042f
  18. #define HIDC_TYPE 0x815c0430
  19. #define HIDC_STATUS 0x815c0432
  20. #define HIDC_PARTSTYLE 0x815c0434
  21. #define HIDC_SPACE 0x815c0431
  22. #define HIDC_CAPACITY 0x815c0122
  23. #define HIDC_RESERVED 0x815c0435
  24. #define HIDC_VOLUME_LIST 0x815c0132
  25. #define HIDC_VOLUME_PROPERTY 0x815c0442
  26. #define HIDC_VOLUME_POPULATE 0x815c0444
  27. // context help map
  28. static const DWORD VolumeHelpIDs[]=
  29. {
  30. IDC_DISK, HIDC_DISK,
  31. IDC_TYPE, HIDC_TYPE,
  32. IDC_STATUS, HIDC_STATUS,
  33. IDC_PARTSTYLE, HIDC_PARTSTYLE,
  34. IDC_SPACE, HIDC_SPACE,
  35. IDC_CAPACITY, HIDC_CAPACITY,
  36. IDC_RESERVED, HIDC_RESERVED,
  37. IDC_VOLUME_LIST, HIDC_VOLUME_LIST,
  38. IDC_VOLUME_PROPERTY, HIDC_VOLUME_PROPERTY,
  39. IDC_DISK_STATIC, HIDC_DISK,
  40. IDC_TYPE_STATIC, HIDC_TYPE,
  41. IDC_STATUS_STATIC, HIDC_STATUS,
  42. IDC_PARTSTYLE_STATIC, HIDC_PARTSTYLE,
  43. IDC_SPACE_STATIC, HIDC_SPACE,
  44. IDC_CAPACITY_STATIC, HIDC_CAPACITY,
  45. IDC_RESERVED_STATIC, HIDC_RESERVED,
  46. IDC_VOLUMELIST_STATIC, HIDC_VOLUME_LIST,
  47. IDC_VOLUME_POPULATE, HIDC_VOLUME_POPULATE,
  48. IDC_DIV1_STATIC, ((DWORD) -1),
  49. 0, 0
  50. };
  51. // Volume property page functions
  52. //
  53. int CALLBACK SortVolumeList(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  54. {
  55. LV_FINDINFO findInfo1 = {LVFI_PARAM,NULL,lParam1};
  56. LV_FINDINFO findInfo2 = {LVFI_PARAM,NULL,lParam2};
  57. HWND hwndVolumeList = (HWND)lParamSort;
  58. int index1 = ListView_FindItem(hwndVolumeList, -1, &findInfo1);
  59. int index2 = ListView_FindItem(hwndVolumeList, -1, &findInfo2);
  60. TCHAR ItemText1[ITEM_LENGTH];
  61. TCHAR ItemText2[ITEM_LENGTH];
  62. ListView_GetItemText(hwndVolumeList,index1,0,ItemText1,ITEM_LENGTH);
  63. ListView_GetItemText(hwndVolumeList,index2,0,ItemText2,ITEM_LENGTH);
  64. if (lstrcmp(ItemText1,ItemText2)>0)
  65. return 1;
  66. else
  67. return -1;
  68. }
  69. BOOL
  70. VolumeOnPopulate(HWND HWnd,
  71. PVOLUME_PAGE_DATA volumeData )
  72. {
  73. HMODULE LdmModule;
  74. PPROPERTY_PAGE_DATA pPropertyPageData = NULL;
  75. HWND hwndVolumeList=GetDlgItem(HWnd, IDC_VOLUME_LIST);
  76. int iCount, i;
  77. LVITEM lvitem;
  78. BOOL bLoadedDmdskmgr=FALSE;
  79. BOOL bResult=FALSE;
  80. TCHAR bufferError[800]; // big enough for localization
  81. TCHAR bufferTitle[100];
  82. //
  83. // Check if LDM is loaded in the same process. If yes, check to see if
  84. // volume information is already available from it.
  85. //
  86. LdmModule = GetModuleHandle(TEXT("dmdskmgr"));
  87. if ( LdmModule )
  88. {
  89. GET_PROPERTY_PAGE_DATA pfnGetPropertyPageData;
  90. pfnGetPropertyPageData = (GET_PROPERTY_PAGE_DATA)
  91. GetProcAddress(LdmModule, "GetPropertyPageData");
  92. if (pfnGetPropertyPageData)
  93. pPropertyPageData = (*pfnGetPropertyPageData)(
  94. volumeData->MachineName,
  95. volumeData->DeviceInstanceId);
  96. }
  97. //
  98. // Try to load the data through dmadmin otherwise.
  99. //
  100. if (!pPropertyPageData)
  101. {
  102. LOAD_PROPERTY_PAGE_DATA pfnLoadPropertyPageData;
  103. if (!LdmModule)
  104. {
  105. LdmModule = LoadLibrary(TEXT("dmdskmgr"));
  106. if (!LdmModule)
  107. goto _out;
  108. bLoadedDmdskmgr = TRUE;
  109. }
  110. pfnLoadPropertyPageData = (LOAD_PROPERTY_PAGE_DATA)
  111. GetProcAddress(LdmModule, "LoadPropertyPageData");
  112. if (pfnLoadPropertyPageData)
  113. pPropertyPageData = (*pfnLoadPropertyPageData)(
  114. volumeData->MachineName,
  115. volumeData->DeviceInfoSet,
  116. volumeData->DeviceInfoData );
  117. }
  118. if (!pPropertyPageData)
  119. {
  120. if ( LoadString( ModuleInstance, IDS_DISK_INFO_NOT_FOUND, bufferError,
  121. 800 ) &&
  122. LoadString( ModuleInstance, IDS_DISK_INFO_NOT_FOUND_TITLE, bufferTitle,
  123. 100 ) )
  124. {
  125. MessageBox( HWnd,
  126. bufferError,
  127. bufferTitle,
  128. MB_OK | MB_ICONERROR );
  129. }
  130. goto _out;
  131. }
  132. volumeData->pPropertyPageData = pPropertyPageData;
  133. //
  134. // Initialize property page items.
  135. //
  136. SendDlgItemMessage( HWnd, IDC_DISK, WM_SETTEXT, (WPARAM)NULL,
  137. (LPARAM)pPropertyPageData->DiskName );
  138. SendDlgItemMessage( HWnd, IDC_STATUS, WM_SETTEXT, (WPARAM)NULL,
  139. (LPARAM)pPropertyPageData->DiskStatus );
  140. SendDlgItemMessage( HWnd, IDC_TYPE, WM_SETTEXT, (WPARAM)NULL,
  141. (LPARAM)pPropertyPageData->DiskType );
  142. SendDlgItemMessage( HWnd, IDC_PARTSTYLE, WM_SETTEXT, (WPARAM)NULL,
  143. (LPARAM)pPropertyPageData->DiskPartitionStyle );
  144. SendDlgItemMessage( HWnd, IDC_CAPACITY, WM_SETTEXT, (WPARAM)NULL,
  145. (LPARAM)pPropertyPageData->DiskCapacity );
  146. SendDlgItemMessage( HWnd, IDC_SPACE, WM_SETTEXT, (WPARAM)NULL,
  147. (LPARAM)pPropertyPageData->DiskFreeSpace );
  148. SendDlgItemMessage( HWnd, IDC_RESERVED, WM_SETTEXT, (WPARAM)NULL,
  149. (LPARAM)pPropertyPageData->DiskReservedSpace );
  150. // Set image list
  151. ListView_SetImageList( hwndVolumeList,
  152. pPropertyPageData->ImageList,
  153. LVSIL_SMALL);
  154. //
  155. // Fill in volume list.
  156. //
  157. iCount = 0;
  158. lvitem.state = 0;
  159. lvitem.stateMask = 0;
  160. lvitem.iImage = 1;
  161. for (i=0; i<pPropertyPageData->VolumeCount; i++)
  162. {
  163. int iIndex;
  164. lvitem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
  165. lvitem.pszText = pPropertyPageData->VolumeArray[i].Label;
  166. lvitem.iItem = i;
  167. lvitem.iSubItem = 0;
  168. lvitem.lParam = (LPARAM)(pPropertyPageData->VolumeArray[i].MountName);
  169. lvitem.iImage = 1;
  170. iIndex = ListView_InsertItem( hwndVolumeList, &lvitem );
  171. ListView_SetItemText( hwndVolumeList, iIndex, 1,
  172. pPropertyPageData->VolumeArray[i].Size );
  173. }
  174. ListView_SortItems( hwndVolumeList, SortVolumeList, hwndVolumeList );
  175. EnableWindow( GetDlgItem(HWnd,IDC_VOLUME_POPULATE), FALSE );
  176. bResult = TRUE;
  177. _out:
  178. if ( bLoadedDmdskmgr )
  179. FreeLibrary( LdmModule );
  180. return bResult;
  181. }
  182. BOOL
  183. VolumeOnInitDialog(HWND HWnd,
  184. HWND HWndFocus,
  185. LPARAM LParam)
  186. {
  187. SP_DEVINFO_LIST_DETAIL_DATA DeviceInfoSetDetailData;
  188. HWND hwndVolumeList;
  189. LPPROPSHEETPAGE page = (LPPROPSHEETPAGE) LParam;
  190. PVOLUME_PAGE_DATA volumeData = (PVOLUME_PAGE_DATA)page->lParam;
  191. TCHAR HeadingColumn[ITEM_LENGTH], *pstrTemp;
  192. LVCOLUMN lvcolumn;
  193. RECT rect;
  194. volumeData->pPropertyPageData = NULL;
  195. //
  196. // Display volume list headings.
  197. //
  198. hwndVolumeList = GetDlgItem( HWnd, IDC_VOLUME_LIST );
  199. HeadingColumn[0] = TEXT('\0');
  200. LoadString( ModuleInstance, IDS_VOLUME_VOLUME, HeadingColumn,
  201. ITEM_LENGTH );
  202. lvcolumn.mask = LVCF_TEXT | LVCF_FMT;
  203. lvcolumn.pszText = HeadingColumn;
  204. lvcolumn.fmt = LVCFMT_LEFT;
  205. lvcolumn.iSubItem= 0;
  206. ListView_InsertColumn( hwndVolumeList, 0, &lvcolumn );
  207. HeadingColumn[0] = TEXT('\0');
  208. LoadString( ModuleInstance, IDS_VOLUME_CAPACITY, HeadingColumn,
  209. ITEM_LENGTH );
  210. lvcolumn.mask = LVCF_TEXT | LVCF_FMT | LVCF_SUBITEM;
  211. lvcolumn.pszText = HeadingColumn;
  212. lvcolumn.fmt = LVCFMT_LEFT;
  213. lvcolumn.iSubItem= 1;
  214. ListView_InsertColumn( hwndVolumeList, 1, &lvcolumn );
  215. //
  216. // Set column widths.
  217. //
  218. GetClientRect( hwndVolumeList, &rect );
  219. ListView_SetColumnWidth( hwndVolumeList, 0, (int)rect.right*2/3 );
  220. ListView_SetColumnWidth( hwndVolumeList, 1, (int)rect.right/3 );
  221. EnableWindow( GetDlgItem(HWnd, IDC_VOLUME_PROPERTY), FALSE );
  222. //
  223. // Get machine name.
  224. //
  225. DeviceInfoSetDetailData.cbSize = sizeof(SP_DEVINFO_LIST_DETAIL_DATA);
  226. if ( !SetupDiGetDeviceInfoListDetail( volumeData->DeviceInfoSet,
  227. &DeviceInfoSetDetailData) )
  228. return FALSE;
  229. if (DeviceInfoSetDetailData.RemoteMachineHandle)
  230. {
  231. volumeData->bIsLocalMachine = FALSE;
  232. pstrTemp = DeviceInfoSetDetailData.RemoteMachineName;
  233. while (*pstrTemp==_T('\\')) pstrTemp++;
  234. lstrcpy( volumeData->MachineName, pstrTemp );
  235. }
  236. else
  237. {
  238. volumeData->bIsLocalMachine = TRUE;
  239. volumeData->MachineName[0] = _T('\0');
  240. }
  241. //
  242. // Get physical device instance Id.
  243. //
  244. if ( !SetupDiGetDeviceInstanceId( volumeData->DeviceInfoSet,
  245. volumeData->DeviceInfoData,
  246. volumeData->DeviceInstanceId,
  247. sizeof(volumeData->DeviceInstanceId),
  248. NULL
  249. ) )
  250. return FALSE;
  251. SetWindowLongPtr( HWnd, DWLP_USER, (LONG_PTR)volumeData );
  252. //
  253. // Hide "Populate" button and populate volume page if this page is
  254. // brought up from Disk Management snapin.
  255. //
  256. if (volumeData->bInvokedByDiskmgr)
  257. {
  258. ShowWindow(GetDlgItem(HWnd,IDC_VOLUME_POPULATE), SW_HIDE);
  259. VolumeOnPopulate( HWnd, volumeData );
  260. }
  261. return TRUE;
  262. }
  263. VOID VolumeOnProperty(HWND HWnd)
  264. {
  265. HWND hwndVolumeList = GetDlgItem(HWnd, IDC_VOLUME_LIST);
  266. LVITEM lvitem;
  267. int iSelItem;
  268. WCHAR *MountName;
  269. //
  270. // Find selected item.
  271. //
  272. iSelItem = ListView_GetNextItem(hwndVolumeList, -1, LVNI_SELECTED);
  273. if (iSelItem==LB_ERR)
  274. return;
  275. //
  276. // Get mount name.
  277. //
  278. lvitem.mask = LVIF_PARAM;
  279. lvitem.iItem = iSelItem;
  280. lvitem.iSubItem = 0;
  281. lvitem.lParam = 0;
  282. ListView_GetItem(hwndVolumeList, &lvitem);
  283. MountName = (WCHAR *)lvitem.lParam;
  284. SetFocus(hwndVolumeList);
  285. ListView_SetItemState( hwndVolumeList,
  286. iSelItem,
  287. LVIS_FOCUSED | LVIS_SELECTED,
  288. LVIS_FOCUSED | LVIS_SELECTED);
  289. // EnableWindow(GetDlgItem(HWnd,IDC_VOLUME_PROPERTY), TRUE);
  290. if ( MountName[1]==L':' )
  291. SHObjectProperties(NULL, SHOP_FILEPATH, MountName, NULL);
  292. else
  293. SHObjectProperties(NULL, SHOP_VOLUMEGUID, MountName, NULL);
  294. }
  295. VOID
  296. VolumeOnCommand(HWND HWnd,
  297. int id,
  298. HWND HWndCtl,
  299. UINT codeNotify)
  300. {
  301. HCURSOR hOldCursor;
  302. PVOLUME_PAGE_DATA volumeData = (PVOLUME_PAGE_DATA) GetWindowLongPtr(HWnd,
  303. DWLP_USER);
  304. switch (id) {
  305. case IDC_VOLUME_POPULATE:
  306. hOldCursor = SetCursor( LoadCursor(NULL, IDC_WAIT) );
  307. VolumeOnPopulate(HWnd, volumeData);
  308. SetCursor( hOldCursor );
  309. break;
  310. case IDC_VOLUME_PROPERTY:
  311. VolumeOnProperty(HWnd);
  312. break;
  313. }
  314. }
  315. LRESULT
  316. VolumeOnNotify (HWND HWnd,
  317. int HWndFocus,
  318. LPNMHDR lpNMHdr)
  319. {
  320. PVOLUME_PAGE_DATA volumeData = (PVOLUME_PAGE_DATA) GetWindowLongPtr(HWnd,
  321. DWLP_USER);
  322. int iSelItem;
  323. WCHAR *MountName;
  324. switch(lpNMHdr->code) {
  325. case NM_CLICK:
  326. //
  327. // Sanity check.
  328. //
  329. if (lpNMHdr->idFrom!=IDC_VOLUME_LIST)
  330. break;
  331. //
  332. // Don't do volume property on remote machine.
  333. //
  334. if (!volumeData->bIsLocalMachine)
  335. break;
  336. iSelItem = ListView_GetNextItem(lpNMHdr->hwndFrom,
  337. -1, LVNI_SELECTED);
  338. if (iSelItem == LB_ERR)
  339. EnableWindow(GetDlgItem(HWnd, IDC_VOLUME_PROPERTY), FALSE);
  340. else {
  341. // enable only if item has a mount name
  342. LVITEM lvitem;
  343. lvitem.mask = LVIF_PARAM;
  344. lvitem.iItem = iSelItem;
  345. lvitem.iSubItem = 0;
  346. lvitem.lParam = 0;
  347. ListView_GetItem(GetDlgItem(HWnd, IDC_VOLUME_LIST), &lvitem);
  348. MountName = (WCHAR *)lvitem.lParam;
  349. if (MountName)
  350. EnableWindow(GetDlgItem(HWnd, IDC_VOLUME_PROPERTY), TRUE);
  351. else
  352. EnableWindow(GetDlgItem(HWnd, IDC_VOLUME_PROPERTY), FALSE);
  353. }
  354. break;
  355. }
  356. return 0;
  357. }
  358. BOOL
  359. VolumeContextMenu(
  360. HWND HwndControl,
  361. WORD Xpos,
  362. WORD Ypos
  363. )
  364. {
  365. WinHelp(HwndControl,
  366. _T("diskmgmt.hlp"),
  367. HELP_CONTEXTMENU,
  368. (ULONG_PTR) VolumeHelpIDs);
  369. return FALSE;
  370. }
  371. void
  372. VolumeHelp(
  373. HWND ParentHwnd,
  374. LPHELPINFO HelpInfo
  375. )
  376. {
  377. if (HelpInfo->iContextType == HELPINFO_WINDOW) {
  378. WinHelp((HWND) HelpInfo->hItemHandle,
  379. _T("diskmgmt.hlp"),
  380. HELP_WM_HELP,
  381. (ULONG_PTR) VolumeHelpIDs);
  382. }
  383. }
  384. void
  385. VolumeOnDestroy(HWND HWnd)
  386. {
  387. PVOLUME_PAGE_DATA volumeData = (PVOLUME_PAGE_DATA) GetWindowLongPtr(HWnd,
  388. DWLP_USER);
  389. PPROPERTY_PAGE_DATA pPropertyPageData = NULL;
  390. int i;
  391. //
  392. // release data memory
  393. //
  394. if (volumeData->pPropertyPageData)
  395. {
  396. pPropertyPageData = volumeData->pPropertyPageData;
  397. for (i=0; i<pPropertyPageData->VolumeCount; i++ )
  398. {
  399. if (pPropertyPageData->VolumeArray[i].MountName)
  400. HeapFree( GetProcessHeap(), 0,
  401. pPropertyPageData->VolumeArray[i].MountName);
  402. }
  403. HeapFree( GetProcessHeap(), 0, pPropertyPageData );
  404. }
  405. }
  406. INT_PTR
  407. VolumeDialogProc(HWND hWnd,
  408. UINT Message,
  409. WPARAM wParam,
  410. LPARAM lParam)
  411. {
  412. switch(Message)
  413. {
  414. HANDLE_MSG(hWnd, WM_INITDIALOG, VolumeOnInitDialog);
  415. HANDLE_MSG(hWnd, WM_COMMAND, VolumeOnCommand);
  416. HANDLE_MSG(hWnd, WM_NOTIFY, VolumeOnNotify);
  417. case WM_CONTEXTMENU:
  418. return VolumeContextMenu((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
  419. case WM_HELP:
  420. VolumeHelp(hWnd, (LPHELPINFO) lParam);
  421. break;
  422. case WM_DESTROY:
  423. VolumeOnDestroy(hWnd);
  424. break;
  425. }
  426. return FALSE;
  427. }
  428. BOOL
  429. VolumeDialogCallback(
  430. HWND HWnd,
  431. UINT Message,
  432. LPPROPSHEETPAGE Page
  433. )
  434. {
  435. return TRUE;
  436. }