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.

876 lines
28 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. g_pkfProfile = g_pkfStart->Next;
  355. free(g_pkfProfile);
  356. g_pkfStart = g_pkfProfile;
  357. }
  358. // allocate memory and reload keys.
  359. LoadKeyValues();
  360. // read linked list into current key data struct.
  361. ReadRecordIn(lpszBuffer);
  362. // adjust the controls accordingly.
  363. SetControlValues();
  364. }
  365. ///////////////////////////////////////////////////////////////////////////////
  366. // change the title of the app to reflect the currently selected profile
  367. ///////////////////////////////////////////////////////////////////////////////
  368. void ResetTitle(TCHAR lpszBuffer[])
  369. {
  370. HWND hWndParent;
  371. TCHAR lpszCaption[MAXKEYSIZE] = TEXT("");
  372. // change window caption
  373. LoadString (g_hInst, IDS_WINDOW_TITLE,
  374. lpszCaption, sizeof (lpszCaption));
  375. _tcscat(lpszCaption, lpszBuffer);
  376. hWndParent = GetParent(g_hwndProfilesDlg);
  377. SendMessage(hWndParent, WM_SETTEXT, 0,
  378. (LPARAM) lpszCaption);
  379. }
  380. ///////////////////////////////////////////////////////////////////////////////
  381. void SetEditCell(TCHAR lpszBuffer[],
  382. HWND hwndProfilesCBO)
  383. {
  384. LRESULT i;
  385. //
  386. // set edit cell text to selected profile string
  387. //
  388. i = SendMessage(hwndProfilesCBO,
  389. CB_FINDSTRING, 0,
  390. (LPARAM) lpszBuffer);
  391. SendMessage(hwndProfilesCBO,
  392. CB_SETCURSEL, i, 0);
  393. }
  394. ///////////////////////////////////////////////////////////////////////////////
  395. // Recursive function to allocate memory and read in the values stored
  396. // in the registry.
  397. ///////////////////////////////////////////////////////////////////////////////
  398. void GetClientProfileNames(TCHAR lpszClientProfilePath[])
  399. {
  400. TCHAR lpszKeyName[MAX_PATH];
  401. ULONG lpPathLen = MAX_PATH;
  402. static HKEY hKey;
  403. static int nKeyIndex = 0;
  404. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszClientProfilePath, 0,
  405. KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
  406. if (RegEnumKeyEx(hKey, nKeyIndex, &lpszKeyName[0], &lpPathLen,
  407. NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
  408. //
  409. // allocate memory for the first key
  410. //
  411. if (nKeyIndex == 0) {
  412. g_pkfProfile = (PROFILE_KEY_INFO *) malloc
  413. (sizeof(PROFILE_KEY_INFO));
  414. g_pkfStart = g_pkfProfile;
  415. }
  416. //
  417. // Catches failure if malloc fails above
  418. //
  419. if(!g_pkfProfile)
  420. {
  421. return;
  422. }
  423. // save the key name to the data structure
  424. _tcsncpy(g_pkfProfile->KeyInfo->Key, lpszKeyName,
  425. sizeof(g_pkfProfile->KeyInfo->Key)/sizeof(TCHAR));
  426. // give the data element an index number
  427. g_pkfProfile->Index = nKeyIndex;
  428. // allocate memory for the next structure
  429. g_pkfProfile->Next = (PROFILE_KEY_INFO *) malloc
  430. (sizeof(PROFILE_KEY_INFO));
  431. // increment the pointer to the next element
  432. g_pkfProfile = g_pkfProfile->Next;
  433. // close the current registry key
  434. RegCloseKey(hKey);
  435. if(!g_pkfProfile)
  436. {
  437. return;
  438. }
  439. nKeyIndex++;
  440. GetClientProfileNames(lpszClientProfilePath);
  441. }
  442. RegCloseKey(hKey);
  443. }
  444. nKeyIndex = 0;
  445. }
  446. ///////////////////////////////////////////////////////////////////////////////
  447. // adjust all of the controls in the application to the values stored
  448. // by the profile.
  449. ///////////////////////////////////////////////////////////////////////////////
  450. void SetControlValues()
  451. {
  452. TCHAR lpszBuffer[MAXKEYSIZE];
  453. HWND hwndComboCache;
  454. static HWND hwndSliderNumCaches;
  455. static HWND hwndSliderDistProp[PERCENT_COMBO_COUNT];
  456. static HWND hwndSliderDistBuddy[PERCENT_COMBO_COUNT];
  457. static HWND hwndPropChkBox[PERCENT_COMBO_COUNT];
  458. static HWND hwndSlider[NUMBER_OF_SLIDERS];
  459. static HWND hwndSliderEditBuddy[NUMBER_OF_SLIDERS];
  460. static HWND hwndEditNumCaches;
  461. static HWND hwndComboTextFrag;
  462. static HWND hwndComboOrder;
  463. static HWND hwndRadioShadowEn, hwndRadioShadowDis;
  464. static HWND hwndRadioDedicatedEn, hwndRadioDedicatedDis;
  465. static TCHAR lpszRegPath[MAX_PATH];
  466. static UINT nGlyphBuffer;
  467. int nPos;
  468. int i;
  469. LoadString (g_hInst, IDS_REG_PATH, lpszRegPath, sizeof (lpszRegPath));
  470. // shadow bitmap page *****************************************************
  471. hwndComboCache = GetDlgItem(g_hwndShadowBitmapDlg,
  472. IDC_COMBO_CACHE_SIZE);
  473. hwndSliderNumCaches = GetDlgItem(g_hwndShadowBitmapDlg,
  474. IDC_SLD_NO_CACHES);
  475. hwndEditNumCaches = GetDlgItem(g_hwndShadowBitmapDlg,
  476. IDC_TXT_NO_CACHES);
  477. for (i = 0; i < PERCENT_COMBO_COUNT; i++) {
  478. _itot(g_KeyInfo[i + CACHEPROP1].CurrentKeyValue,
  479. lpszBuffer, 10);
  480. hwndSliderDistProp[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  481. IDC_SLD_DST_PROP_1 + i);
  482. hwndSliderDistBuddy[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  483. IDC_TXT_DST_PROP_1 + i);
  484. SetWindowText(hwndSliderDistBuddy[i], lpszBuffer);
  485. hwndPropChkBox[i] = GetDlgItem(g_hwndShadowBitmapDlg,
  486. IDC_CHK_CSH_1 + i);
  487. }
  488. //
  489. // enable/disable check boxes and sliders
  490. //
  491. EnableControls(g_hwndShadowBitmapDlg, hwndSliderDistProp,
  492. hwndPropChkBox, hwndSliderDistBuddy,
  493. hwndEditNumCaches, hwndSliderNumCaches,
  494. PERCENT_COMBO_COUNT, lpszRegPath);
  495. _itot(g_KeyInfo[CACHESIZEINDEX].CurrentKeyValue, lpszBuffer, 10);
  496. SetWindowText(hwndComboCache, lpszBuffer);
  497. // glyph page *************************************************************
  498. hwndComboTextFrag = GetDlgItem(g_hwndGlyphCacheDlg, IDC_CBO_TXT_FRAG);
  499. switch (g_KeyInfo[GLYPHINDEX].CurrentKeyValue) {
  500. case 0:
  501. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_NONE, TRUE);
  502. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_PARTIAL, FALSE);
  503. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_FULL, FALSE);
  504. break;
  505. case 1:
  506. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_NONE, FALSE);
  507. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_PARTIAL, TRUE);
  508. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_FULL, FALSE);
  509. break;
  510. case 2:
  511. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_NONE, FALSE);
  512. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_PARTIAL, FALSE);
  513. CheckDlgButton(g_hwndGlyphCacheDlg, IDC_RADIO_FULL, TRUE);
  514. break;
  515. }
  516. _itot(g_KeyInfo[TEXTFRAGINDEX].CurrentKeyValue, lpszBuffer, 10);
  517. SendMessage(hwndComboTextFrag, CB_SELECTSTRING, -1,
  518. (LPARAM)(LPCSTR) lpszBuffer);
  519. for (i = 0; i < NUMBER_OF_SLIDERS; i++) {
  520. hwndSlider[i] = GetDlgItem(g_hwndGlyphCacheDlg,
  521. (IDC_SLIDER1 + i));
  522. hwndSliderEditBuddy[i] = GetDlgItem(g_hwndGlyphCacheDlg,
  523. (IDC_STATIC1 + i));
  524. SetWindowLongPtr(hwndSlider[i], GWLP_USERDATA, i);
  525. _itot(g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue,
  526. (lpszBuffer), 10);
  527. //
  528. // position the thumb on the slider control
  529. //
  530. nGlyphBuffer = g_KeyInfo[i + GLYPHCACHEBASE].CurrentKeyValue;
  531. #ifdef _X86_
  532. // EXECUTE ASSEMBLER CODE ONLY IF X86 PROCESSOR
  533. // BSF: Bit Scan Forward -
  534. // Scans the value contained in the EAX regiseter
  535. // for the first significant (1) bit.
  536. // This function returns the location of the first
  537. // significant bit. The function is used in this
  538. // application as a base 2 logarythm. The location
  539. // of the bit is determined, stored in the nPos
  540. // variable, and nPos is used to set the slider
  541. // control. ie. If the register value is 4, nPos
  542. // is set to 2 (00000100). 10 minus 2 (position 8
  543. // on the slider control) represents the value 4.
  544. __asm
  545. {
  546. BSF EAX, nGlyphBuffer
  547. MOV nPos, EAX
  548. }
  549. nPos = 10 - nPos;
  550. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, (LPARAM)nPos);
  551. #else
  552. switch (nGlyphBuffer) {
  553. case 4:
  554. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 8);
  555. break;
  556. case 8:
  557. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 7);
  558. break;
  559. case 16:
  560. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 6);
  561. break;
  562. case 32:
  563. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 5);
  564. break;
  565. case 64:
  566. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 4);
  567. break;
  568. case 128:
  569. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 3);
  570. break;
  571. case 256:
  572. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 2);
  573. break;
  574. case 512:
  575. SendMessage(hwndSlider[i], TBM_SETPOS, TRUE, 1);
  576. break;
  577. }
  578. #endif
  579. }
  580. //misc page ***************************************************************
  581. hwndComboOrder = GetDlgItem(g_hwndMiscDlg, IDC_COMBO_ORDER);
  582. hwndRadioShadowEn = GetDlgItem(g_hwndMiscDlg, IDC_SHADOW_ENABLED);
  583. hwndRadioShadowDis = GetDlgItem(g_hwndMiscDlg, IDC_SHADOW_DISABLED);
  584. hwndRadioDedicatedEn = GetDlgItem(g_hwndMiscDlg, IDC_DEDICATED_ENABLED);
  585. hwndRadioDedicatedDis = GetDlgItem(g_hwndMiscDlg, IDC_DEDICATED_DISABLED);
  586. //
  587. // set radio buttons
  588. //
  589. RestoreSettings(g_hwndMiscDlg, SHADOWINDEX,
  590. IDC_SHADOW_DISABLED, IDC_SHADOW_ENABLED,
  591. g_pkfProfile->KeyInfo[i].KeyPath);
  592. RestoreSettings(g_hwndMiscDlg, DEDICATEDINDEX,
  593. IDC_DEDICATED_ENABLED, IDC_DEDICATED_DISABLED,
  594. g_pkfProfile->KeyInfo[i].KeyPath);
  595. _itot( g_KeyInfo[ORDERINDEX].CurrentKeyValue,
  596. lpszBuffer, 10);
  597. SetWindowText(hwndComboOrder, lpszBuffer);
  598. }
  599. ///////////////////////////////////////////////////////////////////////////////
  600. //
  601. //
  602. // send handles to controls and the integer value for the number of
  603. // enabled combo & check boxes
  604. ///////////////////////////////////////////////////////////////////////////////
  605. void EnableControls(HWND hDlg,
  606. HWND hwndSliderDistProp[],
  607. HWND hwndPropChkBox[],
  608. HWND hwndSliderDistBuddy[],
  609. HWND hwndEditNumCaches,
  610. HWND hwndSliderNumCaches,
  611. int nNumCellCaches,
  612. TCHAR lpszRegPath[])
  613. {
  614. int i, nPos;
  615. TCHAR lpszBuffer[6];
  616. for (i = 0; i < nNumCellCaches; i++) {
  617. //
  618. // check/uncheck check boxes for persistent caching
  619. //
  620. if (g_KeyInfo[BM_PERSIST_BASE_INDEX + i].CurrentKeyValue == 0)
  621. CheckDlgButton(hDlg, IDC_CHK_CSH_1 + i, FALSE);
  622. else
  623. CheckDlgButton(hDlg, IDC_CHK_CSH_1 + i, TRUE);
  624. //
  625. // enable/disable check & slider controls
  626. //
  627. if (i < (INT) g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue) {
  628. EnableWindow(hwndSliderDistProp[i], TRUE);
  629. EnableWindow(hwndPropChkBox[i], TRUE);
  630. EnableWindow(hwndSliderDistBuddy[i], TRUE);
  631. _itot(g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue,
  632. lpszBuffer, 10);
  633. SetWindowText(hwndSliderDistBuddy[i], lpszBuffer);
  634. //
  635. // position the thumb on the slider control
  636. //
  637. nPos = g_KeyInfo[CACHEPROP1 + i].CurrentKeyValue;
  638. SendMessage(hwndSliderDistProp[i], TBM_SETPOS, TRUE,
  639. 11 - nPos / 10);
  640. } else {
  641. EnableWindow(hwndSliderDistProp[i], FALSE);
  642. EnableWindow(hwndPropChkBox[i], FALSE);
  643. EnableWindow(hwndSliderDistBuddy[i], FALSE);
  644. SetWindowText(hwndSliderDistBuddy[i], NULL);
  645. CheckDlgButton(hDlg, IDC_CHK_CSH_1 + i, FALSE);
  646. SendMessage(hwndSliderDistProp[i], TBM_SETPOS, TRUE, 11);
  647. }
  648. }
  649. //
  650. // position the thumb on the slider control (num caches)
  651. //
  652. SendMessage(hwndSliderNumCaches, TBM_SETPOS, TRUE,
  653. g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue + 1);
  654. _itot( g_KeyInfo[NUM_CELL_CACHES_INDEX].CurrentKeyValue,
  655. lpszBuffer, 10);
  656. //
  657. // display string in edit cell
  658. //
  659. SetWindowText(hwndEditNumCaches, lpszBuffer);
  660. }
  661. // end of file
  662. ///////////////////////////////////////////////////////////////////////////////
  663. // pass the key name along with the key path and the function
  664. // returns the value stored in the registry
  665. // DWORD values
  666. ///////////////////////////////////////////////////////////////////////////////
  667. int GetKeyVal(TCHAR lpszRegPath[MAX_PATH], TCHAR lpszKeyName[MAX_PATH])
  668. {
  669. int nKeyValue;
  670. HKEY hKey;
  671. DWORD dwType;
  672. DWORD dwSize;
  673. dwType = REG_SZ;
  674. dwSize = sizeof(DWORD);
  675. if (RegOpenKeyEx(HKEY_CURRENT_USER, lpszRegPath, 0,
  676. KEY_READ, &hKey) == ERROR_SUCCESS) {
  677. if (RegQueryValueEx(hKey, lpszKeyName, 0,
  678. &dwType, (LPBYTE) &nKeyValue,
  679. &dwSize) == ERROR_SUCCESS) {
  680. RegCloseKey(hKey);
  681. return nKeyValue;
  682. }
  683. RegCloseKey(hKey);
  684. }
  685. return 0;
  686. }
  687. ///////////////////////////////////////////////////////////////////////////////
  688. // send path AND key name to set key value - used with foreground window
  689. // lock timeout.
  690. ///////////////////////////////////////////////////////////////////////////////
  691. void SetRegKeyVal(TCHAR lpszRegPath[MAX_PATH],
  692. TCHAR lpszKeyName[MAX_PATH],
  693. int nKeyValue)
  694. {
  695. HKEY hKey;
  696. DWORD dwDisposition;
  697. RegCreateKeyEx(HKEY_CURRENT_USER, lpszRegPath,
  698. 0, NULL, REG_OPTION_NON_VOLATILE,
  699. KEY_ALL_ACCESS, 0, &hKey, &dwDisposition);
  700. //
  701. // write the key value to the registry
  702. //
  703. if(hKey != NULL) {
  704. RegSetValueEx(hKey, lpszKeyName, 0, REG_DWORD,
  705. & (unsigned char) (nKeyValue),
  706. sizeof(DWORD));
  707. RegCloseKey(hKey);
  708. }
  709. }
  710. //////////////////////////////////////////////////////////////////////////////