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.

879 lines
29 KiB

  1. /*-----------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** reg.c **
  6. ** **
  7. ** Functions for reading, writing, and deleting **
  8. ** registry keys - TSREG **
  9. ** 07-01-98 a-clindh Created **
  10. **-----------------------------------------------*/
  11. #include <windows.h>
  12. #include <commctrl.h>
  13. #include <TCHAR.H>
  14. #include <stdlib.h>
  15. #include "tsreg.h"
  16. #include "resource.h"
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // Had to have this function in case the user wants to save a profile
  19. // that only has default settings. This will write a key but the key
  20. // will contain no values.
  21. ///////////////////////////////////////////////////////////////////////////////
  22. void WriteBlankKey(TCHAR lpszRegPath[MAX_PATH])
  23. {
  24. HKEY hKey;
  25. DWORD dwDisposition;
  26. RegCreateKeyEx(HKEY_CURRENT_USER, lpszRegPath,
  27. 0, NULL, REG_OPTION_NON_VOLATILE,
  28. KEY_ALL_ACCESS, 0, &hKey, &dwDisposition);
  29. RegCloseKey(hKey);
  30. }
  31. ///////////////////////////////////////////////////////////////////////////////
  32. void SetRegKey(int i, TCHAR lpszRegPath[MAX_PATH])
  33. {
  34. HKEY hKey;
  35. DWORD dwDisposition;
  36. RegCreateKeyEx(HKEY_CURRENT_USER, lpszRegPath,
  37. 0, NULL, REG_OPTION_NON_VOLATILE,
  38. KEY_ALL_ACCESS, 0, &hKey, &dwDisposition);
  39. //
  40. // write the key value to the registry
  41. //
  42. if(hKey != NULL) {
  43. RegSetValueEx(hKey, g_KeyInfo[i].Key, 0, REG_DWORD,
  44. & (unsigned char) (g_KeyInfo[i].CurrentKeyValue),
  45. sizeof(DWORD));
  46. }
  47. RegCloseKey(hKey);
  48. }
  49. ///////////////////////////////////////////////////////////////////////////////
  50. void DeleteRegKey(int i, TCHAR lpszRegPath[MAX_PATH])
  51. {
  52. HKEY hKey;
  53. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszRegPath, 0,
  54. KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  55. RegDeleteValue(hKey, g_KeyInfo[i].Key);
  56. RegCloseKey(hKey);
  57. }
  58. }
  59. ///////////////////////////////////////////////////////////////////////////////
  60. // returns 1 if the registry key is there and 0 if it isn't
  61. ///////////////////////////////////////////////////////////////////////////////
  62. int GetRegKey(int i, TCHAR lpszRegPath[MAX_PATH])
  63. {
  64. DWORD *dwKeyValue;
  65. HKEY hKey;
  66. DWORD dwType;
  67. DWORD dwSize;
  68. dwType = REG_SZ;
  69. dwSize = sizeof(DWORD);
  70. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszRegPath, 0,
  71. KEY_READ, &hKey) == ERROR_SUCCESS) {
  72. if (RegQueryValueEx(hKey, g_KeyInfo[i].Key, 0,
  73. &dwType, (LPBYTE) &dwKeyValue,
  74. &dwSize) == ERROR_SUCCESS) {
  75. RegCloseKey(hKey);
  76. return 1;
  77. }
  78. RegCloseKey(hKey);
  79. }
  80. return 0;
  81. }
  82. ///////////////////////////////////////////////////////////////////////////////
  83. void SaveSettings(HWND dlghwnd, int i,
  84. int nCtlID1, int nCtlID2, TCHAR lpszRegPath[MAX_PATH])
  85. {
  86. do {
  87. if (IsDlgButtonChecked(dlghwnd, nCtlID1)) {
  88. SetRegKey(i, lpszRegPath);
  89. } else {
  90. if (IsDlgButtonChecked(dlghwnd, nCtlID2)) {
  91. DeleteRegKey(i, lpszRegPath);
  92. }
  93. }
  94. dlghwnd = GetNextWindow(dlghwnd, GW_HWNDNEXT);
  95. } while (dlghwnd != NULL);
  96. }
  97. ///////////////////////////////////////////////////////////////////////////////
  98. void RestoreSettings(HWND dlghwnd, int i,
  99. int nCtlID1, int nCtlID2, TCHAR lpszRegPath[MAX_PATH])
  100. {
  101. // check settings and enable appropriate radio button.
  102. if (GetRegKey(i, lpszRegPath) != 0) {
  103. CheckDlgButton(dlghwnd, nCtlID1, TRUE);
  104. CheckDlgButton(dlghwnd, nCtlID2, FALSE);
  105. } else {
  106. CheckDlgButton(dlghwnd, nCtlID1, FALSE);
  107. CheckDlgButton(dlghwnd, nCtlID2, TRUE);
  108. }
  109. }
  110. ///////////////////////////////////////////////////////////////////////////////
  111. // pass the index of the key and the function
  112. // returns the value stored in the registry
  113. ///////////////////////////////////////////////////////////////////////////////
  114. int GetRegKeyValue(int i)
  115. {
  116. int nKeyValue;
  117. HKEY hKey;
  118. DWORD dwType;
  119. DWORD dwSize;
  120. TCHAR lpszRegPath[MAX_PATH];
  121. LoadString (g_hInst, IDS_REG_PATH, lpszRegPath, sizeof (lpszRegPath));
  122. dwType = REG_SZ;
  123. dwSize = sizeof(DWORD);
  124. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszRegPath, 0,
  125. KEY_READ, &hKey) == ERROR_SUCCESS) {
  126. if (RegQueryValueEx(hKey, g_KeyInfo[i].Key, 0,
  127. &dwType, (LPBYTE) &nKeyValue,
  128. &dwSize) == ERROR_SUCCESS) {
  129. RegCloseKey(hKey);
  130. return nKeyValue;
  131. }
  132. RegCloseKey(hKey);
  133. }
  134. return 0;
  135. }
  136. ///////////////////////////////////////////////////////////////////////////////
  137. // Initialize the controls for the original "misc" sheet.
  138. ///////////////////////////////////////////////////////////////////////////////
  139. void InitMiscControls(HWND hDlg, HWND hwndComboBox)
  140. {
  141. TCHAR szBuffer[4];
  142. int i, nKeyVal;
  143. TCHAR lpszRegPath[MAX_PATH];
  144. LoadString (g_hInst, IDS_REG_PATH, lpszRegPath, sizeof (lpszRegPath));
  145. //
  146. // fill the combo box list
  147. //
  148. SendMessage(hwndComboBox, CB_ADDSTRING, 0,
  149. (LPARAM) (LPCTSTR) TEXT("0"));
  150. for (i = 2; i <= MAXTEXTFRAGSIZE; i*= 2) {
  151. _itot(i, szBuffer, 10);
  152. SendMessage(hwndComboBox, CB_ADDSTRING, 0,
  153. (LPARAM) (LPCTSTR) szBuffer);
  154. } // ** end for loop
  155. //
  156. // limit combo box to 4 characters
  157. //
  158. SendMessage(hwndComboBox, CB_LIMITTEXT, 3, 0);
  159. //
  160. // get values from registry for text frag combo box
  161. //
  162. nKeyVal = GetRegKey(TEXTFRAGINDEX, lpszRegPath); // check for null
  163. if ( nKeyVal == 1 ) {
  164. nKeyVal = GetRegKeyValue(TEXTFRAGINDEX);
  165. } else {
  166. nKeyVal = g_KeyInfo[TEXTFRAGINDEX].DefaultKeyValue;
  167. }
  168. g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue = nKeyVal;
  169. _itot( nKeyVal, szBuffer, 10);
  170. SendMessage(hwndComboBox, CB_SELECTSTRING, -1,
  171. (LPARAM)(LPCSTR) szBuffer);
  172. //
  173. // get values from registry for radio buttons
  174. //
  175. nKeyVal = GetRegKey(GLYPHINDEX, lpszRegPath); // check for null
  176. if ( nKeyVal == 1 ) {
  177. nKeyVal = GetRegKeyValue(GLYPHINDEX);
  178. switch (nKeyVal) {
  179. case 0:
  180. CheckDlgButton(hDlg, IDC_RADIO_NONE, TRUE);
  181. break;
  182. case 1:
  183. CheckDlgButton(hDlg, IDC_RADIO_PARTIAL, TRUE);
  184. break;
  185. case 2:
  186. CheckDlgButton(hDlg, IDC_RADIO_FULL, TRUE);
  187. break;
  188. }
  189. } else {
  190. nKeyVal = g_KeyInfo[GLYPHINDEX].DefaultKeyValue;
  191. CheckDlgButton(hDlg, IDC_RADIO_FULL, TRUE);
  192. }
  193. g_KeyInfo[GLYPHINDEX].CurrentKeyValue = nKeyVal;
  194. }
  195. ///////////////////////////////////////////////////////////////////////////////
  196. // Needed a special funtion to save settings for the bitmap cache. The
  197. // combined total must be 100 and can only be checked after all combo
  198. // boxes have been filled.
  199. ///////////////////////////////////////////////////////////////////////////////
  200. BOOL SaveBitmapSettings(TCHAR lpszRegPath[MAX_PATH])
  201. {
  202. static HWND hwndComboCache;
  203. static HWND hwndSliderNumCaches;
  204. static HWND hwndSliderDistProp[PERCENT_COMBO_COUNT];
  205. static HWND hwndPropChkBox[PERCENT_COMBO_COUNT];
  206. static HWND hwndSliderBuddy[PERCENT_COMBO_COUNT];
  207. TCHAR lpszBuffer[6];
  208. int i;
  209. //
  210. // get handles for cache size combo box and the
  211. // number of caches slider
  212. /////////////////////////////////////////////////////////////////
  213. hwndSliderNumCaches = GetDlgItem(g_hwndShadowBitmapDlg,
  214. IDC_SLD_NO_CACHES);
  215. hwndComboCache = GetDlgItem(g_hwndShadowBitmapDlg,
  216. IDC_COMBO_CACHE_SIZE);
  217. //---------------------------------------------------------------
  218. //
  219. // save settings for cache size
  220. /////////////////////////////////////////////////////////////////
  221. if (g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue ==
  222. g_KeyInfo[CACHESIZEINDEX].DefaultKeyValue) {
  223. DeleteRegKey(CACHESIZEINDEX, lpszRegPath);
  224. } else {
  225. SetRegKey(CACHESIZEINDEX, lpszRegPath);
  226. }
  227. //---------------------------------------------------------------
  228. //
  229. // save settings for number of caches
  230. /////////////////////////////////////////////////////////////////
  231. if ( g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue ==
  232. g_KeyInfo[NUM_CELL_CACHES_INDEX].DefaultKeyValue) {
  233. DeleteRegKey(NUM_CELL_CACHES_INDEX, lpszRegPath);
  234. } else {
  235. SetRegKey(NUM_CELL_CACHES_INDEX, lpszRegPath);
  236. }
  237. //---------------------------------------------------------------
  238. for (i = 0; i < PERCENT_COMBO_COUNT; i++) {
  239. //
  240. // get handles to sliders, edit, & check boxes
  241. /////////////////////////////////////////////////////////////
  242. hwndSliderDistProp[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  243. IDC_SLD_DST_PROP_1 + i);
  244. hwndSliderBuddy[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  245. IDC_TXT_DST_PROP_1 + i);
  246. hwndPropChkBox[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  247. IDC_CHK_CSH_1 + i);
  248. //-----------------------------------------------------------
  249. GetWindowText(hwndSliderBuddy[i], lpszBuffer, 4);
  250. g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue =
  251. _ttoi(lpszBuffer);
  252. //
  253. // save settings for cache sizes
  254. /////////////////////////////////////////////////////////////
  255. if ( g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue ==
  256. g_KeyInfo[CACHEPROP1 + i].DefaultKeyValue) {
  257. DeleteRegKey(CACHEPROP1 + i, lpszRegPath);
  258. } else {
  259. SetRegKey(CACHEPROP1 + i, lpszRegPath);
  260. }
  261. //-----------------------------------------------------------
  262. //
  263. // save settings for persistent caching
  264. /////////////////////////////////////////////////////////////
  265. if (IsDlgButtonChecked(g_hwndShadowBitmapDlg, IDC_CHK_CSH_1 + i)) {
  266. g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue = 1;
  267. SetRegKey(BM_PERSIST_BASE_INDEX + i, lpszRegPath);
  268. } else {
  269. g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue = 0;
  270. DeleteRegKey(BM_PERSIST_BASE_INDEX + i, lpszRegPath);
  271. }
  272. //-----------------------------------------------------------
  273. } // ** end for loop
  274. return TRUE;
  275. }
  276. ///////////////////////////////////////////////////////////////////////////////
  277. // reads individual key values for each profile into it's associated
  278. // variable from the regisgry (if there is a value) or assigns the
  279. // element it's default value.
  280. ///////////////////////////////////////////////////////////////////////////////
  281. void LoadKeyValues()
  282. {
  283. TCHAR lpszClientProfilePath[MAX_PATH];
  284. static HWND hwndProfilesCBO;
  285. int i, index, nKeyValue;
  286. TCHAR lpszSubKeyPath[MAX_PATH];
  287. DWORD dwType;
  288. DWORD dwSize;
  289. static HKEY hKey;
  290. hwndProfilesCBO = GetDlgItem(g_hwndProfilesDlg, IDC_CBO_PROFILES);
  291. LoadString (g_hInst, IDS_PROFILE_PATH,
  292. lpszClientProfilePath, sizeof(lpszClientProfilePath));
  293. // get the key name of each profile
  294. GetClientProfileNames(lpszClientProfilePath);
  295. g_pkfProfile = g_pkfStart;
  296. for (index = 0; index <= g_pkfProfile->Index; index++) {
  297. // fill combo box existing profile names
  298. SendMessage(hwndProfilesCBO, CB_ADDSTRING, 0,
  299. (LPARAM) g_pkfProfile->KeyInfo->Key);
  300. _tcscpy(lpszSubKeyPath, lpszClientProfilePath);
  301. _tcscat(lpszSubKeyPath, TEXT("\\"));
  302. _tcscat(lpszSubKeyPath, g_pkfProfile->KeyInfo->Key);
  303. for (i = 0; i < KEYCOUNT; i++) {
  304. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszSubKeyPath, 0,
  305. KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  306. g_pkfProfile->KeyInfo[i].DefaultKeyValue =
  307. g_KeyInfo[i].DefaultKeyValue;
  308. _tcscpy(g_pkfProfile->KeyInfo[i].KeyPath,
  309. lpszSubKeyPath);
  310. if (RegQueryValueEx(hKey, g_KeyInfo[i].Key, 0,
  311. &dwType, (LPBYTE) &nKeyValue,
  312. &dwSize) == ERROR_SUCCESS) {
  313. g_pkfProfile->KeyInfo[i].CurrentKeyValue =
  314. nKeyValue;
  315. RegCloseKey(hKey);
  316. } else {
  317. g_pkfProfile->KeyInfo[i].CurrentKeyValue =
  318. g_KeyInfo[i].DefaultKeyValue;
  319. RegCloseKey(hKey);
  320. }
  321. RegCloseKey(hKey);
  322. }
  323. }// inner for loop
  324. g_pkfProfile = g_pkfProfile->Next;
  325. }// outer for loop
  326. }
  327. ///////////////////////////////////////////////////////////////////////////////
  328. void ReadRecordIn(TCHAR lpszBuffer[])
  329. {
  330. // adds values from linked list to default data structure.
  331. int i, index;
  332. g_pkfProfile = g_pkfStart;
  333. for (index = 0; index <= g_pkfProfile->Index; index++) {
  334. if (_tcscmp( lpszBuffer,
  335. g_pkfProfile->KeyInfo->Key) == 0) {
  336. for (i = 0; i < KEYCOUNT; i++) {
  337. g_KeyInfo[i].CurrentKeyValue =
  338. g_pkfProfile->KeyInfo[i].
  339. CurrentKeyValue;
  340. }
  341. break;
  342. }
  343. g_pkfProfile = g_pkfProfile->Next;
  344. }
  345. }
  346. ///////////////////////////////////////////////////////////////////////////////
  347. void ReloadKeys(TCHAR lpszBuffer[], HWND hwndProfilesCBO)
  348. {
  349. int index;
  350. SendMessage(hwndProfilesCBO, CB_RESETCONTENT, 0, 0);
  351. // free any allocated memory.
  352. g_pkfProfile = g_pkfStart;
  353. for (index = 0; index <= g_pkfProfile->Index; index++)
  354. {
  355. g_pkfProfile = g_pkfProfile->Next;
  356. if (g_pkfStart)
  357. free(g_pkfStart);
  358. g_pkfStart = g_pkfProfile;
  359. }
  360. if (g_pkfStart)
  361. free(g_pkfStart);
  362. // allocate memory and reload keys.
  363. LoadKeyValues();
  364. // read linked list into current key data struct.
  365. ReadRecordIn(lpszBuffer);
  366. // adjust the controls accordingly.
  367. SetControlValues();
  368. }
  369. ///////////////////////////////////////////////////////////////////////////////
  370. // change the title of the app to reflect the currently selected profile
  371. ///////////////////////////////////////////////////////////////////////////////
  372. void ResetTitle(TCHAR lpszBuffer[])
  373. {
  374. HWND hWndParent;
  375. TCHAR lpszCaption[MAXKEYSIZE] = TEXT("");
  376. // change window caption
  377. LoadString (g_hInst, IDS_WINDOW_TITLE,
  378. lpszCaption, sizeof (lpszCaption));
  379. _tcscat(lpszCaption, lpszBuffer);
  380. hWndParent = GetParent(g_hwndProfilesDlg);
  381. SendMessage(hWndParent, WM_SETTEXT, 0,
  382. (LPARAM) lpszCaption);
  383. }
  384. ///////////////////////////////////////////////////////////////////////////////
  385. void SetEditCell(TCHAR lpszBuffer[],
  386. HWND hwndProfilesCBO)
  387. {
  388. LRESULT i;
  389. //
  390. // set edit cell text to selected profile string
  391. //
  392. i = SendMessage(hwndProfilesCBO,
  393. CB_FINDSTRING, 0,
  394. (LPARAM) lpszBuffer);
  395. SendMessage(hwndProfilesCBO,
  396. CB_SETCURSEL, i, 0);
  397. }
  398. ///////////////////////////////////////////////////////////////////////////////
  399. // Recursive function to allocate memory and read in the values stored
  400. // in the registry.
  401. ///////////////////////////////////////////////////////////////////////////////
  402. void GetClientProfileNames(TCHAR lpszClientProfilePath[])
  403. {
  404. TCHAR lpszKeyName[MAX_PATH];
  405. ULONG lpPathLen = MAX_PATH;
  406. static HKEY hKey;
  407. static int nKeyIndex = 0;
  408. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszClientProfilePath, 0,
  409. KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  410. if (RegEnumKeyEx(hKey, nKeyIndex, &lpszKeyName[0], &lpPathLen,
  411. NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
  412. //
  413. // allocate memory for the first key
  414. //
  415. if (nKeyIndex == 0) {
  416. g_pkfProfile = (PROFILE_KEY_INFO *) malloc
  417. (sizeof(PROFILE_KEY_INFO));
  418. g_pkfStart = g_pkfProfile;
  419. }
  420. //
  421. // Catches failure if malloc fails above
  422. //
  423. if(!g_pkfProfile)
  424. {
  425. return;
  426. }
  427. // save the key name to the data structure
  428. _tcsncpy(g_pkfProfile->KeyInfo->Key, lpszKeyName,
  429. sizeof(g_pkfProfile->KeyInfo->Key)/sizeof(TCHAR));
  430. // give the data element an index number
  431. g_pkfProfile->Index = nKeyIndex;
  432. // allocate memory for the next structure
  433. g_pkfProfile->Next = (PROFILE_KEY_INFO *) malloc
  434. (sizeof(PROFILE_KEY_INFO));
  435. // increment the pointer to the next element
  436. g_pkfProfile = g_pkfProfile->Next;
  437. // close the current registry key
  438. RegCloseKey(hKey);
  439. if(!g_pkfProfile)
  440. {
  441. return;
  442. }
  443. nKeyIndex++;
  444. GetClientProfileNames(lpszClientProfilePath);
  445. }
  446. RegCloseKey(hKey);
  447. }
  448. nKeyIndex = 0;
  449. }
  450. ///////////////////////////////////////////////////////////////////////////////
  451. // adjust all of the controls in the application to the values stored
  452. // by the profile.
  453. ///////////////////////////////////////////////////////////////////////////////
  454. void SetControlValues()
  455. {
  456. TCHAR lpszBuffer[MAXKEYSIZE];
  457. HWND hwndComboCache;
  458. static HWND hwndSliderNumCaches;
  459. static HWND hwndSliderDistProp[PERCENT_COMBO_COUNT];
  460. static HWND hwndSliderDistBuddy[PERCENT_COMBO_COUNT];
  461. static HWND hwndPropChkBox[PERCENT_COMBO_COUNT];
  462. static HWND hwndSlider[NUMBER_OF_SLIDERS];
  463. static HWND hwndSliderEditBuddy[NUMBER_OF_SLIDERS];
  464. static HWND hwndEditNumCaches;
  465. static HWND hwndComboTextFrag;
  466. static HWND hwndComboOrder;
  467. static HWND hwndRadioShadowEn, hwndRadioShadowDis;
  468. static HWND hwndRadioDedicatedEn, hwndRadioDedicatedDis;
  469. static TCHAR lpszRegPath[MAX_PATH];
  470. static UINT nGlyphBuffer;
  471. int nPos;
  472. int i;
  473. LoadString (g_hInst, IDS_REG_PATH, lpszRegPath, sizeof (lpszRegPath));
  474. // shadow bitmap page *****************************************************
  475. hwndComboCache = GetDlgItem(g_hwndShadowBitmapDlg,
  476. IDC_COMBO_CACHE_SIZE);
  477. hwndSliderNumCaches = GetDlgItem(g_hwndShadowBitmapDlg,
  478. IDC_SLD_NO_CACHES);
  479. hwndEditNumCaches = GetDlgItem(g_hwndShadowBitmapDlg,
  480. IDC_TXT_NO_CACHES);
  481. for (i = 0; i < PERCENT_COMBO_COUNT; i++) {
  482. _itot(g_KeyInfo[i + CACHEPROP1].CurrentKeyValue,
  483. lpszBuffer, 10);
  484. hwndSliderDistProp[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  485. IDC_SLD_DST_PROP_1 + i);
  486. hwndSliderDistBuddy[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  487. IDC_TXT_DST_PROP_1 + i);
  488. SetWindowText(hwndSliderDistBuddy[i], lpszBuffer);
  489. hwndPropChkBox[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  490. IDC_CHK_CSH_1 + i);
  491. }
  492. //
  493. // enable/disable check boxes and sliders
  494. //
  495. EnableControls(g_hwndShadowBitmapDlg, hwndSliderDistProp,
  496. hwndPropChkBox, hwndSliderDistBuddy,
  497. hwndEditNumCaches, hwndSliderNumCaches,
  498. PERCENT_COMBO_COUNT, lpszRegPath);
  499. _itot(g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue, lpszBuffer, 10);
  500. SetWindowText(hwndComboCache, lpszBuffer);
  501. // glyph page *************************************************************
  502. hwndComboTextFrag = GetDlgItem(g_hwndGlyphCacheDlg, IDC_CBO_TXT_FRAG);
  503. switch (g_KeyInfo[GLYPHINDEX].CurrentKeyValue) {
  504. case 0:
  505. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_NONE, TRUE);
  506. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_PARTIAL, FALSE);
  507. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_FULL, FALSE);
  508. break;
  509. case 1:
  510. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_NONE, FALSE);
  511. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_PARTIAL, TRUE);
  512. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_FULL, FALSE);
  513. break;
  514. case 2:
  515. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_NONE, FALSE);
  516. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_PARTIAL, FALSE);
  517. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_FULL, TRUE);
  518. break;
  519. }
  520. _itot(g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue, lpszBuffer, 10);
  521. SendMessage(hwndComboTextFrag, CB_SELECTSTRING, -1,
  522. (LPARAM)(LPCSTR) lpszBuffer);
  523. for (i = 0; i < NUMBER_OF_SLIDERS; i++) {
  524. hwndSlider[i] = GetDlgItem(g_hwndGlyphCacheDlg,
  525. (IDC_SLIDER1 + i));
  526. hwndSliderEditBuddy[i] = GetDlgItem(g_hwndGlyphCacheDlg,
  527. (IDC_STATIC1 + i));
  528. SetWindowLongPtr(hwndSlider[i], GWLP_USERDATA, i);
  529. _itot(g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue,
  530. (lpszBuffer), 10);
  531. //
  532. // position the thumb on the slider control
  533. //
  534. nGlyphBuffer = g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue;
  535. #ifdef _X86_
  536. // EXECUTE ASSEMBLER CODE ONLY IF X86 PROCESSOR
  537. // BSF: Bit Scan Forward -
  538. // Scans the value contained in the EAX regiseter
  539. // for the first significant (1) bit.
  540. // This function returns the location of the first
  541. // significant bit. The function is used in this
  542. // application as a base 2 logarythm. The location
  543. // of the bit is determined, stored in the nPos
  544. // variable, and nPos is used to set the slider
  545. // control. ie. If the register value is 4, nPos
  546. // is set to 2 (00000100). 10 minus 2 (position 8
  547. // on the slider control) represents the value 4.
  548. __asm
  549. {
  550. BSF EAX, nGlyphBuffer
  551. MOV nPos, EAX
  552. }
  553. nPos = 10 - nPos;
  554. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, (LPARAM)nPos);
  555. #else
  556. switch (nGlyphBuffer) {
  557. case 4:
  558. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 8);
  559. break;
  560. case 8:
  561. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 7);
  562. break;
  563. case 16:
  564. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 6);
  565. break;
  566. case 32:
  567. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 5);
  568. break;
  569. case 64:
  570. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 4);
  571. break;
  572. case 128:
  573. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 3);
  574. break;
  575. case 256:
  576. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 2);
  577. break;
  578. case 512:
  579. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 1);
  580. break;
  581. }
  582. #endif
  583. }
  584. //misc page ***************************************************************
  585. hwndComboOrder = GetDlgItem(g_hwndMiscDlg, IDC_COMBO_ORDER);
  586. hwndRadioShadowEn = GetDlgItem(g_hwndMiscDlg, IDC_SHADOW_ENABLED);
  587. hwndRadioShadowDis = GetDlgItem(g_hwndMiscDlg, IDC_SHADOW_DISABLED);
  588. hwndRadioDedicatedEn = GetDlgItem(g_hwndMiscDlg, IDC_DEDICATED_ENABLED);
  589. hwndRadioDedicatedDis = GetDlgItem(g_hwndMiscDlg, IDC_DEDICATED_DISABLED);
  590. //
  591. // set radio buttons
  592. //
  593. RestoreSettings(g_hwndMiscDlg, SHADOWINDEX,
  594. IDC_SHADOW_DISABLED, IDC_SHADOW_ENABLED,
  595. g_pkfProfile->KeyInfo[i].KeyPath);
  596. RestoreSettings(g_hwndMiscDlg, DEDICATEDINDEX,
  597. IDC_DEDICATED_ENABLED, IDC_DEDICATED_DISABLED,
  598. g_pkfProfile->KeyInfo[i].KeyPath);
  599. _itot( g_KeyInfo[ORDERINDEX].CurrentKeyValue,
  600. lpszBuffer, 10);
  601. SetWindowText(hwndComboOrder, lpszBuffer);
  602. }
  603. ///////////////////////////////////////////////////////////////////////////////
  604. //
  605. //
  606. // send handles to controls and the integer value for the number of
  607. // enabled combo & check boxes
  608. ///////////////////////////////////////////////////////////////////////////////
  609. void EnableControls(HWND hDlg,
  610. HWND hwndSliderDistProp[],
  611. HWND hwndPropChkBox[],
  612. HWND hwndSliderDistBuddy[],
  613. HWND hwndEditNumCaches,
  614. HWND hwndSliderNumCaches,
  615. int nNumCellCaches,
  616. TCHAR lpszRegPath[])
  617. {
  618. int i, nPos;
  619. TCHAR lpszBuffer[6];
  620. for (i = 0; i < nNumCellCaches; i++) {
  621. //
  622. // check/uncheck check boxes for persistent caching
  623. //
  624. if (g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue == 0)
  625. CheckDlgButton(hDlg, IDC_CHK_CSH_1 + i, FALSE);
  626. else
  627. CheckDlgButton(hDlg, IDC_CHK_CSH_1 + i, TRUE);
  628. //
  629. // enable/disable check & slider controls
  630. //
  631. if (i < (INT) g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue) {
  632. EnableWindow(hwndSliderDistProp[i], TRUE);
  633. EnableWindow(hwndPropChkBox[i], TRUE);
  634. EnableWindow(hwndSliderDistBuddy[i], TRUE);
  635. _itot(g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue,
  636. lpszBuffer, 10);
  637. SetWindowText(hwndSliderDistBuddy[i], lpszBuffer);
  638. //
  639. // position the thumb on the slider control
  640. //
  641. nPos = g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue;
  642. SendMessage(hwndSliderDistProp[i], TBM_SETPOS, TRUE,
  643. 11 - nPos / 10);
  644. } else {
  645. EnableWindow(hwndSliderDistProp[i], FALSE);
  646. EnableWindow(hwndPropChkBox[i], FALSE);
  647. EnableWindow(hwndSliderDistBuddy[i], FALSE);
  648. SetWindowText(hwndSliderDistBuddy[i], NULL);
  649. CheckDlgButton(hDlg, IDC_CHK_CSH_1 + i, FALSE);
  650. SendMessage(hwndSliderDistProp[i], TBM_SETPOS, TRUE, 11);
  651. }
  652. }
  653. //
  654. // position the thumb on the slider control (num caches)
  655. //
  656. SendMessage(hwndSliderNumCaches, TBM_SETPOS, TRUE,
  657. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue + 1);
  658. _itot( g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue,
  659. lpszBuffer, 10);
  660. //
  661. // display string in edit cell
  662. //
  663. SetWindowText(hwndEditNumCaches, lpszBuffer);
  664. }
  665. // end of file
  666. ///////////////////////////////////////////////////////////////////////////////
  667. // pass the key name along with the key path and the function
  668. // returns the value stored in the registry
  669. // DWORD values
  670. ///////////////////////////////////////////////////////////////////////////////
  671. int GetKeyVal(TCHAR lpszRegPath[MAX_PATH], TCHAR lpszKeyName[MAX_PATH])
  672. {
  673. int nKeyValue;
  674. HKEY hKey;
  675. DWORD dwType;
  676. DWORD dwSize;
  677. dwType = REG_SZ;
  678. dwSize = sizeof(DWORD);
  679. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszRegPath, 0,
  680. KEY_READ, &hKey) == ERROR_SUCCESS) {
  681. if (RegQueryValueEx(hKey, lpszKeyName, 0,
  682. &dwType, (LPBYTE) &nKeyValue,
  683. &dwSize) == ERROR_SUCCESS) {
  684. RegCloseKey(hKey);
  685. return nKeyValue;
  686. }
  687. RegCloseKey(hKey);
  688. }
  689. return 0;
  690. }
  691. ///////////////////////////////////////////////////////////////////////////////
  692. // send path AND key name to set key value - used with foreground window
  693. // lock timeout.
  694. ///////////////////////////////////////////////////////////////////////////////
  695. void SetRegKeyVal(TCHAR lpszRegPath[MAX_PATH],
  696. TCHAR lpszKeyName[MAX_PATH],
  697. int nKeyValue)
  698. {
  699. HKEY hKey;
  700. DWORD dwDisposition;
  701. RegCreateKeyEx(HKEY_CURRENT_USER, lpszRegPath,
  702. 0, NULL, REG_OPTION_NON_VOLATILE,
  703. KEY_ALL_ACCESS, 0, &hKey, &dwDisposition);
  704. //
  705. // write the key value to the registry
  706. //
  707. if(hKey != NULL) {
  708. RegSetValueEx(hKey, lpszKeyName, 0, REG_DWORD,
  709. & (unsigned char) (nKeyValue),
  710. sizeof(DWORD));
  711. RegCloseKey(hKey);
  712. }
  713. }
  714. //////////////////////////////////////////////////////////////////////////////