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.

377 lines
12 KiB

  1. /*---------------------------------------------**
  2. ** Copyright (c) 1998 Microsoft Corporation **
  3. ** All Rights reserved **
  4. ** **
  5. ** misc.c **
  6. ** **
  7. ** Miscellaneous dialog - TSREG **
  8. ** 07-01-98 a-clindh Created **
  9. **---------------------------------------------*/
  10. #include <windows.h>
  11. #include <winuser.h>
  12. #include <commctrl.h>
  13. #include <TCHAR.H>
  14. #include <stdlib.h>
  15. #include "tsreg.h"
  16. #include "resource.h"
  17. //HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout. Set it to zero
  18. TCHAR lpszTimoutPath[] = "Control Panel\\Desktop";
  19. TCHAR lpszTimeoutKey[] = "ForegroundLockTimeout";
  20. HWND g_hwndMiscDlg;
  21. ///////////////////////////////////////////////////////////////////////////////
  22. INT_PTR CALLBACK Miscellaneous(HWND hDlg, UINT nMsg,
  23. WPARAM wParam, LPARAM lParam)
  24. {
  25. NMHDR *lpnmhdr;
  26. static HWND hwndComboOrder;
  27. static HWND hwndRadioShadowEn, hwndRadioShadowDis;
  28. static HWND hwndRadioDedicatedEn, hwndRadioDedicatedDis;
  29. static HWND hwndSliderTimeout, hwndEditTimeout;
  30. static HWND hwndSliderFrame;
  31. static TCHAR lpszRegPath[MAX_PATH];
  32. TCHAR lpszBuffer[6];
  33. TCHAR lpszMBoxTitle[25];
  34. TCHAR lpszMBoxError[90];
  35. int i, nPos;
  36. LPHELPINFO lphi;
  37. OSVERSIONINFO osvi;
  38. static BOOL bIsWindows98orLater;
  39. static BOOL bIsNT5orLater;
  40. static int nLockValue;
  41. //
  42. // get a pointer to the NMHDR struct for apply button
  43. //
  44. lpnmhdr = (LPNMHDR) lParam;
  45. switch (nMsg) {
  46. case WM_INITDIALOG:
  47. LoadString (g_hInst, IDS_REG_PATH,
  48. lpszRegPath, sizeof (lpszRegPath));
  49. //
  50. // get handles
  51. //
  52. g_hwndMiscDlg = hDlg;
  53. hwndComboOrder = GetDlgItem(hDlg, IDC_COMBO_ORDER);
  54. hwndRadioShadowEn = GetDlgItem(hDlg, IDC_SHADOW_ENABLED);
  55. hwndRadioShadowDis = GetDlgItem(hDlg, IDC_SHADOW_DISABLED);
  56. hwndRadioDedicatedEn = GetDlgItem(hDlg, IDC_DEDICATED_ENABLED);
  57. hwndRadioDedicatedDis = GetDlgItem(hDlg, IDC_DEDICATED_DISABLED);
  58. //
  59. // lock timeout stuff ------->
  60. hwndSliderTimeout = GetDlgItem(hDlg, IDC_SLD_TIMEOUT);
  61. hwndEditTimeout = GetDlgItem(hDlg, IDC_TXT_TIMEOUT);
  62. hwndSliderFrame = GetDlgItem(hDlg, IDC_FRAME_TIMEOUT);
  63. //
  64. // Find out what operating system is is
  65. // before doing the lock timeout stuff
  66. //
  67. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  68. GetVersionEx (&osvi);
  69. bIsWindows98orLater =
  70. (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
  71. ( (osvi.dwMajorVersion > 4) ||
  72. ( (osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0) ) );
  73. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  74. GetVersionEx (&osvi);
  75. bIsNT5orLater =
  76. (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
  77. ( (osvi.dwMajorVersion > 4) ||
  78. ( (osvi.dwMajorVersion == 5) ) );
  79. if ((bIsNT5orLater == TRUE) || (bIsWindows98orLater == TRUE)) {
  80. //
  81. // set range on slider
  82. //
  83. SendMessage(hwndSliderTimeout, TBM_SETRANGE, TRUE,
  84. (LPARAM) MAKELONG(1, 6));
  85. //
  86. // get value from registry
  87. //
  88. nPos = GetKeyVal(lpszTimoutPath, lpszTimeoutKey);
  89. // Use '<=' here - if there is no reg value for
  90. // ForegroundWindowLockTimeout, the slider control
  91. // will read -1.
  92. if (nPos <= 0) {
  93. SendMessage(hwndSliderTimeout,
  94. TBM_SETPOS, TRUE, 0);
  95. _itot(0, lpszBuffer, 10);
  96. SetWindowText(hwndEditTimeout, lpszBuffer);
  97. } else {
  98. SendMessage(hwndSliderTimeout, TBM_SETPOS, TRUE,
  99. ((nPos / 100000) + 1));
  100. _itot(nPos / 100000, lpszBuffer, 10);
  101. SetWindowText(hwndEditTimeout, lpszBuffer);
  102. }
  103. } else {
  104. //
  105. // disable controls if not NT 5 / Win98 or greater
  106. //
  107. EnableWindow(hwndSliderTimeout, FALSE);
  108. EnableWindow(hwndEditTimeout, FALSE);
  109. EnableWindow(hwndSliderFrame, FALSE);
  110. }
  111. //<------------ end lock timeout stuff
  112. //_____________________________________________________
  113. //
  114. // set radio buttons
  115. //
  116. RestoreSettings(hDlg, SHADOWINDEX,
  117. IDC_SHADOW_DISABLED, IDC_SHADOW_ENABLED,
  118. lpszRegPath);
  119. RestoreSettings(hDlg, DEDICATEDINDEX,
  120. IDC_DEDICATED_ENABLED, IDC_DEDICATED_DISABLED,
  121. lpszRegPath);
  122. // ---------------------------------------
  123. // fill the combo box list with a range of
  124. // typical values.
  125. //
  126. SendMessage(hwndComboOrder, CB_ADDSTRING, 0,
  127. (LPARAM) (LPCTSTR) TEXT("0"));
  128. for (i = 5; i < 55; i+= 5) {
  129. _itot(i, lpszBuffer, 10);
  130. SendMessage(hwndComboOrder, CB_ADDSTRING, 0,
  131. (LPARAM) (LPCTSTR) lpszBuffer);
  132. } // ** end for loop
  133. for (i = 100; i < 1000; i+= 100) {
  134. _itot(i, lpszBuffer, 10);
  135. SendMessage(hwndComboOrder, CB_ADDSTRING, 0,
  136. (LPARAM) (LPCTSTR) lpszBuffer);
  137. } // ** end for loop
  138. for (i = 1000; i < 10000; i+= 1000) {
  139. _itot(i, lpszBuffer, 10);
  140. SendMessage(hwndComboOrder, CB_ADDSTRING, 0,
  141. (LPARAM) (LPCTSTR) lpszBuffer);
  142. } // ** end for loop
  143. for (i = 10000; i < 70000; i+= 10000) {
  144. _itot(i, lpszBuffer, 10);
  145. SendMessage(hwndComboOrder, CB_ADDSTRING, 0,
  146. (LPARAM) (LPCTSTR) lpszBuffer);
  147. } // ** end for loop
  148. //
  149. // end filling the combo box dropdown list.
  150. // ----------------------------------------
  151. //
  152. // limit combo box to 5 characters
  153. //
  154. SendMessage(hwndComboOrder, CB_LIMITTEXT, 5, 0);
  155. //
  156. // set edit box from registry
  157. //
  158. if (GetRegKey(ORDERINDEX, lpszRegPath) == 1) {
  159. g_KeyInfo[ORDERINDEX].CurrentKeyValue =
  160. (GetRegKeyValue(ORDERINDEX));
  161. } else {
  162. g_KeyInfo[ORDERINDEX].CurrentKeyValue =
  163. g_KeyInfo[ORDERINDEX].DefaultKeyValue;
  164. }
  165. //
  166. // write to the edit box
  167. //
  168. _itot( g_KeyInfo[ORDERINDEX].CurrentKeyValue, lpszBuffer, 10);
  169. SetWindowText(hwndComboOrder, lpszBuffer);
  170. break;
  171. case WM_NOTIFY:
  172. switch (lpnmhdr->code) {
  173. case PSN_HELP:
  174. lphi = (LPHELPINFO) lParam;
  175. WinHelp(lphi->hItemHandle,
  176. g_lpszPath, HELP_CONTENTS, lphi->iCtrlId);
  177. break;
  178. case PSN_APPLY:
  179. if (g_KeyInfo[ORDERINDEX].CurrentKeyValue ==
  180. g_KeyInfo[ORDERINDEX].DefaultKeyValue) {
  181. DeleteRegKey(ORDERINDEX, lpszRegPath);
  182. } else {
  183. SetRegKey(ORDERINDEX, lpszRegPath);
  184. }
  185. //
  186. // save radio button settings
  187. //
  188. SaveSettings(hDlg, DEDICATEDINDEX, IDC_DEDICATED_ENABLED,
  189. IDC_DEDICATED_DISABLED, lpszRegPath);
  190. SaveSettings(hDlg, SHADOWINDEX, IDC_SHADOW_DISABLED,
  191. IDC_SHADOW_ENABLED, lpszRegPath);
  192. //
  193. // Write the lock timeout (milliseconds) to
  194. // the registry.
  195. //
  196. SetRegKeyVal(lpszTimoutPath,
  197. lpszTimeoutKey,
  198. (nLockValue - 1) * 100000);
  199. break;
  200. }
  201. break;
  202. case WM_HELP:
  203. lphi = (LPHELPINFO) lParam;
  204. WinHelp(lphi->hItemHandle,
  205. g_lpszPath, HELP_CONTEXTPOPUP, lphi->iCtrlId);
  206. break;
  207. case WM_COMMAND:
  208. switch LOWORD (wParam) {
  209. case IDC_SHADOW_ENABLED:
  210. CheckDlgButton(hDlg, IDC_SHADOW_DISABLED, FALSE);
  211. break;
  212. case IDC_SHADOW_DISABLED:
  213. CheckDlgButton(hDlg, IDC_SHADOW_ENABLED, FALSE);
  214. break;
  215. case IDC_DEDICATED_ENABLED:
  216. CheckDlgButton(hDlg, IDC_DEDICATED_DISABLED, FALSE);
  217. break;
  218. case IDC_DEDICATED_DISABLED:
  219. CheckDlgButton(hDlg, IDC_DEDICATED_ENABLED, FALSE);
  220. break;
  221. case IDC_MISC_BUTTON_RESTORE:
  222. CheckDlgButton(hDlg, IDC_SHADOW_ENABLED, TRUE);
  223. CheckDlgButton(hDlg, IDC_SHADOW_DISABLED, FALSE);
  224. CheckDlgButton(hDlg, IDC_DEDICATED_DISABLED, TRUE);
  225. CheckDlgButton(hDlg, IDC_DEDICATED_ENABLED, FALSE);
  226. _itot( g_KeyInfo[ORDERINDEX].DefaultKeyValue,
  227. lpszBuffer, 10);
  228. SetWindowText(hwndComboOrder, lpszBuffer);
  229. g_KeyInfo[ORDERINDEX].CurrentKeyValue =
  230. g_KeyInfo[ORDERINDEX].DefaultKeyValue;
  231. //
  232. // Reset the position of the slider control
  233. // for the foreground lock timeout.
  234. //
  235. _itot(LOCK_TIMEOUT / 100000, lpszBuffer, 10);
  236. SetWindowText(hwndEditTimeout, lpszBuffer);
  237. SendMessage(hwndSliderTimeout, TBM_SETPOS, TRUE,
  238. ((LOCK_TIMEOUT / 100000) + 1));
  239. nLockValue = (LOCK_TIMEOUT / 100000) + 1;
  240. break;
  241. }
  242. switch HIWORD (wParam) {
  243. case CBN_SELCHANGE:
  244. g_KeyInfo[ORDERINDEX].CurrentKeyValue = (DWORD)
  245. SendMessage(hwndComboOrder, CB_GETCURSEL, 0, 0);
  246. SendMessage(hwndComboOrder, CB_GETLBTEXT,
  247. g_KeyInfo[ORDERINDEX].CurrentKeyValue,
  248. (LPARAM) lpszBuffer);
  249. g_KeyInfo[ORDERINDEX].CurrentKeyValue = _ttoi(lpszBuffer);
  250. break;
  251. case CBN_EDITUPDATE:
  252. GetWindowText(hwndComboOrder, lpszBuffer, 6);
  253. g_KeyInfo[ORDERINDEX].CurrentKeyValue = _ttoi(lpszBuffer);
  254. break;
  255. case CBN_KILLFOCUS:
  256. GetWindowText(hwndComboOrder, lpszBuffer, 6);
  257. g_KeyInfo[ORDERINDEX].CurrentKeyValue = _ttoi(lpszBuffer);
  258. if ( (g_KeyInfo[ORDERINDEX].CurrentKeyValue >
  259. MAX_ORDER_DRAW_VAL) ) {
  260. //
  261. // display error if value is off
  262. //
  263. LoadString (g_hInst, IDS_MISC_TAB, lpszMBoxTitle,
  264. sizeof (lpszMBoxTitle));
  265. LoadString (g_hInst, IDS_ODRAW_ERROR, lpszMBoxError,
  266. sizeof (lpszMBoxError));
  267. MessageBox(hDlg, lpszMBoxError,
  268. lpszMBoxTitle,
  269. MB_OK | MB_ICONEXCLAMATION);
  270. _itot(g_KeyInfo[ORDERINDEX].DefaultKeyValue,
  271. lpszBuffer, 10);
  272. SetWindowText(hwndComboOrder, lpszBuffer);
  273. g_KeyInfo[ORDERINDEX].CurrentKeyValue =
  274. g_KeyInfo[ORDERINDEX].DefaultKeyValue ;
  275. }
  276. break;
  277. }
  278. break;
  279. case WM_HSCROLL:
  280. //
  281. // get the position of the slider control
  282. //
  283. nLockValue = (int) SendMessage(hwndSliderTimeout, TBM_GETPOS, 0,0);
  284. _itot(nLockValue - 1, lpszBuffer, 10);
  285. SetWindowText(hwndEditTimeout, lpszBuffer);
  286. break;
  287. }
  288. return (FALSE);
  289. }
  290. // end of file
  291. ///////////////////////////////////////////////////////////////////////////////