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.

1144 lines
38 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // File: PROPSEXT.CPP
  4. //
  5. // Implementation of the CPropSheetExt object.
  6. //
  7. //---------------------------------------------------------------------------
  8. #include "precomp.hxx"
  9. #pragma hdrstop
  10. //Defines for getting registry settings
  11. const TCHAR c_szHICKey[] = TEXT("Control Panel\\Desktop\\WindowMetrics"); // show icons using highest possible colors
  12. const TCHAR c_szHICVal[] = TEXT("Shell Icon BPP"); // (4 if the checkbox is false, otherwise 16, don't set it to anything else)
  13. const TCHAR c_szHIKey[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced");
  14. const TCHAR c_szHIVal[] = TEXT("HideIcons");
  15. const TCHAR c_szWMSISVal[] = TEXT("Shell Icon Size"); // Normal Icon Size (default 32 x 32)
  16. const TCHAR c_szTitle[] = TEXT("Effects");
  17. #ifdef INET_EXP_ICON
  18. const TCHAR c_szIEXP[] = TEXT("\\Program Files\\Microsoft Internet Explorer 4");
  19. #endif
  20. #define HSUBKEY_HIC (LPTSTR)c_szHICKey
  21. #define HVALUE_HIC (LPTSTR)c_szHICVal
  22. #define HSUBKEY_WM (LPTSTR)c_szHICKey
  23. #define HVALUE_WMSIS (LPTSTR)c_szWMSISVal
  24. #define ICON_DEFAULT_SMALL 16
  25. #define ICON_DEFAULT_NORMAL 32
  26. #define ICON_DEFAULT_LARGE 48
  27. enum ICON_SIZE_TYPES {
  28. ICON_DEFAULT = 0,
  29. ICON_LARGE = 1,
  30. ICON_INDETERMINATE = 2
  31. };
  32. // Registry Info for the icons
  33. typedef struct tagIconRegKeys
  34. {
  35. TCHAR szIconSubKey[128];
  36. TCHAR szIconValue[16];
  37. TCHAR szTitleSubKey[128];
  38. int iTitleResource;
  39. int iDefaultTitleResource;
  40. BOOL bNTOnly;
  41. }ICONREGKEYS;
  42. ICONREGKEYS sIconRegKeys[] =
  43. {
  44. // "My Computer" icon
  45. { TEXT("CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\DefaultIcon"),
  46. TEXT("\0"),
  47. TEXT("CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}"),
  48. NULL,
  49. IDS_MYCOMPUTER,
  50. FALSE
  51. },
  52. // "My Documents" icon
  53. { TEXT("CLSID\\{450D8FBA-AD25-11D0-98A8-0800361B1103}\\DefaultIcon"),
  54. TEXT("\0"),
  55. TEXT("CLSID\\{450D8FBA-AD25-11D0-98A8-0800361B1103}"),
  56. NULL,
  57. IDS_MYDOCUMENTS,
  58. FALSE
  59. },
  60. // This one doesn't seem to pick up updates, so disable for now...
  61. #ifdef INET_EXP_ICON
  62. // "Internet Explorer" icon
  63. { TEXT("CLSID\\{FBF23B42-E3F0-101B-8488-00AA003E56F8}\\DefaultIcon"),
  64. TEXT("\0"),
  65. TEXT("CLSID\\{FBF23B42-E3F0-101B-8488-00AA003E56F8}"),
  66. NULL,
  67. IDS_INTERNET
  68. },
  69. #endif
  70. // "Net Neighbourhood" icon
  71. { TEXT("CLSID\\{208D2C60-3AEA-1069-A2D7-08002B30309D}\\DefaultIcon"),
  72. TEXT("\0"),
  73. TEXT("CLSID\\{208D2C60-3AEA-1069-A2D7-08002B30309D}"),
  74. NULL,
  75. IDS_NETNEIGHBOUR
  76. },
  77. // "Trash full" icon
  78. { TEXT("CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon"),
  79. TEXT("full"),
  80. TEXT("CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}"),
  81. IDS_FULL,
  82. IDS_TRASHFULL
  83. },
  84. // "Trash empty" icon
  85. { TEXT("CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon"),
  86. TEXT("empty"),
  87. TEXT("CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}"),
  88. IDS_EMPTY,
  89. IDS_TRASHEMPTY
  90. },
  91. //
  92. // This is not a desktop icon, so for now it's not included.
  93. //
  94. /*
  95. // "Directory" icon
  96. { TEXT("CLSID\\{FE1290F0-CFBD-11CF-A330-00AA00C16E65}\\DefaultIcon"),
  97. TEXT("\0"),
  98. TEXT("CLSID\\{FE1290F0-CFBD-11CF-A330-00AA00C16E65}"),
  99. NULL,
  100. IDS_DIRECTORY
  101. },
  102. */
  103. };
  104. #define NUM_ICONS (ARRAYSIZE(sIconRegKeys))
  105. #define PATH_WIN 0
  106. #define PATH_SYS 1
  107. #define PATH_IEXP 2
  108. typedef struct tagDefIcons
  109. {
  110. int iIndex;
  111. UINT uPath;
  112. TCHAR szFile[16];
  113. }DEFICONS;
  114. DEFICONS sDefaultIcons[NUM_ICONS] =
  115. {
  116. { 0,PATH_WIN ,TEXT("\\EXPLORER.EXE")}, // "My Computer" default icon
  117. { 0,PATH_SYS ,TEXT("\\mydocs.dll")}, // "My Documents" default icon
  118. #ifdef INET_EXP_ICON
  119. { 0,PATH_IEXP,TEXT("\\iexplore.exe")}, // "Internet Explorer" default icon
  120. #endif
  121. {17,PATH_SYS, TEXT("\\shell32.dll")}, // "Net Neighbourhood" default icon
  122. {32,PATH_SYS, TEXT("\\shell32.dll")}, // "Trash full" default icon
  123. {31,PATH_SYS, TEXT("\\shell32.dll")}, // "Trash empty" default icon
  124. // { 0,TEXT("\\dsfolder.dll")}, // "Directory" default icon
  125. };
  126. // Name of the file that holds each icon, and an index for which icon to use in the file
  127. typedef struct tagIconKeys
  128. {
  129. TCHAR szOldFile[MAX_PATH];
  130. int iOldIndex;
  131. TCHAR szNewFile[MAX_PATH];
  132. int iNewIndex;
  133. }ICONDATA;
  134. ICONDATA sIconData[NUM_ICONS];
  135. typedef struct
  136. {
  137. DWORD dwControlID;
  138. DWORD dwHelpContextID;
  139. }POPUP_HELP_ARRAY;
  140. POPUP_HELP_ARRAY phaMainWin[] = {
  141. { (DWORD)IDC_ICONS, (DWORD)IDH_DISPLAY_PLUSPACK_LIST },
  142. { (DWORD)IDC_CHANGEICON, (DWORD)IDH_DISPLAY_PLUSPACK_CHANGEICON },
  143. { (DWORD)IDC_LARGEICONS, (DWORD)IDH_DISPLAY_PLUSPACK_LARGEICONS },
  144. { (DWORD)IDC_ICONHIGHCOLOR, (DWORD)IDH_DISPLAY_PLUSPACK_ALLCOLORS },
  145. { (DWORD)IDC_ICONDEFAULT, (DWORD)IDH_DISPLAY_PLUSPACK_DEFAULT_ICON },
  146. { (DWORD)IDC_GRPBOX_1, (DWORD)IDH_COMM_GROUPBOX },
  147. { (DWORD)IDC_GRPBOX_2, (DWORD)IDH_COMM_GROUPBOX },
  148. { (DWORD)0, (DWORD)0 },
  149. { (DWORD)0, (DWORD)0 }, // double-null terminator NECESSARY!
  150. };
  151. POPUP_HELP_ARRAY phaMainWinPlus[] = {
  152. { (DWORD)IDC_ICONS, (DWORD)IDH_PLUS_PLUSPACK_LIST },
  153. { (DWORD)IDC_CHANGEICON, (DWORD)IDH_PLUS_PLUSPACK_CHANGEICON },
  154. { (DWORD)IDC_LARGEICONS, (DWORD)IDH_PLUS_PLUSPACK_LARGEICONS },
  155. { (DWORD)IDC_ICONHIGHCOLOR, (DWORD)IDH_PLUS_PLUSPACK_ALLCOLORS },
  156. { (DWORD)IDC_GRPBOX_1, (DWORD)IDH_COMM_GROUPBOX },
  157. { (DWORD)IDC_GRPBOX_2, (DWORD)IDH_COMM_GROUPBOX },
  158. { (DWORD)0, (DWORD)0 },
  159. { (DWORD)0, (DWORD)0 }, // double-null terminator NECESSARY!
  160. };
  161. POPUP_HELP_ARRAY * g_phaHelp = NULL;
  162. HWND hWndList; // handle to the list view window
  163. HIMAGELIST hIconList; // handles to image lists for large icons
  164. // Handle to the DLL
  165. extern HINSTANCE g_hInst;
  166. // vars needed for new shell api
  167. #define SZ_SHELL32 TEXT("shell32.dll")
  168. #define SZ_SHUPDATERECYCLEBINICON "SHUpdateRecycleBinIcon" // Parameter for GetProcAddr()... DO NOT TEXT("") IT!
  169. HINSTANCE hmodShell32 = NULL;
  170. typedef void (* PFNSHUPDATERECYCLEBINICON)( void );
  171. PFNSHUPDATERECYCLEBINICON pfnSHUpdateRecycleBinIcon = NULL;
  172. // Function prototype
  173. INT_PTR CALLBACK PlusPackDlgProc( HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam );
  174. HWND CreateListView( HWND hWndParent );
  175. // Icon Stuff
  176. int GetIconState (void);
  177. BOOL ChangeIconSizes (HWND hDlg, int iOldState, int iNewState);
  178. HRESULT ExtractPlusColorIcon(LPCTSTR szPath, int nIndex, HICON *phIcon, UINT uSizeLarge, UINT uSizeSmall);
  179. BOOL gfCoInitDone = FALSE; // track state of OLE CoInitialize()
  180. //---------------------------------------------------------------------------
  181. // Class Member functions
  182. //---------------------------------------------------------------------------
  183. //---------------------------------------------------------------------------
  184. // Constructor
  185. //---------------------------------------------------------------------------
  186. CPropSheetExt::CPropSheetExt( LPUNKNOWN pUnkOuter, LPFNDESTROYED pfnDestroy )
  187. {
  188. m_cRef = 0;
  189. m_pUnkOuter = pUnkOuter;
  190. m_pfnDestroy = pfnDestroy;
  191. return;
  192. }
  193. //---------------------------------------------------------------------------
  194. // Destructor
  195. //---------------------------------------------------------------------------
  196. CPropSheetExt::~CPropSheetExt( void )
  197. {
  198. return;
  199. }
  200. //---------------------------------------------------------------------------
  201. // QueryInterface()
  202. //---------------------------------------------------------------------------
  203. STDMETHODIMP CPropSheetExt::QueryInterface( REFIID riid, LPVOID* ppv )
  204. {
  205. *ppv = NULL;
  206. if( IsEqualIID( riid, IID_IShellPropSheetExt ) )
  207. {
  208. *ppv = (LPVOID)this;
  209. ++m_cRef;
  210. return NOERROR;
  211. }
  212. return ResultFromScode(E_NOINTERFACE);
  213. }
  214. //---------------------------------------------------------------------------
  215. // AddRef()
  216. //---------------------------------------------------------------------------
  217. STDMETHODIMP_(ULONG) CPropSheetExt::AddRef( void )
  218. {
  219. return ++m_cRef;
  220. }
  221. //---------------------------------------------------------------------------
  222. // Release()
  223. //---------------------------------------------------------------------------
  224. STDMETHODIMP_(ULONG) CPropSheetExt::Release( void )
  225. {
  226. ULONG cRefT;
  227. cRefT = --m_cRef;
  228. if( m_cRef == 0 )
  229. {
  230. // Tell the housing that an object is going away so that it
  231. // can shut down if appropriate.
  232. if( NULL != m_pfnDestroy )
  233. {
  234. (*m_pfnDestroy)();
  235. }
  236. delete this;
  237. }
  238. return cRefT;
  239. }
  240. //---------------------------------------------------------------------------
  241. // AddPages()
  242. //---------------------------------------------------------------------------
  243. STDMETHODIMP CPropSheetExt::AddPages( LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam )
  244. {
  245. PROPSHEETPAGE psp;
  246. HPROPSHEETPAGE hpage;
  247. TCHAR szTitle[ 30 ];
  248. LoadString( g_hInst, IDS_ICONS, szTitle, ARRAYSIZE(szTitle) );
  249. psp.dwSize = sizeof(PROPSHEETPAGE);
  250. psp.dwFlags = PSP_USETITLE;
  251. psp.hIcon = NULL;
  252. psp.hInstance = g_hInst;
  253. psp.pszTemplate =MAKEINTRESOURCE( PLUSPACK_DLG );
  254. psp.pfnDlgProc = PlusPackDlgProc;
  255. psp.pszTitle = szTitle;
  256. psp.lParam = 0;
  257. if( ( hpage = CreatePropertySheetPage( &psp ) ) == NULL )
  258. {
  259. return ( E_OUTOFMEMORY );
  260. }
  261. if( !lpfnAddPage( hpage, lParam ) )
  262. {
  263. DestroyPropertySheetPage( hpage );
  264. return ( E_FAIL );
  265. }
  266. return NOERROR;
  267. }
  268. //---------------------------------------------------------------------------
  269. // ReplacePage()
  270. //---------------------------------------------------------------------------
  271. STDMETHODIMP CPropSheetExt::ReplacePage( UINT uPageID, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam )
  272. {
  273. return NOERROR;
  274. }
  275. //---------------------------------------------------------------------------
  276. //
  277. // PlusPackDlgProc()
  278. //
  279. // The dialog procedure for the "PlusPack" property sheet page.
  280. //
  281. //---------------------------------------------------------------------------
  282. INT_PTR CALLBACK PlusPackDlgProc( HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam )
  283. {
  284. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE)GetWindowLong( hDlg, DWL_USER );
  285. static int iOldLI, iNewLI; // Large Icon State
  286. static int iOldHIC, iNewHIC; // High Icon Colour
  287. static BOOL bOldMA, bNewMA; // Menu Animation State
  288. static BOOL bOldSF, bNewSF; // Font Smoothing State
  289. static BOOL bOldDW, bNewDW; // Drag Window State
  290. static BOOL bOldHI, bNewHI; // Hide Icons State
  291. BOOL bDorked = FALSE, bRet, bDorkedIcons;
  292. static int iIndex, iX;
  293. static char szHelpFile[32];
  294. switch( uMessage )
  295. {
  296. case WM_INITDIALOG:
  297. {
  298. OSVERSIONINFO osvi;
  299. UINT id = IDS_HELPFILE_PLUS;
  300. // Create our list view and fill it with the system icons
  301. CreateListView( hDlg );
  302. iIndex = 0;
  303. SetWindowLong( hDlg, DWL_USER, lParam );
  304. psp = (LPPROPSHEETPAGE)lParam;
  305. // Get the name of our help file. For Memphis, it's
  306. // IDS_HELPFILE_PLUS for NT it's IDS_HELPFILE.
  307. g_phaHelp = phaMainWinPlus;
  308. osvi.dwOSVersionInfoSize = sizeof(osvi);
  309. if (GetVersionEx( &osvi ))
  310. {
  311. if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
  312. {
  313. id = IDS_HELPFILE;
  314. g_phaHelp = phaMainWin;
  315. }
  316. }
  317. LoadString( g_hInst, id, szHelpFile, 32 );
  318. // Get the values for the settings from the registry and set the checkboxes
  319. // Large Icons
  320. iOldLI = GetIconState ();
  321. if (iOldLI == ICON_INDETERMINATE)
  322. {
  323. HWND hItem = GetDlgItem (hDlg, IDC_LARGEICONS);
  324. SendMessage( hItem,
  325. BM_SETSTYLE,
  326. (WPARAM)LOWORD(BS_AUTO3STATE),
  327. MAKELPARAM( FALSE,0)
  328. );
  329. }
  330. iNewLI = iOldLI;
  331. SendMessage( (HWND)GetDlgItem( hDlg, IDC_LARGEICONS ),
  332. BM_SETCHECK,
  333. (WPARAM)iOldLI,
  334. 0
  335. );
  336. // Full Color Icons
  337. bRet = GetRegValueInt( HKEY_CURRENT_USER,
  338. HSUBKEY_HIC,
  339. HVALUE_HIC,
  340. &iOldHIC
  341. );
  342. if( bRet == FALSE ) // Key not in registry yet
  343. {
  344. iOldHIC = iNewHIC = 4;
  345. }
  346. iNewHIC = iOldHIC;
  347. SendMessage( (HWND)GetDlgItem( hDlg, IDC_ICONHIGHCOLOR ),
  348. BM_SETCHECK,
  349. (WPARAM)(BOOL)(iOldHIC == 16),
  350. 0
  351. );
  352. // Hide Icons
  353. bOldHI = (BOOL)GetRegValueDword( HKEY_CURRENT_USER,
  354. (LPTSTR)c_szHIKey,
  355. (LPTSTR)c_szHIVal
  356. );
  357. if (bOldHI == REG_BAD_DWORD)
  358. {
  359. bOldHI = FALSE;
  360. }
  361. SendMessage( (HWND)GetDlgItem( hDlg, IDC_HIDEICONS ),
  362. BM_SETCHECK,
  363. (WPARAM)bOldHI,
  364. 0
  365. );
  366. bNewHI = bOldHI;
  367. // Use menu animations
  368. bOldMA = FALSE;
  369. SystemParametersInfo( SPI_GETMENUANIMATION, 0, (PVOID)&bOldMA, 0 );
  370. SendMessage( (HWND)GetDlgItem( hDlg, IDC_MENUANIMATION ),
  371. BM_SETCHECK,
  372. (WPARAM)bOldMA,
  373. 0
  374. );
  375. bNewMA = bOldMA;
  376. // Smooth edges of screen fonts
  377. bOldSF = FALSE;
  378. SystemParametersInfo( SPI_GETFONTSMOOTHING, 0, (PVOID)&bOldSF, 0 );
  379. SendMessage( (HWND)GetDlgItem( hDlg, IDC_FONTSMOOTH ),
  380. BM_SETCHECK,
  381. (WPARAM)bOldSF,
  382. 0
  383. );
  384. bNewSF = bOldSF;
  385. // Show contents while dragging
  386. bOldDW = FALSE;
  387. SystemParametersInfo( SPI_GETDRAGFULLWINDOWS, 0, (PVOID)&bOldDW, 0 );
  388. SendMessage( (HWND)GetDlgItem( hDlg, IDC_SHOWDRAG ),
  389. BM_SETCHECK,
  390. (WPARAM)bOldDW,
  391. 0
  392. );
  393. bNewDW = bOldDW;
  394. // Load SHUpdateRecycleBinIcon() if it exists
  395. hmodShell32 = LoadLibrary(SZ_SHELL32);
  396. pfnSHUpdateRecycleBinIcon = (PFNSHUPDATERECYCLEBINICON)GetProcAddress( hmodShell32, SZ_SHUPDATERECYCLEBINICON );
  397. }
  398. break;
  399. case WM_DESTROY:
  400. if ( gfCoInitDone )
  401. CoUninitialize();
  402. if (hmodShell32)
  403. FreeLibrary(hmodShell32);
  404. break;
  405. case WM_COMMAND:
  406. switch( LOWORD(wParam) )
  407. {
  408. case IDC_LARGEICONS:
  409. iNewLI = SendMessage ( (HWND)lParam, BM_GETCHECK, 0, 0 );
  410. bDorked = TRUE;
  411. break;
  412. case IDC_ICONHIGHCOLOR:
  413. iNewHIC = 4;
  414. if( SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == TRUE )
  415. {
  416. iNewHIC = 16;
  417. }
  418. bDorked = TRUE;
  419. break;
  420. case IDC_SHOWDRAG:
  421. bNewDW = (SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == BST_CHECKED);
  422. bDorked = TRUE;
  423. break;
  424. case IDC_HIDEICONS:
  425. bNewHI = (SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == BST_CHECKED);
  426. bDorked = TRUE;
  427. break;
  428. case IDC_MENUANIMATION:
  429. bNewMA = (SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == BST_CHECKED);
  430. bDorked = TRUE;
  431. break;
  432. case IDC_FONTSMOOTH:
  433. bNewSF = (SendMessage( (HWND)lParam, BM_GETCHECK, 0, 0 ) == BST_CHECKED);
  434. bDorked = TRUE;
  435. break;
  436. case IDC_CHANGEICON:
  437. {
  438. INT i = sIconData[iIndex].iOldIndex;
  439. WCHAR szTemp[ MAX_PATH ];
  440. TCHAR szExp[ MAX_PATH ];
  441. ExpandEnvironmentStrings( sIconData[iIndex].szOldFile,
  442. szExp,
  443. ARRAYSIZE(szExp)
  444. );
  445. if (g_RunningOnNT)
  446. {
  447. MultiByteToWideChar( CP_ACP, 0, szExp, -1, szTemp, ARRAYSIZE(szTemp) );
  448. }
  449. else
  450. {
  451. lstrcpy( (LPTSTR)szTemp, szExp );
  452. }
  453. if ( PickIconDlg( hDlg,
  454. (LPTSTR)szTemp,
  455. ARRAYSIZE(szTemp),
  456. &i
  457. ) == TRUE
  458. )
  459. {
  460. HICON hIcon;
  461. if (g_RunningOnNT)
  462. {
  463. WideCharToMultiByte( CP_ACP, 0,
  464. szTemp, -1,
  465. sIconData[iIndex].szNewFile,
  466. ARRAYSIZE(sIconData[iIndex].szNewFile),
  467. NULL, NULL
  468. );
  469. }
  470. else
  471. {
  472. lstrcpy( sIconData[iIndex].szNewFile, (LPTSTR)szTemp );
  473. }
  474. sIconData[iIndex].iNewIndex = i;
  475. ExtractPlusColorIcon( sIconData[iIndex].szNewFile,
  476. sIconData[iIndex].iNewIndex,
  477. &hIcon,
  478. 0,
  479. 0
  480. );
  481. ImageList_ReplaceIcon( hIconList, iIndex, hIcon );
  482. ListView_RedrawItems( hWndList, iIndex, iIndex );
  483. bDorked = TRUE;
  484. }
  485. }
  486. break;
  487. case IDC_ICONDEFAULT:
  488. {
  489. TCHAR szTemp[_MAX_PATH];
  490. HICON hIcon;
  491. switch( sDefaultIcons[iIndex].uPath )
  492. {
  493. case PATH_WIN:
  494. GetWindowsDirectory( szTemp, ARRAYSIZE(szTemp) );
  495. break;
  496. #ifdef INET_EXP_ICON
  497. case PATH_IEXP:
  498. if (g_RunningOnNT)
  499. {
  500. lstrcpy( szTemp, TEXT("%SystemDrive%") );
  501. }
  502. else
  503. {
  504. GetWindowsDirectory( szTemp, ARRAYSIZE(szTemp) );
  505. //
  506. // Clear out path after drive, ie: C:
  507. //
  508. szTemp[ 2 ] = 0;
  509. }
  510. lstrcat( szTemp, c_szIEXP );
  511. break;
  512. #endif
  513. case PATH_SYS:
  514. default:
  515. GetSystemDirectory( szTemp, ARRAYSIZE(szTemp) );
  516. break;
  517. }
  518. lstrcat( szTemp, sDefaultIcons[iIndex].szFile );
  519. lstrcpy( sIconData[iIndex].szNewFile, szTemp );
  520. sIconData[iIndex].iNewIndex = sDefaultIcons[iIndex].iIndex;
  521. ExtractPlusColorIcon( sIconData[iIndex].szNewFile,
  522. sIconData[iIndex].iNewIndex,
  523. &hIcon,
  524. 0,
  525. 0
  526. );
  527. ImageList_ReplaceIcon( hIconList, iIndex, hIcon );
  528. ListView_RedrawItems( hWndList, iIndex, iIndex );
  529. bDorked = TRUE;
  530. }
  531. break;
  532. default:
  533. break;
  534. }
  535. // If the user dorked with a setting, tell the property manager we
  536. // have outstanding changes. This will enable the "Apply Now" button...
  537. if( bDorked )
  538. {
  539. SendMessage( GetParent( hDlg ), PSM_CHANGED, (WPARAM)hDlg, 0L );
  540. }
  541. break;
  542. case WM_NOTIFY:
  543. switch( ((NMHDR *)lParam)->code )
  544. {
  545. case LVN_ITEMCHANGED: // The selection changed in our listview
  546. if( wParam == IDC_ICONS )
  547. {
  548. BOOL bEnable = FALSE;
  549. // Find out who's selected now
  550. for( iIndex = 0; iIndex < NUM_ICONS;iIndex++ )
  551. {
  552. if( ListView_GetItemState( hWndList, iIndex, LVIS_SELECTED ) )
  553. {
  554. bEnable = TRUE;
  555. break;
  556. }
  557. }
  558. EnableWindow( GetDlgItem( hDlg, IDC_CHANGEICON ), bEnable );
  559. EnableWindow( GetDlgItem( hDlg, IDC_ICONDEFAULT ), bEnable );
  560. }
  561. break;
  562. case PSN_APPLY: // OK or Apply clicked
  563. {
  564. HDC hDC = GetDC( NULL );
  565. int iBitsPerPixel;
  566. iBitsPerPixel = GetDeviceCaps( hDC, BITSPIXEL );
  567. ReleaseDC( NULL, hDC );
  568. // Large Icons
  569. bDorkedIcons = ChangeIconSizes (hDlg, iOldLI, iNewLI);
  570. if (bDorkedIcons)
  571. {
  572. iOldLI = iNewLI;
  573. bDorked = TRUE;
  574. }
  575. // Full Color Icons
  576. if( iOldHIC != iNewHIC )
  577. {
  578. TCHAR szTemp1[512];
  579. TCHAR szTemp2[256];
  580. bRet = SetRegValueInt( HKEY_CURRENT_USER,
  581. HSUBKEY_HIC,
  582. HVALUE_HIC,
  583. iNewHIC
  584. );
  585. iOldHIC = iNewHIC;
  586. if ((iBitsPerPixel < 16) && (iNewHIC == 16)) // Display mode won't support icon high colors
  587. {
  588. LoadString (g_hInst, IDS_256COLORPROBLEM, szTemp1, ARRAYSIZE(szTemp1) );
  589. LoadString( g_hInst, IDS_ICONCOLORWONTWORK, szTemp2, ARRAYSIZE(szTemp2) );
  590. lstrcat (szTemp1, szTemp2);
  591. MessageBox( hDlg, szTemp1, c_szTitle, MB_OK );
  592. }
  593. else
  594. {
  595. LoadString( g_hInst, IDS_REBOOTFORCHANGE, szTemp1, ARRAYSIZE(szTemp1) );
  596. MessageBox( hDlg, szTemp1, c_szTitle, MB_OK );
  597. }
  598. }
  599. // Full window drag
  600. if ( bOldDW != bNewDW )
  601. {
  602. bOldDW = bNewDW;
  603. SystemParametersInfo( SPI_SETDRAGFULLWINDOWS,
  604. bNewDW,
  605. NULL,
  606. SPIF_SENDCHANGE
  607. );
  608. }
  609. // Font smoothing
  610. if ( bOldSF != bNewSF )
  611. {
  612. bOldSF = bNewSF;
  613. SystemParametersInfo( SPI_SETFONTSMOOTHING,
  614. bNewSF,
  615. NULL,
  616. SPIF_SENDCHANGE
  617. );
  618. }
  619. // Menu animations
  620. if ( bOldMA != bNewMA )
  621. {
  622. bOldMA = bNewMA;
  623. SystemParametersInfo( SPI_SETMENUANIMATION,
  624. bNewMA,
  625. NULL,
  626. SPIF_SENDCHANGE
  627. );
  628. }
  629. // Hide Icons
  630. if ( bOldHI != bNewHI )
  631. {
  632. bOldHI = bNewHI;
  633. SetRegValueDword( HKEY_CURRENT_USER,
  634. (LPTSTR)c_szHIKey,
  635. (LPTSTR)c_szHIVal,
  636. (DWORD)bNewHI
  637. );
  638. }
  639. // Change the system icons
  640. for( iX = 0;iX < NUM_ICONS;iX++ )
  641. {
  642. if( (lstrcmpi( sIconData[iX].szNewFile, sIconData[iX].szOldFile ) != 0) ||
  643. (sIconData[iX].iNewIndex != sIconData[iX].iOldIndex)
  644. )
  645. {
  646. TCHAR szTemp[MAX_PATH];
  647. wsprintf( szTemp,
  648. TEXT("%s,%d"),
  649. sIconData[iX].szNewFile,
  650. sIconData[iX].iNewIndex
  651. );
  652. bRet = IconSetRegValueString( sIconRegKeys[iX].szIconSubKey,
  653. sIconRegKeys[iX].szIconValue,
  654. (LPTSTR)szTemp
  655. );
  656. // Next two lines necessary if the user does an Apply as opposed to OK
  657. lstrcpy( sIconData[iX].szOldFile, sIconData[iX].szNewFile );
  658. sIconData[iX].iOldIndex = sIconData[iX].iNewIndex;
  659. bDorked = TRUE;
  660. }
  661. }
  662. // Make the system notice we changed the system icons
  663. if( bDorked )
  664. {
  665. SHChangeNotify( SHCNE_ASSOCCHANGED, 0, NULL, NULL ); // should do the trick!
  666. if (pfnSHUpdateRecycleBinIcon != NULL)
  667. {
  668. pfnSHUpdateRecycleBinIcon();
  669. }
  670. }
  671. if (bDorkedIcons)
  672. {
  673. SendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
  674. }
  675. break;
  676. }
  677. default:
  678. break;
  679. }
  680. break;
  681. case WM_HELP:
  682. {
  683. LPHELPINFO lphi = (LPHELPINFO)lParam;
  684. if( lphi->iContextType == HELPINFO_WINDOW )
  685. {
  686. WinHelp( (HWND)lphi->hItemHandle,
  687. (LPTSTR)szHelpFile,
  688. HELP_WM_HELP,
  689. (DWORD)((POPUP_HELP_ARRAY FAR *)g_phaHelp)
  690. );
  691. }
  692. }
  693. break;
  694. case WM_CONTEXTMENU:
  695. // first check for dlg window
  696. if( (HWND)wParam == hDlg )
  697. {
  698. // let the def dlg proc decide whether to respond or ignore;
  699. // necessary for title bar sys menu on right click
  700. return FALSE; // didn't process message EXIT
  701. }
  702. else
  703. {
  704. // else go for the controls
  705. WinHelp( (HWND)wParam,
  706. (LPTSTR)szHelpFile,
  707. HELP_CONTEXTMENU,
  708. (DWORD)((POPUP_HELP_ARRAY FAR *)g_phaHelp)
  709. );
  710. }
  711. break;
  712. default:
  713. return FALSE;
  714. }
  715. return(TRUE);
  716. }
  717. /****************************************************************************
  718. *
  719. * FUNCTION: CreateListView(HWND)
  720. *
  721. * PURPOSE: Creates the list view window and initializes it
  722. *
  723. ****************************************************************************/
  724. HWND CreateListView( HWND hWndParent )
  725. {
  726. LV_ITEM lvI; // List view item structure
  727. TCHAR szTemp[MAX_PATH];
  728. BOOL bEnable = FALSE;
  729. RECT rc;
  730. // Create a device independant size and location
  731. LONG lWndunits = GetDialogBaseUnits();
  732. int iWndx = LOWORD(lWndunits);
  733. int iWndy = HIWORD(lWndunits);
  734. int iX = ((11 * iWndx) / 4);
  735. int iY = ((15 * iWndy) / 8);
  736. int iWidth = ((163 * iWndx) / 4);
  737. int iHeight = ((40 * iWndy) / 8);
  738. // Ensure that the common control DLL is loaded.
  739. InitCommonControls();
  740. // Get the list view window
  741. hWndList = GetDlgItem (hWndParent, IDC_ICONS);
  742. if( hWndList == NULL )
  743. return NULL;
  744. // initialize the list view window
  745. // First, initialize the image lists we will need
  746. hIconList = ImageList_Create( 32, 32, ILC_MASK | ILC_COLOR24, NUM_ICONS, 0 ); // create an image list for the icons
  747. // load the icons and add them to the image lists
  748. // get the icon files and indexes from the registry, including for the Default recycle bin
  749. for( iX = 0; iX < NUM_ICONS; iX++ )
  750. {
  751. TCHAR* pPos;
  752. HICON hIcon;
  753. BOOL bRet;
  754. bRet = IconGetRegValueString( sIconRegKeys[iX].szIconSubKey,
  755. sIconRegKeys[iX].szIconValue,
  756. (LPSTR)szTemp,
  757. MAX_PATH
  758. );
  759. int iIndex = PathParseIconLocation( szTemp );
  760. // store the icon information
  761. lstrcpy( sIconData[iX].szOldFile, szTemp );
  762. lstrcpy( sIconData[iX].szNewFile, szTemp );
  763. sIconData[iX].iOldIndex = iIndex;
  764. sIconData[iX].iNewIndex = iIndex;
  765. ExtractPlusColorIcon( szTemp, iIndex, &hIcon, 0, 0);
  766. // Added this "if" to fix bug 2831. We want to use SHELL32.DLL
  767. // icon 0 if there is no icon in the file specified in the
  768. // registry (or if the registry didn't specify a file).
  769. if( hIcon == NULL )
  770. {
  771. GetSystemDirectory( szTemp, sizeof(szTemp) );
  772. lstrcat( szTemp, TEXT("\\shell32.dll") );
  773. lstrcpy( sIconData[iX].szOldFile, szTemp );
  774. lstrcpy( sIconData[iX].szNewFile, szTemp );
  775. sIconData[iX].iOldIndex = sIconData[iX].iNewIndex = 0;
  776. hIcon = ExtractIcon( g_hInst, szTemp, iIndex );
  777. }
  778. if (ImageList_AddIcon( hIconList, hIcon ) == -1)
  779. {
  780. return NULL;
  781. }
  782. }
  783. // Make sure that all of the icons were added
  784. if( ImageList_GetImageCount( hIconList ) < NUM_ICONS )
  785. return FALSE;
  786. ListView_SetImageList( hWndList, hIconList, LVSIL_NORMAL );
  787. // Make sure the listview has WS_HSCROLL set on it.
  788. DWORD dwStyle = GetWindowLong( hWndList, GWL_STYLE );
  789. SetWindowLong( hWndList, GWL_STYLE, (dwStyle & (~WS_VSCROLL)) | WS_HSCROLL );
  790. // Finally, let's add the actual items to the control. Fill in the LV_ITEM
  791. // structure for each of the items to add to the list. The mask specifies
  792. // the the .pszText, .iImage, and .state members of the LV_ITEM structure are valid.
  793. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
  794. lvI.state = 0;
  795. lvI.stateMask = 0;
  796. for( iX = 0; iX < NUM_ICONS; iX++ )
  797. {
  798. TCHAR szAppend[64];
  799. BOOL bRet;
  800. bRet = IconGetRegValueString( sIconRegKeys[iX].szTitleSubKey,
  801. NULL,
  802. (LPTSTR)szTemp,
  803. MAX_PATH
  804. );
  805. // if the title string was in the registry, else we have to use the default in our resources
  806. if( (bRet) && (lstrlen(szTemp) > 0) )
  807. {
  808. if( LoadString( g_hInst, sIconRegKeys[iX].iTitleResource, szAppend, 64 ) != 0 )
  809. {
  810. lstrcat( szTemp, szAppend );
  811. }
  812. }
  813. else
  814. {
  815. LoadString( g_hInst,
  816. sIconRegKeys[iX].iDefaultTitleResource,
  817. szTemp,
  818. MAX_PATH
  819. );
  820. }
  821. lvI.iItem = iX;
  822. lvI.iSubItem = 0;
  823. lvI.pszText = (LPSTR)&(szTemp);
  824. lvI.cchTextMax = lstrlen(szTemp);
  825. lvI.iImage = iX;
  826. if( ListView_InsertItem( hWndList, &lvI ) == -1 )
  827. return NULL;
  828. }
  829. /*
  830. // To fix long standing listview bug, we need to "jiggle" the listview
  831. // window size so that it will do a recompute and realize that we need a
  832. // scroll bar...
  833. GetWindowRect( hWndList, &rc );
  834. MapWindowPoints( NULL, hWndParent, (LPPOINT)&rc, 2 );
  835. MoveWindow( hWndList, rc.left, rc.top, rc.right - rc.left+1, rc.bottom - rc.top, FALSE );
  836. MoveWindow( hWndList, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE );
  837. */
  838. // Set First item to selected
  839. ListView_SetItemState (hWndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  840. // Get Selected item
  841. for(int iIndex = 0;iIndex < NUM_ICONS;iIndex++ )
  842. {
  843. if( ListView_GetItemState( hWndList, iIndex, LVIS_SELECTED ) )
  844. {
  845. bEnable = TRUE;
  846. break;
  847. }
  848. }
  849. EnableWindow( GetDlgItem( hWndParent, IDC_CHANGEICON ), bEnable );
  850. EnableWindow( GetDlgItem( hWndParent, IDC_ICONDEFAULT ), bEnable );
  851. return (hWndList);
  852. }
  853. int GetIconState (void)
  854. {
  855. BOOL bRet;
  856. int iSize;
  857. bRet = GetRegValueInt (HKEY_CURRENT_USER, HSUBKEY_WM, HVALUE_WMSIS, &iSize);
  858. if (bRet == FALSE)
  859. return ICON_DEFAULT;
  860. if (iSize == ICON_DEFAULT_NORMAL)
  861. return ICON_DEFAULT;
  862. else if (iSize == ICON_DEFAULT_LARGE)
  863. return ICON_LARGE;
  864. return ICON_INDETERMINATE;
  865. }
  866. BOOL ChangeIconSizes (HWND hDlg, int iOldState, int iNewState)
  867. {
  868. BOOL bRet;
  869. int iOldSize, iNewSize;
  870. int iHorz;
  871. int iVert;
  872. // Don't bother if nothing changed
  873. if (iOldState == iNewState)
  874. return FALSE;
  875. // Get New Size
  876. switch (iNewState)
  877. {
  878. case ICON_DEFAULT:
  879. iNewSize = ICON_DEFAULT_NORMAL;
  880. break;
  881. case ICON_LARGE:
  882. iNewSize = ICON_DEFAULT_LARGE;
  883. break;
  884. case ICON_INDETERMINATE:
  885. // Don't bother to change anything
  886. return FALSE;
  887. default:
  888. return FALSE;
  889. }
  890. // Get Original Size
  891. bRet = GetRegValueInt (HKEY_CURRENT_USER, HSUBKEY_WM, HVALUE_WMSIS, &iOldSize);
  892. if (!bRet)
  893. {
  894. // Try geting system default instead
  895. iOldSize = GetSystemMetrics (SM_CXICON);
  896. }
  897. // Don't need to change size if nothing has really changed
  898. if (iNewSize == iOldSize)
  899. return FALSE;
  900. // Get new horizontal spacing
  901. iHorz = GetSystemMetrics (SM_CXICONSPACING);
  902. iHorz -= iOldSize;
  903. if (iHorz < 0)
  904. {
  905. iHorz = 0;
  906. }
  907. iHorz += iNewSize;
  908. // Get new vertical spacing
  909. iVert = GetSystemMetrics (SM_CYICONSPACING);
  910. iVert -= iOldSize;
  911. if (iVert < 0)
  912. {
  913. iVert = 0;
  914. }
  915. iVert += iNewSize;
  916. // Set New sizes and spacing
  917. bRet = SetRegValueInt( HKEY_CURRENT_USER, HSUBKEY_WM, HVALUE_WMSIS, iNewSize );
  918. if (!bRet)
  919. return FALSE;
  920. SystemParametersInfo( SPI_ICONHORIZONTALSPACING, (WPARAM)iHorz, NULL, SPIF_UPDATEINIFILE );
  921. SystemParametersInfo( SPI_ICONVERTICALSPACING, (WPARAM)iVert, NULL, SPIF_UPDATEINIFILE );
  922. // Turn from Tri-State back to normal check box
  923. if (iOldState == ICON_INDETERMINATE)
  924. {
  925. HWND hItem = GetDlgItem (hDlg, IDC_LARGEICONS);
  926. SendMessage( hItem,
  927. BM_SETSTYLE,
  928. (WPARAM)LOWORD(BS_AUTOCHECKBOX),
  929. MAKELPARAM( FALSE,0)
  930. );
  931. }
  932. // We did change the sizes
  933. return TRUE;
  934. }
  935. //
  936. // ExtractPlusColorIcon
  937. //
  938. // Extract Icon from a file in proper Hi or Lo color for current system display
  939. //
  940. // from FrancisH on 6/22/95 with mods by TimBragg
  941. HRESULT ExtractPlusColorIcon( LPCTSTR szPath, int nIndex, HICON *phIcon,
  942. UINT uSizeLarge, UINT uSizeSmall)
  943. {
  944. IShellLink *psl;
  945. HRESULT hres;
  946. HICON hIcons[2]; // MUST! - provide for TWO return icons
  947. if ( !gfCoInitDone )
  948. {
  949. if (SUCCEEDED(CoInitialize(NULL)))
  950. gfCoInitDone = TRUE;
  951. }
  952. *phIcon = NULL;
  953. if (SUCCEEDED(hres = CoCreateInstance(CLSID_ShellLink, NULL,
  954. CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl)))
  955. {
  956. if (SUCCEEDED(hres = psl->SetIconLocation(szPath, nIndex)))
  957. {
  958. IExtractIcon *pei;
  959. if (SUCCEEDED(hres = psl->QueryInterface(IID_IExtractIcon, (void**)&pei)))
  960. {
  961. if (SUCCEEDED(hres = pei->Extract(szPath, nIndex,
  962. &hIcons[0], &hIcons[1], (UINT)MAKEWPARAM((WORD)uSizeLarge,
  963. (WORD)uSizeSmall))))
  964. {
  965. *phIcon = hIcons[0]; // Return first icon to caller
  966. }
  967. pei->Release();
  968. }
  969. }
  970. psl->Release();
  971. }
  972. return hres;
  973. } // end ExtractPlusColorIcon()