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.

271 lines
7.5 KiB

  1. #include "sysdm.h"
  2. #include <windowsx.h>
  3. #include "shlapip.h"
  4. #include "regstr.h"
  5. #include "ccstock.h"
  6. #include "shguidp.h"
  7. #include "ieguidp.h"
  8. #include "help.h"
  9. #define REGSTRA_EXPLORER_VISUALFX "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VisualEffects"
  10. #define REGSTRA_VISUALFX_SETTING "VisualFXSetting"
  11. #define VISUALFX_SETTING_AUTO 0x0
  12. #define VISUALFX_SETTING_LOOKS 0x1
  13. #define VISUALFX_SETTING_PERF 0x2
  14. #define VISUALFX_SETTING_CUSTOM 0x3
  15. DWORD aVisualFXHelpIds[] =
  16. {
  17. IDC_VFX_TITLE, NO_HELP,
  18. IDC_VFX_TREE, NO_HELP,
  19. IDC_VFX_BESTLOOKS, (IDH_PERF + 10),
  20. IDC_VFX_BESTPERF, (IDH_PERF + 11),
  21. IDC_VFX_AUTO, (IDH_PERF + 12),
  22. IDC_VFX_CUSTOM, (IDH_PERF + 19),
  23. 0, 0
  24. };
  25. class CVisualEffectsDlg
  26. {
  27. public:
  28. INT_PTR DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  29. HRESULT Init();
  30. CVisualEffectsDlg();
  31. virtual ~CVisualEffectsDlg();
  32. private:
  33. void _EnableApply();
  34. void _SetItemCheckState(HTREEITEM hti, BOOL fCheck);
  35. void _OnCommand(WORD wID);
  36. void _OnInitDialog(HWND hDlg);
  37. void _OnNotify(LPNMHDR pnm);
  38. WORD _wMode;
  39. HWND _hwndTree;
  40. HWND _hDlg;
  41. IRegTreeOptions *_prto;
  42. BOOL _fDirtyTree;
  43. BOOL _fTreeInit;
  44. };
  45. CVisualEffectsDlg::CVisualEffectsDlg() : _hwndTree(NULL), _hDlg(NULL), _prto(NULL), _fDirtyTree(FALSE), _fTreeInit(FALSE), _wMode(VISUALFX_SETTING_AUTO)
  46. {
  47. }
  48. CVisualEffectsDlg::~CVisualEffectsDlg()
  49. {
  50. ATOMICRELEASE(_prto);
  51. }
  52. HRESULT CVisualEffectsDlg::Init()
  53. {
  54. return CoCreateInstance(CLSID_CRegTreeOptions, NULL, CLSCTX_INPROC_SERVER,
  55. IID_PPV_ARG(IRegTreeOptions, &_prto));
  56. }
  57. void CVisualEffectsDlg::_EnableApply()
  58. {
  59. if( !_fTreeInit )
  60. {
  61. // Enable the "Apply" button because changes have happened.
  62. _fDirtyTree = TRUE;
  63. SendMessage(GetParent(_hDlg), PSM_CHANGED, (WPARAM)_hDlg, 0L);
  64. }
  65. }
  66. void CVisualEffectsDlg::_SetItemCheckState(HTREEITEM hti, BOOL fCheck)
  67. {
  68. TVITEM tvi;
  69. tvi.hItem = hti;
  70. tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  71. if (TreeView_GetItem(_hwndTree, &tvi))
  72. {
  73. tvi.iImage = fCheck ? IDCHECKED : IDUNCHECKED;
  74. tvi.iSelectedImage = tvi.iImage;
  75. TreeView_SetItem(_hwndTree, &tvi);
  76. }
  77. }
  78. void CVisualEffectsDlg::_OnCommand(WORD wID)
  79. {
  80. if (wID != _wMode)
  81. {
  82. _wMode = wID;
  83. switch (wID)
  84. {
  85. case IDC_VFX_BESTLOOKS:
  86. case IDC_VFX_BESTPERF:
  87. {
  88. BOOL fCheck = (wID == IDC_VFX_BESTLOOKS);
  89. for (HTREEITEM hti = TreeView_GetRoot(_hwndTree); hti != NULL;
  90. hti = TreeView_GetNextItem(_hwndTree, hti, TVGN_NEXT))
  91. {
  92. _SetItemCheckState(hti, fCheck);
  93. }
  94. }
  95. _EnableApply();
  96. break;
  97. case IDC_VFX_AUTO:
  98. _prto->WalkTree(WALK_TREE_RESTORE);
  99. _EnableApply();
  100. break;
  101. case IDC_VFX_CUSTOM:
  102. break;
  103. }
  104. }
  105. }
  106. void CVisualEffectsDlg::_OnInitDialog(HWND hDlg)
  107. {
  108. _hDlg = hDlg;
  109. _hwndTree = GetDlgItem(hDlg, IDC_VFX_TREE);
  110. DWORD cbData, dwData;
  111. cbData = sizeof(dwData);
  112. if (ERROR_SUCCESS != SHRegGetUSValue(TEXT(REGSTRA_EXPLORER_VISUALFX), TEXT(REGSTRA_VISUALFX_SETTING), NULL, &dwData, &cbData, FALSE, NULL, 0))
  113. {
  114. dwData = VISUALFX_SETTING_AUTO;
  115. }
  116. _fTreeInit = TRUE;
  117. _prto->InitTree(_hwndTree, HKEY_LOCAL_MACHINE, REGSTRA_EXPLORER_VISUALFX, NULL);
  118. SendMessage(GetDlgItem(_hDlg, IDC_VFX_AUTO + dwData), BM_CLICK, 0, 0);
  119. _fTreeInit = FALSE;
  120. }
  121. void CVisualEffectsDlg::_OnNotify(LPNMHDR pnm)
  122. {
  123. switch (pnm->code)
  124. {
  125. case NM_CLICK:
  126. case NM_DBLCLK:
  127. if (pnm->idFrom == IDC_VFX_TREE)
  128. {
  129. TV_HITTESTINFO ht;
  130. DWORD dwPos = GetMessagePos(); // get where we were hit
  131. ht.pt.x = GET_X_LPARAM(dwPos);
  132. ht.pt.y = GET_Y_LPARAM(dwPos);
  133. ScreenToClient(_hwndTree, &ht.pt); // translate it to our window
  134. // retrieve the item hit
  135. HTREEITEM hti = TreeView_HitTest(_hwndTree, &ht);
  136. if (hti)
  137. {
  138. if (VISUALFX_SETTING_CUSTOM != _wMode)
  139. {
  140. CheckRadioButton(_hDlg, IDC_VFX_AUTO, IDC_VFX_CUSTOM, IDC_VFX_CUSTOM);
  141. }
  142. _prto->ToggleItem(hti);
  143. _EnableApply();
  144. }
  145. }
  146. break;
  147. case TVN_KEYDOWN:
  148. if (((LPNMTVKEYDOWN)pnm)->wVKey == VK_SPACE)
  149. {
  150. if (VISUALFX_SETTING_CUSTOM != _wMode)
  151. {
  152. CheckRadioButton(_hDlg, IDC_VFX_AUTO, IDC_VFX_CUSTOM, IDC_VFX_CUSTOM);
  153. }
  154. _prto->ToggleItem((HTREEITEM)SendMessage(_hwndTree, TVM_GETNEXTITEM, (WPARAM)TVGN_CARET, 0L));
  155. _EnableApply();
  156. }
  157. break;
  158. case PSN_APPLY:
  159. if (_fDirtyTree)
  160. {
  161. _prto->WalkTree(WALK_TREE_SAVE);
  162. for (int i = IDC_VFX_AUTO; i <= IDC_VFX_CUSTOM; i++)
  163. {
  164. if (BST_CHECKED == SendMessage(GetDlgItem(_hDlg, i), BM_GETCHECK, 0, 0))
  165. {
  166. DWORD dwData = VISUALFX_SETTING_AUTO + (i - IDC_VFX_AUTO);
  167. SHRegSetUSValue(TEXT(REGSTRA_EXPLORER_VISUALFX), TEXT(REGSTRA_VISUALFX_SETTING), REG_DWORD, &dwData, sizeof(dwData), SHREGSET_FORCE_HKCU);
  168. break;
  169. }
  170. }
  171. DWORD_PTR dwResult = 0;
  172. SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, NULL, (LPARAM)TEXT("VisualEffects"),
  173. SMTO_NOTIMEOUTIFNOTHUNG, 1000, &dwResult);
  174. _fDirtyTree = FALSE;
  175. }
  176. break;
  177. }
  178. }
  179. INT_PTR CVisualEffectsDlg::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  180. {
  181. switch (uMsg)
  182. {
  183. case WM_INITDIALOG:
  184. _OnInitDialog(hDlg);
  185. break;
  186. case WM_NOTIFY:
  187. _OnNotify(((LPNMHDR)lParam));
  188. break;
  189. case WM_COMMAND:
  190. _OnCommand(GET_WM_COMMAND_ID(wParam, lParam));
  191. break;
  192. case WM_DESTROY:
  193. _prto->WalkTree(WALK_TREE_DELETE);
  194. break;
  195. case WM_HELP: // F1
  196. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  197. (DWORD_PTR) (LPSTR) aVisualFXHelpIds);
  198. break;
  199. case WM_CONTEXTMENU: // right mouse click
  200. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  201. (DWORD_PTR) (LPSTR) aVisualFXHelpIds);
  202. break;
  203. default:
  204. return FALSE;
  205. }
  206. return TRUE;
  207. }
  208. INT_PTR WINAPI VisualEffectsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  209. {
  210. INT_PTR fRet = FALSE;
  211. CVisualEffectsDlg* pve;
  212. if (uMsg == WM_INITDIALOG)
  213. {
  214. pve = new CVisualEffectsDlg();
  215. if (pve && FAILED(pve->Init()))
  216. {
  217. delete pve;
  218. pve = NULL;
  219. }
  220. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pve);
  221. }
  222. else
  223. {
  224. pve = (CVisualEffectsDlg*)GetWindowLongPtr(hDlg, DWLP_USER);
  225. }
  226. if (pve)
  227. {
  228. fRet = pve->DlgProc(hDlg, uMsg, wParam, lParam);
  229. if (uMsg == WM_DESTROY)
  230. {
  231. delete pve;
  232. SetWindowLongPtr(hDlg, DWLP_USER, NULL);
  233. }
  234. }
  235. return fRet;
  236. }