mycomp.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 6k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. /*
  2.  * mycomp - Dialog box property sheet for "My Computer"
  3.  *
  4.  *  For now, we display only Drives.
  5.  */
  6. #include "tweakui.h"
  7. #pragma BEGIN_CONST_DATA
  8. const static DWORD CODESEG rgdwHelp[] = {
  9. IDC_ICONLVTEXT, IDH_GROUP,
  10. IDC_ICONLVTEXT2, IDH_MYCOMP,
  11. IDC_ICONLV, IDH_MYCOMP,
  12. 0, 0,
  13. };
  14. typedef struct MDI { /* mdi = my computer dialog info */
  15.     DWORD dwNoDrives;
  16.     DWORD dwValidDrives;
  17. } MDI, *PMDI;
  18. MDI mdi;
  19. #define pdmi (&mdi)
  20. #pragma END_CONST_DATA
  21. /*****************************************************************************
  22.  *
  23.  *  MyComp_BuildRoot
  24.  *
  25.  * Build the root directory of a drive.  The buffer must be 4 chars.
  26.  *
  27.  *****************************************************************************/
  28. LPTSTR PASCAL
  29. MyComp_BuildRoot(LPTSTR ptsz, UINT uiDrive)
  30. {
  31.     ptsz[0] = uiDrive + TEXT('A');
  32.     ptsz[1] = TEXT(':');
  33.     ptsz[2] = TEXT('\');
  34.     ptsz[3] = TEXT('');
  35.     return ptsz;
  36. }
  37. /*****************************************************************************
  38.  *
  39.  *  MyComp_LV_GetIcon
  40.  *
  41.  * Produce the icon associated with an item.  This is called when
  42.  * we need to rebuild the icon list after the icon cache has been
  43.  * purged.
  44.  *
  45.  *****************************************************************************/
  46. #define idiPhantom -11 /* Magic index for disconnected drive */
  47. int PASCAL
  48. MyComp_LV_GetIcon(LPARAM insi)
  49. {
  50.     if (pdmi->dwValidDrives & (1 << insi)) {
  51. SHFILEINFO sfi;
  52. TCHAR tszRoot[4]; /* Root directory thing */
  53. SHGetFileInfo(MyComp_BuildRoot(tszRoot, insi), 0, &sfi, cbX(sfi),
  54.       SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
  55. return sfi.iIcon;
  56.     } else {
  57. if (g_fNT) {
  58.     UnicodeFromPtsz(wsz, g_tszPathShell32);
  59.     return mit.Shell_GetCachedImageIndex(wsz, idiPhantom, 0);
  60. } else {
  61.     return mit.Shell_GetCachedImageIndex(g_tszPathShell32,
  62.  idiPhantom, 0);
  63. }
  64.     }
  65. }
  66. /*****************************************************************************
  67.  *
  68.  *  MyComp_OnInitDialog
  69.  *
  70.  *  For now, just populate with each physical local drive.
  71.  *
  72.  *****************************************************************************/
  73. BOOL PASCAL
  74. MyComp_OnInitDialog(HWND hwnd)
  75. {
  76.     UINT ui;
  77.     TCHAR tszDrive[3];
  78.     tszDrive[1] = TEXT(':');
  79.     tszDrive[2] = TEXT('');
  80.     pdmi->dwNoDrives = GetRegDword(g_hkCUSMWCV, c_tszRestrictions,
  81.    c_tszNoDrives, 0);
  82.     pdmi->dwValidDrives = GetLogicalDrives();
  83.     for (ui = 0; ui < 26; ui++) {
  84. int iIcon = MyComp_LV_GetIcon(ui);
  85. tszDrive[0] = ui + TEXT('A');
  86. LV_AddItem(hwnd, ui, tszDrive, iIcon, !(pdmi->dwNoDrives & (1 << ui)));
  87.     }
  88.     return 1;
  89. }
  90. /*****************************************************************************
  91.  *
  92.  *  MyComp_OnDestroy
  93.  *
  94.  *  Free the memory we allocated.
  95.  *
  96.  *****************************************************************************/
  97. BOOL PASCAL
  98. MyComp_OnDestroy(HWND hdlg)
  99. {
  100. //    Misc_FreePgxa(&pddii->gxa);
  101. //    if (pddii->hkNS) {
  102. // RegCloseKey(pddii->hkNS);
  103. //    }
  104.     return 1;
  105. }
  106. #if 0
  107. /*****************************************************************************
  108.  *
  109.  *  MyComp_FactoryReset
  110.  *
  111.  * This is scary and un-undoable, so let's do extra confirmation.
  112.  *
  113.  *****************************************************************************/
  114. void PASCAL
  115. MyComp_FactoryReset(HWND hdlg)
  116. {
  117.     if (MessageBoxId(hdlg, IDS_MyCompRESETOK,
  118.      tszName, MB_YESNO + MB_DEFBUTTON2) == IDYES) {
  119. pcdii->fRunShellInf = 1;
  120. Common_NeedLogoff(hdlg);
  121. PropSheet_Apply(GetParent(hdlg));
  122.     }
  123. }
  124. #endif
  125. /*****************************************************************************
  126.  *
  127.  *  MyComp_OnApply
  128.  *
  129.  * Write the changes to the registry.
  130.  *
  131.  *****************************************************************************/
  132. void PASCAL
  133. MyComp_OnApply(HWND hdlg)
  134. {
  135.     HWND hwnd = GetDlgItem(hdlg, IDC_ICONLV);
  136.     DWORD dwDrives = 0;
  137.     LV_ITEM lvi;
  138.     for (lvi.iItem = 0; lvi.iItem < 26; lvi.iItem++) {
  139. lvi.stateMask = LVIS_STATEIMAGEMASK;
  140. Misc_LV_GetItemInfo(hwnd, &lvi, lvi.iItem, LVIF_STATE);
  141. if (!LV_IsChecked(&lvi)) {
  142.     dwDrives |= 1 << lvi.iItem;
  143. }
  144.     }
  145.     if (pdmi->dwNoDrives != dwDrives) {
  146. DWORD dwChanged;
  147. UINT ui;
  148. TCHAR tszRoot[4];
  149. SetRegDword(g_hkCUSMWCV, c_tszRestrictions, c_tszNoDrives, dwDrives);
  150. /* Recompute GetLogicalDrives() in case new drives are here */
  151. dwChanged = (pdmi->dwNoDrives ^ dwDrives) & GetLogicalDrives();
  152. pdmi->dwNoDrives = dwDrives;
  153. /*
  154.  *  SHCNE_UPDATEDIR doesn't work for CSIDL_DRIVES because
  155.  *  Drivesx.c checks the restrictions only in response to a
  156.  *  SHCNE_ADDDRIVE.  So walk through every drive that changed
  157.  *  and send a SHCNE_DRIVEADD or SHCNE_DRIVEREMOVED for it.
  158.  */
  159. for (ui = 0; ui < 26; ui++) {
  160.     DWORD dwMask = 1 << ui;
  161.     if (dwChanged & dwMask) {
  162. MyComp_BuildRoot(tszRoot, ui);
  163. SHChangeNotify((dwDrives & dwMask) ? SHCNE_DRIVEREMOVED
  164.    : SHCNE_DRIVEADD,
  165.        SHCNF_PATH, tszRoot, 0L);
  166.     }
  167. }
  168. #if 0
  169. if (SUCCEEDED(SHGetSpecialFolderLocation(hdlg, CSIDL_DRIVES, &pidl))) {
  170.     Ole_Free(pidl);
  171. }
  172. #endif
  173.     }
  174. }
  175. /*****************************************************************************
  176.  *
  177.  *  Oh yeah, we need this too.
  178.  *
  179.  *****************************************************************************/
  180. #pragma BEGIN_CONST_DATA
  181. LVV lvvMyComp = {
  182.     0,                          /* MyComp_OnCommand */
  183.     0,
  184.     0,                          /* MyComp_LV_Dirtify */
  185.     MyComp_LV_GetIcon,
  186.     MyComp_OnInitDialog,
  187.     MyComp_OnApply,
  188.     MyComp_OnDestroy,
  189.     0,
  190.     4, /* iMenu */
  191.     rgdwHelp,
  192.     0, /* Double-click action */
  193.     lvvflIcons |                /* We need icons */
  194.     lvvflCanCheck,              /* And check boxes */
  195.     {
  196. { 0, 0 },
  197.     }
  198. };
  199. #pragma END_CONST_DATA
  200. /*****************************************************************************
  201.  *
  202.  *  Our window procedure.
  203.  *
  204.  *****************************************************************************/
  205. BOOL EXPORT
  206. MyComp_DlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam)
  207. {
  208.     return LV_DlgProc(&lvvMyComp, hdlg, wm, wParam, lParam);
  209. }