Source code of Windows XP (NT5)
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.

304 lines
7.7 KiB

  1. #include "common.h"
  2. #include "seldrive.h"
  3. #include "msprintf.h"
  4. #include <regstr.h>
  5. #include <help.h>
  6. const DWORD aSelDriveHelpIDs[]=
  7. {
  8. IDC_SELDRIVE_COMBO, IDH_CLEANMGR_SELDRIVE,
  9. IDOK, IDH_CLEANMGR_SELDRIVE_OK,
  10. IDCANCEL, IDH_CLEANMGR_SELDRIVE_EXIT,
  11. IDC_SELDRIVE_TEXT, ((DWORD)-1),
  12. IDC_SELDRIVE_TEXT2, ((DWORD)-1),
  13. 0, 0
  14. };
  15. static struct
  16. {
  17. drenum dreDef; // default drive to choose
  18. drenum dreChose; // drive selected at end of dialog
  19. } dsd;
  20. INT_PTR CALLBACK
  21. SelectDriveProc(
  22. HWND hDlg,
  23. UINT Message,
  24. WPARAM wParam,
  25. LPARAM lParam
  26. );
  27. BOOL
  28. fillSelDriveList(
  29. HWND hDlg
  30. );
  31. WPARAM
  32. AddComboString(
  33. HWND hDlg,
  34. int id,
  35. TCHAR *psz,
  36. DWORD val
  37. );
  38. void
  39. SelectComboItem(
  40. HWND hDlg,
  41. int id,
  42. WPARAM w
  43. );
  44. void
  45. SelectDriveDlgDrawItem(
  46. HWND hDlg,
  47. DRAWITEMSTRUCT *lpdis,
  48. BOOL bHighlightBackground
  49. );
  50. // TRUE if the user selected a drive, FALSE if a user selected Exit.
  51. // If a user does select a drive then that drive is returned in the
  52. //
  53. // in/out:
  54. // pszDrive
  55. BOOL SelectDrive(LPTSTR pszDrive)
  56. {
  57. drenum dre;
  58. GetDriveFromString(pszDrive, dre);
  59. dsd.dreDef = dre;
  60. if (DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_SELDRIVE), NULL, SelectDriveProc) != IDOK)
  61. return FALSE;
  62. CreateStringFromDrive(dsd.dreChose, pszDrive, 4);
  63. return TRUE;
  64. }
  65. INT_PTR CALLBACK SelectDriveProc(HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam)
  66. {
  67. switch (Message)
  68. {
  69. case WM_INITDIALOG:
  70. if (!fillSelDriveList (hDlg))
  71. {
  72. EndDialog (hDlg, IDCANCEL);
  73. }
  74. SetFocus(GetDlgItem(hDlg, IDC_SELDRIVE_COMBO));
  75. break;
  76. case WM_DESTROY:
  77. EndDialog (hDlg, IDCANCEL);
  78. break;
  79. case WM_HELP:
  80. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, NULL,
  81. HELP_WM_HELP, (DWORD_PTR)(LPTSTR)aSelDriveHelpIDs);
  82. return TRUE;
  83. case WM_CONTEXTMENU:
  84. WinHelp((HWND) wParam, NULL, HELP_CONTEXTMENU,
  85. (DWORD_PTR)(LPVOID)aSelDriveHelpIDs);
  86. return TRUE;
  87. case WM_DRAWITEM:
  88. SelectDriveDlgDrawItem(hDlg, (DRAWITEMSTRUCT *)lParam, TRUE);
  89. break;
  90. case WM_COMMAND:
  91. switch(wParam)
  92. {
  93. case IDOK:
  94. dsd.dreChose = (drenum)SendDlgItemMessage(hDlg, IDC_SELDRIVE_COMBO, CB_GETITEMDATA,
  95. (WPARAM)SendDlgItemMessage(hDlg, IDC_SELDRIVE_COMBO, CB_GETCURSEL, 0, 0L), 0L);
  96. //Fall through
  97. case IDCANCEL:
  98. EndDialog (hDlg, wParam);
  99. break;
  100. }
  101. break;
  102. default:
  103. return FALSE;
  104. }
  105. return TRUE;
  106. }
  107. void SelectDriveDlgDrawItem(HWND hDlg, DRAWITEMSTRUCT *lpdis, BOOL bHighlightBackground)
  108. {
  109. HDC hdc = lpdis->hDC;
  110. TCHAR szText[MAX_DESC_LEN*2];
  111. SIZE size;
  112. drenum dre;
  113. HICON hIcon = NULL;
  114. DWORD dwExStyle = 0L;
  115. UINT fuETOOptions = 0;
  116. if ((int)lpdis->itemID < 0)
  117. return;
  118. SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID, (DWORD_PTR)(LPTSTR)szText);
  119. GetTextExtentPoint32(hdc, szText, lstrlen(szText), &size);
  120. dre = (drenum)SendMessage(lpdis->hwndItem, CB_GETITEMDATA, lpdis->itemID, 0);
  121. if (lpdis->itemAction != ODA_FOCUS)
  122. {
  123. int clrBackground = COLOR_WINDOW;
  124. int clrText = COLOR_WINDOWTEXT;
  125. if (bHighlightBackground && lpdis->itemState & ODS_SELECTED) {
  126. clrBackground = COLOR_HIGHLIGHT;
  127. clrText = COLOR_HIGHLIGHTTEXT;
  128. }
  129. //
  130. //For multiple selection, we don't want to draw items as
  131. //selected. Just focus rect below.
  132. //
  133. SetBkColor(hdc, GetSysColor(clrBackground));
  134. SetTextColor(hdc, GetSysColor(clrText));
  135. //
  136. //Fill in the background; do this before mini-icon is drawn
  137. //
  138. ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &(lpdis->rcItem), NULL, 0, NULL);
  139. //
  140. //Draw mini-icon for this item and move string accordingly
  141. //
  142. if ((hIcon = GetDriveIcon(dre, TRUE)) != NULL)
  143. {
  144. DrawIconEx(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, hIcon,
  145. 16, 16, 0, NULL, DI_NORMAL);
  146. lpdis->rcItem.left += 16;
  147. }
  148. lpdis->rcItem.left += INDENT;
  149. //
  150. //Draw the cleanup client display name text transparently on top of the background
  151. //
  152. SetBkMode(hdc, TRANSPARENT);
  153. dwExStyle = GetWindowLong(hDlg, GWL_EXSTYLE);
  154. if(dwExStyle & WS_EX_RTLREADING)
  155. {
  156. fuETOOptions |= ETO_RTLREADING;
  157. }
  158. ExtTextOut(hdc, lpdis->rcItem.left, lpdis->rcItem.top +
  159. ((lpdis->rcItem.bottom - lpdis->rcItem.top) - size.cy) / 2,
  160. fuETOOptions, NULL, szText, lstrlen(szText), NULL);
  161. }
  162. if (lpdis->itemAction == ODA_FOCUS || (lpdis->itemState & ODS_FOCUS))
  163. DrawFocusRect(hdc, &(lpdis->rcItem));
  164. }
  165. BOOL fillSelDriveList(HWND hDlg)
  166. {
  167. BOOL bDoDrive[Drive_Z+1];
  168. int dre;
  169. hardware hw;
  170. WPARAM dw;
  171. WPARAM dwSelected = 0;
  172. USHORT nFound = 0;
  173. drenum dreSelected = Drive_INV;
  174. TCHAR pszText[cbRESOURCE];
  175. int cDrv = 0;
  176. for (dre = (int)Drive_A; dre <= (int)Drive_Z; dre++)
  177. {
  178. bDoDrive[dre] = FALSE;
  179. }
  180. //
  181. //First, figger out what drives to hit.
  182. //
  183. for (dre = (int)Drive_A; dre <= (int)Drive_Z; dre++)
  184. {
  185. // hw id evil by ref param
  186. GetHardwareType((drenum)dre, hw);
  187. switch (hw)
  188. {
  189. case hwFixed:
  190. cDrv += 1;
  191. bDoDrive[dre] = TRUE;
  192. break;
  193. }
  194. }
  195. for (dre = (int)Drive_A; dre <= (int)Drive_Z; dre++)
  196. {
  197. if (!bDoDrive[dre])
  198. continue;
  199. GetDriveDescription((drenum)dre, pszText);
  200. dw = AddComboString(hDlg, IDC_SELDRIVE_COMBO, pszText, (DWORD)dre);
  201. nFound++;
  202. if (dsd.dreDef == (drenum)dre ||
  203. dreSelected == Drive_INV ||
  204. (dreSelected < Drive_C && dsd.dreDef == Drive_ALL) ||
  205. (dreSelected < Drive_C && dsd.dreDef == Drive_INV) )
  206. {
  207. dwSelected = dw;
  208. dreSelected = (drenum)dre;
  209. }
  210. }
  211. //
  212. //Found some drives? Pick one, and leave.
  213. //
  214. if (nFound != 0)
  215. {
  216. SelectComboItem(hDlg, IDC_SELDRIVE_COMBO, dwSelected);
  217. dsd.dreDef = dreSelected;
  218. // if only one drive in the list simulate OK press
  219. if (cDrv == 1)
  220. PostMessage(hDlg, WM_COMMAND, IDOK, 0);
  221. return TRUE;
  222. }
  223. return FALSE;
  224. }
  225. void SelectComboItem(HWND hDlg, int id, WPARAM w)
  226. {
  227. LPARAM lParam = MAKELONG((WORD)GetDlgItem(hDlg,id), (WORD)CBN_SELCHANGE );
  228. SendDlgItemMessage(hDlg, id, CB_SETCURSEL, w, 0L);
  229. SendMessage(hDlg, WM_COMMAND, id, lParam);
  230. }
  231. WPARAM AddComboString(HWND hDlg, int id, TCHAR *psz, DWORD val)
  232. {
  233. WPARAM dw = SendDlgItemMessage(hDlg, id, CB_ADDSTRING, 0, (LPARAM)psz);
  234. SendDlgItemMessage(hDlg, id, CB_SETITEMDATA, dw, (LPARAM)val);
  235. return dw;
  236. }
  237. void GetBootDrive(PTCHAR pDrive, DWORD Size)
  238. {
  239. HKEY hKey;
  240. DWORD cbSize, dwType;
  241. pDrive[0] = '\0';
  242. if (RegOpenKey(HKEY_LOCAL_MACHINE, REGSTR_PATH_SETUP_SETUP, &hKey) == ERROR_SUCCESS)
  243. {
  244. cbSize = Size;
  245. dwType = REG_SZ;
  246. RegQueryValueEx(hKey, REGSTR_VAL_BOOTDIR, NULL, &dwType, (LPBYTE)pDrive, &cbSize);
  247. RegCloseKey(hKey);
  248. }
  249. if (pDrive[0] == '\0')
  250. lstrcpy(pDrive, SZ_DEFAULT_DRIVE);
  251. }