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.

388 lines
15 KiB

  1. /*---------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** shadow.c **
  6. ** **
  7. ** Shadow bitmap dialog - TSREG **
  8. ** 07-01-98 a-clindh Created **
  9. **---------------------------------------------*/
  10. #include <windows.h>
  11. #include <commctrl.h>
  12. #include <TCHAR.H>
  13. #include <stdlib.h>
  14. #include "tsreg.h"
  15. #include "resource.h"
  16. HWND g_hwndShadowBitmapDlg;
  17. ///////////////////////////////////////////////////////////////////////////////
  18. INT_PTR CALLBACK ShadowBitmap(HWND hDlg, UINT nMsg,
  19. WPARAM wParam, LPARAM lParam)
  20. {
  21. NMHDR *lpnmhdr;
  22. static HWND hwndComboCacheSize;
  23. static HWND hwndSliderNumCaches;
  24. static HWND hwndEditNumCaches;
  25. static HWND hwndSliderDistProp[PERCENT_COMBO_COUNT];
  26. static HWND hwndSliderDistBuddy[PERCENT_COMBO_COUNT];
  27. static HWND hwndPropChkBox[PERCENT_COMBO_COUNT];
  28. static TCHAR lpszRegPath[MAX_PATH];
  29. TCHAR lpszBuffer[6];
  30. TCHAR lpszMBoxTitle[25];
  31. TCHAR lpszMBoxError[90];
  32. LPHELPINFO lphi;
  33. int i, nPos;
  34. HWND hwndCtl;
  35. //
  36. // get a pointer to the NMHDR struct for apply button
  37. //
  38. lpnmhdr = (LPNMHDR) lParam;
  39. switch (nMsg) {
  40. case WM_NOTIFY:
  41. //
  42. // save settings
  43. //
  44. switch (lpnmhdr->code) {
  45. case PSN_KILLACTIVE:
  46. SetWindowLongPtr(lpnmhdr->hwndFrom, DWLP_MSGRESULT, FALSE);
  47. break;
  48. case PSN_HELP:
  49. lphi = (LPHELPINFO) lParam;
  50. WinHelp(lphi->hItemHandle,
  51. g_lpszPath, HELP_CONTENTS, lphi->iCtrlId);
  52. break;
  53. case PSN_APPLY:
  54. SaveBitmapSettings(lpszRegPath);
  55. break;
  56. }
  57. break;
  58. case WM_VSCROLL:
  59. hwndCtl = (HWND) (lParam);
  60. i = (int)GetWindowLongPtr(hwndCtl, GWLP_USERDATA);
  61. nPos = (int) SendMessage(hwndSliderDistProp[i], TBM_GETPOS, 0,0);
  62. GetWindowText(hwndSliderDistBuddy[i], lpszBuffer, 4);
  63. //
  64. // save cache size values to global data struct
  65. //
  66. g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue = _ttoi(lpszBuffer);
  67. //
  68. // display values in edit controls
  69. //
  70. _itot(10 * (11 - nPos), lpszBuffer, 10);
  71. SetWindowText(hwndSliderDistBuddy[i], lpszBuffer);
  72. break;
  73. case WM_HSCROLL:
  74. nPos = (int) SendMessage(hwndSliderNumCaches, TBM_GETPOS, 0,0);
  75. _itot(nPos - 1, lpszBuffer, 10);
  76. SetWindowText(hwndEditNumCaches, lpszBuffer);
  77. //
  78. // save values to global data struct (number caches)
  79. //
  80. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue = nPos - 1;
  81. //
  82. // enable/disable check boxes and sliders
  83. //
  84. EnableControls(hDlg, hwndSliderDistProp,
  85. hwndPropChkBox, hwndSliderDistBuddy,
  86. hwndEditNumCaches, hwndSliderNumCaches,
  87. PERCENT_COMBO_COUNT, lpszRegPath);
  88. break;
  89. case WM_INITDIALOG:
  90. LoadString (g_hInst, IDS_REG_PATH,
  91. lpszRegPath, sizeof (lpszRegPath));
  92. //
  93. // get handles
  94. //
  95. g_hwndShadowBitmapDlg = hDlg;
  96. hwndComboCacheSize = GetDlgItem(hDlg, IDC_COMBO_CACHE_SIZE);
  97. hwndSliderNumCaches = GetDlgItem(hDlg, IDC_SLD_NO_CACHES);
  98. hwndEditNumCaches = GetDlgItem(hDlg, IDC_TXT_NO_CACHES);
  99. //
  100. // set range on slider
  101. //
  102. SendMessage(hwndSliderNumCaches, TBM_SETRANGE, TRUE,
  103. (LPARAM) MAKELONG(1, 6));
  104. for (i = 0; i < PERCENT_COMBO_COUNT; i++) {
  105. hwndSliderDistProp[i] = GetDlgItem(hDlg, IDC_SLD_DST_PROP_1 + i);
  106. hwndPropChkBox[i] = GetDlgItem(hDlg, IDC_CHK_CSH_1 + i);
  107. hwndSliderDistBuddy[i] = GetDlgItem(hDlg, IDC_TXT_DST_PROP_1 + i);
  108. //
  109. // save the index of the control
  110. //
  111. SetWindowLongPtr(hwndSliderDistProp[i], GWLP_USERDATA, i);
  112. SetWindowLongPtr(hwndSliderDistBuddy[i], GWLP_USERDATA, i);
  113. SendMessage(hwndSliderDistProp[i], TBM_SETRANGE, TRUE,
  114. (LPARAM) MAKELONG(1, 11));
  115. //
  116. // get values for persistent caching check boxes
  117. //
  118. if (GetRegKey(NUM_CACHE_INDEX + i, lpszRegPath) == 0)
  119. g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue =
  120. g_KeyInfo[BM_PERSIST_BASE_INDEX +
  121. i].DefaultKeyValue;
  122. else
  123. g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue =
  124. GetRegKeyValue(BM_PERSIST_BASE_INDEX + i);
  125. //
  126. // get values for sliders
  127. //
  128. if (GetRegKey(CACHEPROP1 + i, lpszRegPath) == 0)
  129. g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue =
  130. g_KeyInfo[CACHEPROP1 + i].DefaultKeyValue;
  131. else
  132. g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue =
  133. GetRegKeyValue(CACHEPROP1 + i);
  134. _itot(g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue,
  135. lpszBuffer, 10);
  136. //
  137. // display the value in the static edit controls (dist prop.)
  138. //
  139. SetWindowText(hwndSliderDistBuddy[i], lpszBuffer);
  140. //
  141. // position the thumb on the slider control
  142. //
  143. nPos = g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue;
  144. SendMessage(hwndSliderDistProp[i], TBM_SETPOS, TRUE,
  145. 11 - nPos / 10);
  146. } // end for loop **************************************************
  147. //
  148. // get value from registry for number of enabled
  149. // check & slider controls
  150. //
  151. if (GetRegKey(NUM_CELL_CACHES_INDEX, lpszRegPath) == 0)
  152. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue =
  153. g_KeyInfo[NUM_CELL_CACHES_INDEX].DefaultKeyValue;
  154. else
  155. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue =
  156. GetRegKeyValue(NUM_CELL_CACHES_INDEX);
  157. //
  158. // show number of enabled caches in edit box
  159. //
  160. _itot(g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue,
  161. lpszBuffer, 10);
  162. SetWindowText(hwndEditNumCaches, lpszBuffer);
  163. //
  164. // position the thumb on the slider control (num caches)
  165. //
  166. SendMessage(hwndSliderNumCaches, TBM_SETPOS, TRUE,
  167. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue + 1);
  168. //
  169. // enable/disable check boxes and sliders
  170. //
  171. EnableControls(hDlg, hwndSliderDistProp,
  172. hwndPropChkBox, hwndSliderDistBuddy,
  173. hwndEditNumCaches, hwndSliderNumCaches,
  174. PERCENT_COMBO_COUNT, lpszRegPath);
  175. //
  176. // display text in cache size edit box from registry
  177. //
  178. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  179. (GetRegKeyValue(CACHESIZEINDEX));
  180. if ( (g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue <
  181. MIN_BITMAP_CACHE_SIZE) ||
  182. (g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue >
  183. MAX_BITMAP_CACHE_SIZE)) {
  184. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  185. g_KeyInfo[CACHESIZEINDEX].DefaultKeyValue;
  186. }
  187. _itot( g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue,
  188. lpszBuffer, 10);
  189. SetWindowText(hwndComboCacheSize, lpszBuffer);
  190. //
  191. // fill the cache size combo box list
  192. //
  193. SendMessage(hwndComboCacheSize, CB_ADDSTRING, 0,
  194. (LPARAM) _itot(MIN_BITMAP_CACHE_SIZE, lpszBuffer, 10));
  195. for (i = CACHE_LIST_STEP_VAL;
  196. i <= MAX_BITMAP_CACHE_SIZE;
  197. i+= CACHE_LIST_STEP_VAL) {
  198. _itot(i, lpszBuffer, 10);
  199. SendMessage(hwndComboCacheSize, CB_ADDSTRING, 0,
  200. (LPARAM) (LPCTSTR) lpszBuffer);
  201. } // ** end for loop
  202. //
  203. // limit cache size combo box to 4 characters
  204. //
  205. SendMessage(hwndComboCacheSize, CB_LIMITTEXT, 4, 0);
  206. break;
  207. case WM_HELP:
  208. lphi = (LPHELPINFO) lParam;
  209. WinHelp(lphi->hItemHandle,
  210. g_lpszPath, HELP_CONTEXTPOPUP, lphi->iCtrlId);
  211. break;
  212. case WM_COMMAND:
  213. switch LOWORD (wParam) {
  214. case IDC_BTN_RESTORE:
  215. for (i = 0; i < PERCENT_COMBO_COUNT; i++) {
  216. _itot(g_KeyInfo[i + CACHEPROP1].DefaultKeyValue,
  217. lpszBuffer, 10);
  218. SetWindowText(hwndSliderDistProp[i], lpszBuffer);
  219. g_KeyInfo[i + CACHEPROP1].CurrentKeyValue =
  220. g_KeyInfo[i + CACHEPROP1].DefaultKeyValue;
  221. g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue =
  222. g_KeyInfo[BM_PERSIST_BASE_INDEX +
  223. i].DefaultKeyValue;
  224. }
  225. _itot(g_KeyInfo[CACHESIZEINDEX].DefaultKeyValue,
  226. lpszBuffer, 10);
  227. SetWindowText(hwndComboCacheSize, lpszBuffer);
  228. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  229. g_KeyInfo[CACHESIZEINDEX].DefaultKeyValue;
  230. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue =
  231. g_KeyInfo[NUM_CELL_CACHES_INDEX].DefaultKeyValue;
  232. //
  233. // enable/disable check boxes and sliders
  234. //
  235. EnableControls(hDlg, hwndSliderDistProp,
  236. hwndPropChkBox, hwndSliderDistBuddy,
  237. hwndEditNumCaches, hwndSliderNumCaches,
  238. PERCENT_COMBO_COUNT, lpszRegPath);
  239. break;
  240. case IDC_CHK_CSH_1:
  241. if(IsDlgButtonChecked(hDlg, IDC_CHK_CSH_1))
  242. g_KeyInfo[BM_PERSIST_BASE_INDEX].CurrentKeyValue = 1;
  243. else
  244. g_KeyInfo[BM_PERSIST_BASE_INDEX].CurrentKeyValue =
  245. g_KeyInfo[BM_PERSIST_BASE_INDEX].DefaultKeyValue;
  246. break;
  247. case IDC_CHK_CSH_2:
  248. if(IsDlgButtonChecked(hDlg, IDC_CHK_CSH_2))
  249. g_KeyInfo[BM_PERSIST_BASE_INDEX + 1].CurrentKeyValue = 1;
  250. else
  251. g_KeyInfo[BM_PERSIST_BASE_INDEX + 1].CurrentKeyValue =
  252. g_KeyInfo[BM_PERSIST_BASE_INDEX + 1].DefaultKeyValue;
  253. break;
  254. case IDC_CHK_CSH_3:
  255. if(IsDlgButtonChecked(hDlg, IDC_CHK_CSH_3))
  256. g_KeyInfo[BM_PERSIST_BASE_INDEX + 2].CurrentKeyValue = 1;
  257. else
  258. g_KeyInfo[BM_PERSIST_BASE_INDEX + 2].CurrentKeyValue =
  259. g_KeyInfo[BM_PERSIST_BASE_INDEX + 2].DefaultKeyValue;
  260. break;
  261. case IDC_CHK_CSH_4:
  262. if(IsDlgButtonChecked(hDlg, IDC_CHK_CSH_4))
  263. g_KeyInfo[BM_PERSIST_BASE_INDEX + 3].CurrentKeyValue = 1;
  264. else
  265. g_KeyInfo[BM_PERSIST_BASE_INDEX + 3].CurrentKeyValue =
  266. g_KeyInfo[BM_PERSIST_BASE_INDEX + 3].DefaultKeyValue;
  267. break;
  268. case IDC_CHK_CSH_5:
  269. if(IsDlgButtonChecked(hDlg, IDC_CHK_CSH_5))
  270. g_KeyInfo[BM_PERSIST_BASE_INDEX + 4].CurrentKeyValue = 1;
  271. else
  272. g_KeyInfo[BM_PERSIST_BASE_INDEX + 4].CurrentKeyValue =
  273. g_KeyInfo[BM_PERSIST_BASE_INDEX + 4].DefaultKeyValue;
  274. break;
  275. }
  276. switch HIWORD (wParam) {
  277. case CBN_SELCHANGE:
  278. //
  279. // get values for cache size
  280. //
  281. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue = (DWORD)
  282. SendMessage(hwndComboCacheSize, CB_GETCURSEL, 0, 0);
  283. SendMessage(hwndComboCacheSize, CB_GETLBTEXT,
  284. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue,
  285. (LPARAM) (LPCSTR) lpszBuffer);
  286. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  287. _ttoi(lpszBuffer);
  288. break;
  289. case CBN_EDITUPDATE:
  290. GetWindowText(hwndComboCacheSize, lpszBuffer, 5);
  291. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  292. _ttoi(lpszBuffer);
  293. break;
  294. case CBN_KILLFOCUS:
  295. //
  296. // only allow values within acceptable range
  297. //
  298. GetWindowText(hwndComboCacheSize, lpszBuffer, 5);
  299. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  300. _ttoi(lpszBuffer);
  301. if ( (g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue <
  302. MIN_BITMAP_CACHE_SIZE) ||
  303. (g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue >
  304. MAX_BITMAP_CACHE_SIZE) ) {
  305. //
  306. // display error if cache size is too big
  307. //
  308. LoadString (g_hInst,
  309. IDS_BITMAP_CACHE,
  310. lpszMBoxTitle,
  311. sizeof (lpszMBoxTitle));
  312. LoadString (g_hInst,
  313. IDS_BMCACHE_ERROR,
  314. lpszMBoxError,
  315. sizeof (lpszMBoxError));
  316. MessageBox(hDlg, lpszMBoxError,
  317. lpszMBoxTitle,
  318. MB_OK | MB_ICONEXCLAMATION);
  319. _itot(g_KeyInfo[CACHESIZEINDEX].DefaultKeyValue,
  320. lpszBuffer, 10);
  321. SetWindowText(hwndComboCacheSize, lpszBuffer);
  322. g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue =
  323. g_KeyInfo[CACHESIZEINDEX].DefaultKeyValue;
  324. }
  325. break;
  326. }
  327. }
  328. return FALSE;
  329. }
  330. // end of file
  331. ///////////////////////////////////////////////////////////////////////////////