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.

825 lines
24 KiB

  1. /**************************************************************************\
  2. * Module Name: general.cpp
  3. *
  4. * Contains all the code to manage multiple devices
  5. *
  6. * Copyright (c) Microsoft Corp. 1995-1996 All Rights Reserved
  7. *
  8. * NOTES:
  9. *
  10. * History: Create by dli on 7/21/97
  11. *
  12. \**************************************************************************/
  13. #include "priv.h"
  14. #include "SettingsPg.h"
  15. extern INT_PTR CALLBACK CustomFontDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  16. //FEATURE: (dli) This should be put in regstr.h
  17. static const TCHAR sc_szRegFontSize[] = REGSTR_PATH_SETUP TEXT("\\") REGSTR_VAL_FONTSIZE;
  18. static const TCHAR sc_szQuickResRegName[] = TEXT("Taskbar Display Controls");
  19. static const TCHAR sc_szQuickResCommandLine[] = TEXT("RunDLL deskcp16.dll,QUICKRES_RUNDLLENTRY");
  20. static const TCHAR sc_szQuickResClass[] = TEXT("SysQuickRes");
  21. static const char c_szQuickResCommandLine[] = "RunDLL deskcp16.dll,QUICKRES_RUNDLLENTRY";
  22. //-----------------------------------------------------------------------------
  23. static const DWORD sc_GeneralHelpIds[] =
  24. {
  25. // font size
  26. IDC_FONTSIZEGRP, NO_HELP, // IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_FONTSIZE,
  27. IDC_FONT_SIZE_STR, IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_FONTSIZE,
  28. IDC_FONT_SIZE, IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_FONTSIZE,
  29. IDC_CUSTFONTPER, IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_FONTSIZE,
  30. // group box
  31. IDC_DYNA, NO_HELP, // IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_DYNA,
  32. // radio buttons
  33. IDC_DYNA_TEXT, NO_HELP,
  34. IDC_NODYNA, IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_RESTART,
  35. IDC_YESDYNA, IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_DONT_RESTART,
  36. IDC_SHUTUP, IDH_DISPLAY_SETTINGS_ADVANCED_GENERAL_ASK_ME,
  37. IDC_SETTINGS_GEN_COMPATWARNING, (DWORD)-1,
  38. 0, 0
  39. };
  40. BOOL IsUserAdmin(VOID);
  41. /*--------------------------------------------------------------------------*
  42. *--------------------------------------------------------------------------*/
  43. class CGeneralDlg {
  44. private:
  45. int _idCustomFonts;
  46. int _iDynaOrg;
  47. IUnknown * _punkSite;
  48. HWND _hwndFontList;
  49. HWND _hDlg;
  50. //
  51. // current log pixels of the screen.
  52. // does not change !
  53. int _cLogPix;
  54. BOOL _fForceSmallFont;
  55. BOOL _InitFontList();
  56. void _InitDynaCDSPreference();
  57. LRESULT _OnNotify(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  58. public:
  59. CGeneralDlg(GENERAL_ADVDLG_INITPARAMS * pInitParams);
  60. void InitGeneralDlg(HWND hDlg);
  61. void SetFontSizeText( int cdpi );
  62. BOOL ChangeFontSize();
  63. void HandleGeneralApply(HWND hDlg);
  64. void HandleFontSelChange();
  65. void ForceSmallFont();
  66. LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  67. };
  68. CGeneralDlg::CGeneralDlg(GENERAL_ADVDLG_INITPARAMS * pInitParams) : _fForceSmallFont(pInitParams->fFoceSmallFont), _idCustomFonts(-1)
  69. {
  70. HKEY hkFont;
  71. DWORD cb;
  72. _punkSite = pInitParams->punkSite;
  73. // For font size just always use the one of the current screen.
  74. // Whether or not we are testing the current screen.
  75. _cLogPix = 96;
  76. // If the size does not match what is in the registry, then install
  77. // the new one
  78. if ((RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  79. SZ_FONTDPI_PROF,
  80. 0,
  81. KEY_READ,
  82. &hkFont) == ERROR_SUCCESS) ||
  83. (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  84. SZ_FONTDPI,
  85. 0,
  86. KEY_READ,
  87. &hkFont) == ERROR_SUCCESS))
  88. {
  89. cb = sizeof(DWORD);
  90. if (RegQueryValueEx(hkFont,
  91. SZ_LOGPIXELS,
  92. NULL,
  93. NULL,
  94. (LPBYTE) &_cLogPix,
  95. &cb) != ERROR_SUCCESS)
  96. {
  97. _cLogPix = 96;
  98. }
  99. RegCloseKey(hkFont);
  100. }
  101. };
  102. //
  103. // The purpose of this function is to check if the OriginalDPI value was already saved in the
  104. // per-machine part of the registry. If this is NOT present, then get the system DPI and save it
  105. // there. We want to do it just once for a machine. When an end-user logsin, we need to detect if
  106. // we need to change the sizes of UI fonts based on DPI change. We use the "AppliedDPI", which is
  107. // stored on the per-user branch of the registry to determine the dpi change. If this "AppliedDPI"
  108. // is missing, then this OriginalDPI value will be used. If this value is also missing, that
  109. // implies that nobody has changed the system DPI value.
  110. //
  111. void SaveOriginalDPI()
  112. {
  113. //See if the "OriginalDPI value is present under HKEY_LOCAL_MACHINE.
  114. HKEY hk;
  115. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  116. SZ_CONTROLPANEL,
  117. 0,
  118. KEY_READ | KEY_WRITE,
  119. &hk) == ERROR_SUCCESS)
  120. {
  121. DWORD dwOriginalDPI;
  122. DWORD dwDataSize = sizeof(dwOriginalDPI);
  123. if (RegQueryValueEx(hk, SZ_ORIGINALDPI, NULL, NULL,
  124. (LPBYTE)&dwOriginalDPI, &dwDataSize) != ERROR_SUCCESS)
  125. {
  126. //"OriginalDPI" value is not present in the registry. Now, get the DPI
  127. // and save it as the "OriginalDPI"
  128. HDC hdc = GetDC(NULL);
  129. dwOriginalDPI = GetDeviceCaps(hdc, LOGPIXELSY);
  130. ReleaseDC(NULL, hdc);
  131. }
  132. DWORD dwSize = sizeof(dwOriginalDPI);
  133. //Save the current DPI as the "OriginalDPI" value.
  134. RegSetValueEx(hk, SZ_ORIGINALDPI, NULL, REG_DWORD, (LPBYTE) &dwOriginalDPI, dwSize);
  135. RegCloseKey(hk);
  136. }
  137. }
  138. BOOL CGeneralDlg::ChangeFontSize()
  139. {
  140. int cFontSize = 0;
  141. int cForcedFontSize;
  142. int cUIfontSize;
  143. // Change font size if necessary
  144. int i = ComboBox_GetCurSel(_hwndFontList);
  145. if (i != CB_ERR )
  146. {
  147. TCHAR awcDesc[10];
  148. cFontSize = (int)ComboBox_GetItemData(_hwndFontList, i);
  149. if ( (cFontSize != CB_ERR) &&
  150. (cFontSize != 0) &&
  151. (cFontSize != _cLogPix))
  152. {
  153. //Save the original DPI before the DPI ever changed.
  154. SaveOriginalDPI();
  155. cUIfontSize = cForcedFontSize = cFontSize;
  156. if (_idCustomFonts == i)
  157. {
  158. BOOL predefined = FALSE;
  159. int count = ComboBox_GetCount(_hwndFontList);
  160. int max = -1, min = 0xffff, dpi;
  161. for (i = 0; i < count; i++)
  162. {
  163. if (i == _idCustomFonts)
  164. continue;
  165. dpi = (int)ComboBox_GetItemData(_hwndFontList, i);
  166. if (dpi == cFontSize)
  167. {
  168. predefined = TRUE;
  169. break;
  170. }
  171. if (dpi < min) min = dpi;
  172. if (dpi > max) max = dpi;
  173. }
  174. if (!predefined) {
  175. if ((cFontSize > max) || (cFontSize + (max-min)/2 > max))
  176. cForcedFontSize = max;
  177. else
  178. cForcedFontSize = min;
  179. // Currently our Custom font picker allows end-users to pick upto 500% of
  180. // normal font size; But, when we enlarge the UI fonts to this size, the
  181. // system becomes un-usable after reboot. So, what we do here is to allow
  182. // ui font sizes to grow up to 200% and then all further increases are
  183. // proportionally reduced such that the maximum possible ui font size is only
  184. // 250%. (i.e the range 200% to 500% is mapped on to a range of 200% to 250%)
  185. // In other words, we allow upto 192 dpi (200%) with no modification. For any
  186. // DPI greater than 192, we proportionately reduce it such that the highest DPI
  187. // is only 240!
  188. if(cUIfontSize > 192)
  189. cUIfontSize = 192 + ((cUIfontSize - 192)/6);
  190. }
  191. }
  192. // Call setup to change the font size.
  193. wsprintf(awcDesc, TEXT("%d"), cForcedFontSize);
  194. if (SetupChangeFontSize(_hDlg, awcDesc) == NO_ERROR)
  195. {
  196. IPropertyBag * pPropertyBag;
  197. // Font change has succeeded; Now there is a new DPI to be applied to UI fonts!
  198. if (_punkSite && SUCCEEDED(GetPageByCLSID(_punkSite, &PPID_BaseAppearance, &pPropertyBag)))
  199. {
  200. // Use _punkSite to push the DPI back up to the Appearance tab where it's state lives.
  201. LogStatus("CGeneralDlg::ChangeFontSize() user changed DPI to %d\r\n", cUIfontSize);
  202. SHPropertyBag_WriteInt(pPropertyBag, SZ_PBPROP_DPI_MODIFIED_VALUE, cUIfontSize);
  203. pPropertyBag->Release();
  204. }
  205. // A font size change will require a system reboot.
  206. PropSheet_RestartWindows(GetParent(_hDlg));
  207. HrRegSetDWORD(HKEY_LOCAL_MACHINE, SZ_FONTDPI_PROF, SZ_LOGPIXELS, cFontSize);
  208. HrRegSetDWORD(HKEY_LOCAL_MACHINE, SZ_FONTDPI, SZ_LOGPIXELS, cFontSize);
  209. }
  210. else
  211. {
  212. // Setup failed.
  213. FmtMessageBox(_hDlg,
  214. MB_ICONSTOP | MB_OK,
  215. ID_DSP_TXT_CHANGE_FONT,
  216. ID_DSP_TXT_ADMIN_INSTALL);
  217. return FALSE;
  218. }
  219. }
  220. }
  221. if (cFontSize == 0)
  222. {
  223. // If we could not read the inf, then ignore the font selection
  224. // and don't force the reboot on account of that.
  225. cFontSize = _cLogPix;
  226. }
  227. return TRUE;
  228. }
  229. void CGeneralDlg::InitGeneralDlg(HWND hDlg)
  230. {
  231. _hDlg = hDlg;
  232. _hwndFontList = GetDlgItem(_hDlg, IDC_FONT_SIZE);
  233. _InitFontList();
  234. _iDynaOrg = -1;
  235. }
  236. void CGeneralDlg::_InitDynaCDSPreference()
  237. {
  238. int iDyna = GetDynaCDSPreference();
  239. if(iDyna != _iDynaOrg)
  240. {
  241. _iDynaOrg = iDyna;
  242. CheckDlgButton(_hDlg, IDC_SHUTUP, FALSE);
  243. CheckDlgButton(_hDlg, IDC_YESDYNA, FALSE);
  244. CheckDlgButton(_hDlg, IDC_NODYNA, FALSE);
  245. if (_iDynaOrg & DCDSF_ASK)
  246. CheckDlgButton(_hDlg, IDC_SHUTUP, TRUE);
  247. else if (_iDynaOrg & DCDSF_DYNA)
  248. CheckDlgButton(_hDlg, IDC_YESDYNA, TRUE);
  249. else
  250. CheckDlgButton(_hDlg, IDC_NODYNA, TRUE);
  251. }
  252. }
  253. static UINT s_DPIDisplayNames[] =
  254. {
  255. 96 /*DPI*/, IDS_SETTING_GEN_96DPI,
  256. 120 /*DPI*/, IDS_SETTING_GEN_120DPI,
  257. };
  258. HRESULT _LoadDPIDisplayName(int nDPI, LPTSTR pszDisplayName, DWORD cchSize)
  259. {
  260. HRESULT hr = E_FAIL;
  261. int nIndex;
  262. for (nIndex = 0; nIndex < ARRAYSIZE(s_DPIDisplayNames); nIndex += 2)
  263. {
  264. if (nDPI == (int)s_DPIDisplayNames[nIndex])
  265. {
  266. LoadString(HINST_THISDLL, s_DPIDisplayNames[nIndex + 1], pszDisplayName, cchSize);
  267. hr = S_OK;
  268. break;
  269. }
  270. }
  271. return hr;
  272. }
  273. // Init Font sizes
  274. //
  275. // For NT:
  276. // Read the supported fonts out of the inf file(s)
  277. // Select was the user currently has.
  278. //
  279. // For WIN95:
  280. BOOL CGeneralDlg::_InitFontList() {
  281. int i;
  282. ASSERT(_hwndFontList);
  283. ULONG uCurSel = (ULONG) -1;
  284. int cPix = 0;
  285. TCHAR szBuf2[100];
  286. HINF InfFileHandle;
  287. INFCONTEXT infoContext;
  288. //
  289. // Get all font entries from both inf files
  290. //
  291. InfFileHandle = SetupOpenInfFile(TEXT("font.inf"),
  292. NULL,
  293. INF_STYLE_WIN4,
  294. NULL);
  295. if (InfFileHandle != INVALID_HANDLE_VALUE)
  296. {
  297. if (SetupFindFirstLine(InfFileHandle,
  298. TEXT("Font Sizes"),
  299. NULL,
  300. &infoContext))
  301. {
  302. for (;;)
  303. {
  304. TCHAR awcDesc[LINE_LEN];
  305. if (SetupGetStringField(&infoContext,
  306. 0,
  307. awcDesc,
  308. ARRAYSIZE(awcDesc),
  309. NULL) &&
  310. SetupGetIntField(&infoContext,
  311. 1,
  312. &cPix))
  313. {
  314. // Add it to the list box
  315. _LoadDPIDisplayName(cPix, awcDesc, ARRAYSIZE(awcDesc));
  316. i = ComboBox_AddString(_hwndFontList, awcDesc);
  317. if (i != CB_ERR)
  318. {
  319. ComboBox_SetItemData(_hwndFontList, i, cPix);
  320. if (_cLogPix == cPix)
  321. uCurSel = i;
  322. }
  323. }
  324. //
  325. // Try to get the next line.
  326. //
  327. if (!SetupFindNextLine(&infoContext,
  328. &infoContext))
  329. {
  330. break;
  331. }
  332. }
  333. }
  334. SetupCloseInfFile(InfFileHandle);
  335. }
  336. //
  337. // Put in the custom fonts string
  338. //
  339. LoadString(HINST_THISDLL, ID_DSP_CUSTOM_FONTS, szBuf2, ARRAYSIZE(szBuf2));
  340. _idCustomFonts = ComboBox_AddString(_hwndFontList, szBuf2);
  341. if (_idCustomFonts != CB_ERR)
  342. ComboBox_SetItemData(_hwndFontList, _idCustomFonts, _cLogPix);
  343. if (uCurSel == (ULONG) -1) {
  344. uCurSel = _idCustomFonts;
  345. }
  346. // NOTE: We currently change the font size by calling SetupChangeFontSize
  347. // This function will fail if the user is not an administrator. We would like to
  348. // disable this functionality but system admins want to be able to allow
  349. // non-admins to install by turning on a registry flag. NT4 supports this,
  350. // so we need to also. In order for this to work, we need to leave the
  351. // install button enabled. This backs out NT #318617. Contact
  352. // the following people about this issue: Marius Marin, Tom Politis,
  353. // Naresh Jivanji. -BryanSt 3/24/2000
  354. // EnableWindow(_hwndFontList, IsUserAdmin());
  355. if (_fForceSmallFont && (_cLogPix == 96))
  356. this->ForceSmallFont();
  357. else
  358. {
  359. //
  360. // Select the right entry.
  361. //
  362. ComboBox_SetCurSel(_hwndFontList, uCurSel);
  363. this->SetFontSizeText( _cLogPix );
  364. }
  365. return TRUE;
  366. }
  367. void CGeneralDlg::SetFontSizeText( int cdpi )
  368. {
  369. HWND hwndCustFontPer;
  370. TCHAR achStr[80];
  371. TCHAR achFnt[120];
  372. if (cdpi == CDPI_NORMAL)
  373. {
  374. LoadString(HINST_THISDLL, ID_DSP_NORMAL_FONTSIZE_TEXT, achStr, ARRAYSIZE(achStr));
  375. wsprintf(achFnt, achStr, cdpi);
  376. }
  377. else
  378. {
  379. LoadString(HINST_THISDLL, ID_DSP_CUSTOM_FONTSIZE_TEXT, achStr, ARRAYSIZE(achStr));
  380. wsprintf(achFnt, achStr, (100 * cdpi + 50) / CDPI_NORMAL, cdpi );
  381. }
  382. hwndCustFontPer = GetDlgItem(_hDlg, IDC_CUSTFONTPER);
  383. SendMessage(hwndCustFontPer, WM_SETTEXT, 0, (LPARAM)achFnt);
  384. }
  385. //
  386. // ForceSmallFont method
  387. //
  388. //
  389. void CGeneralDlg::ForceSmallFont() {
  390. int i, iSmall, dpiSmall, dpi;
  391. //
  392. // Set small font size in the listbox.
  393. //
  394. iSmall = CB_ERR;
  395. dpiSmall = 9999;
  396. for (i=0; i <=1; i++)
  397. {
  398. dpi = (int)ComboBox_GetItemData(_hwndFontList, i);
  399. if (dpi == CB_ERR)
  400. continue;
  401. if (dpi < dpiSmall || iSmall < CB_ERR)
  402. {
  403. iSmall = i;
  404. dpiSmall = dpi;
  405. }
  406. }
  407. if (iSmall != -1)
  408. ComboBox_SetCurSel(_hwndFontList, iSmall);
  409. this->SetFontSizeText(dpiSmall);
  410. EnableWindow(_hwndFontList, FALSE);
  411. }
  412. void CGeneralDlg::HandleGeneralApply(HWND hDlg)
  413. {
  414. int iDynaNew;
  415. if (IsDlgButtonChecked(hDlg, IDC_YESDYNA))
  416. iDynaNew= DCDSF_YES;
  417. else if (IsDlgButtonChecked(hDlg, IDC_NODYNA))
  418. iDynaNew= DCDSF_NO;
  419. else
  420. iDynaNew = DCDSF_PROBABLY;
  421. if (iDynaNew != _iDynaOrg)
  422. {
  423. SetDisplayCPLPreference(REGSTR_VAL_DYNASETTINGSCHANGE, iDynaNew);
  424. _iDynaOrg = iDynaNew;
  425. }
  426. BOOL bSuccess = ChangeFontSize();
  427. long lRet = (bSuccess ? PSNRET_NOERROR: PSNRET_INVALID_NOCHANGEPAGE);
  428. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, lRet);
  429. }
  430. void CGeneralDlg::HandleFontSelChange()
  431. {
  432. //
  433. // Warn the USER font changes will not be seen until after
  434. // reboot
  435. //
  436. int iCurSel;
  437. int cdpi;
  438. iCurSel = ComboBox_GetCurSel(_hwndFontList);
  439. cdpi = (int)ComboBox_GetItemData(_hwndFontList, iCurSel);
  440. if (iCurSel == _idCustomFonts) {
  441. InitDragSizeClass();
  442. cdpi = (int)DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(DLG_CUSTOMFONT),
  443. _hDlg, CustomFontDlgProc, cdpi );
  444. if (cdpi != 0)
  445. ComboBox_SetItemData(_hwndFontList, _idCustomFonts, cdpi);
  446. else
  447. cdpi = (int)ComboBox_GetItemData(_hwndFontList, _idCustomFonts);
  448. }
  449. if (cdpi != _cLogPix)
  450. {
  451. // Remove in blackcomb. We need to streamline this process. That includes verifying that
  452. // the fonts will always be on disk and there is no need to allow users to get them from
  453. // the CD.
  454. FmtMessageBox(_hDlg,
  455. MB_ICONINFORMATION,
  456. ID_DSP_TXT_CHANGE_FONT,
  457. ID_DSP_TXT_FONT_LATER);
  458. PropSheet_Changed(GetParent(_hDlg), _hDlg);
  459. }
  460. this->SetFontSizeText(cdpi);
  461. }
  462. void StartStopQuickRes(HWND hDlg, BOOL fEnable)
  463. {
  464. HWND hwnd;
  465. TryAgain:
  466. hwnd = FindWindow(sc_szQuickResClass, NULL);
  467. if (fEnable)
  468. {
  469. if (!hwnd)
  470. WinExec(c_szQuickResCommandLine, SW_SHOWNORMAL);
  471. return;
  472. }
  473. if (hwnd)
  474. {
  475. SendMessage(hwnd, WM_CLOSE, 0, 0L);
  476. goto TryAgain;
  477. }
  478. }
  479. LRESULT CGeneralDlg::_OnNotify(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  480. {
  481. LRESULT lReturn = TRUE;
  482. NMHDR *lpnm = (NMHDR *)lParam;
  483. if (lParam)
  484. {
  485. switch (lpnm->code)
  486. {
  487. case PSN_SETACTIVE:
  488. _InitDynaCDSPreference();
  489. break;
  490. case PSN_APPLY:
  491. HandleGeneralApply(hDlg);
  492. break;
  493. case NM_RETURN:
  494. case NM_CLICK:
  495. {
  496. PNMLINK pNMLink = (PNMLINK) lpnm;
  497. if (!StrCmpW(pNMLink->item.szID, L"idGameCompat"))
  498. {
  499. TCHAR szHelpURL[MAX_PATH * 2];
  500. LoadString(HINST_THISDLL, IDS_SETTING_GEN_COMPAT_HELPLINK, szHelpURL, ARRAYSIZE(szHelpURL));
  501. HrShellExecute(hDlg, NULL, szHelpURL, NULL, NULL, SW_NORMAL);
  502. }
  503. break;
  504. }
  505. default:
  506. lReturn = FALSE;
  507. break;
  508. }
  509. }
  510. return lReturn;
  511. }
  512. LRESULT CALLBACK CGeneralDlg::WndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  513. {
  514. LRESULT lReturn = TRUE;
  515. switch (message)
  516. {
  517. case WM_INITDIALOG:
  518. InitGeneralDlg(hDlg);
  519. break;
  520. case WM_NOTIFY:
  521. lReturn = _OnNotify(hDlg, message, wParam, lParam);
  522. break;
  523. case WM_COMMAND:
  524. switch (GET_WM_COMMAND_ID(wParam, lParam))
  525. {
  526. case IDC_NODYNA:
  527. case IDC_YESDYNA:
  528. case IDC_SHUTUP:
  529. if (GET_WM_COMMAND_CMD(wParam, lParam) == BN_CLICKED)
  530. PropSheet_Changed(GetParent(hDlg), hDlg);
  531. break;
  532. case IDC_FONT_SIZE:
  533. switch (GET_WM_COMMAND_CMD(wParam, lParam))
  534. {
  535. case CBN_SELCHANGE:
  536. HandleFontSelChange();
  537. break;
  538. default:
  539. break;
  540. }
  541. break;
  542. default:
  543. break;
  544. }
  545. break;
  546. case WM_HELP:
  547. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle, TEXT("display.hlp"), HELP_WM_HELP,
  548. (DWORD_PTR)(LPTSTR)sc_GeneralHelpIds);
  549. break;
  550. case WM_CONTEXTMENU:
  551. WinHelp((HWND)wParam, TEXT("display.hlp"), HELP_CONTEXTMENU,
  552. (DWORD_PTR)(LPTSTR)sc_GeneralHelpIds);
  553. break;
  554. default:
  555. return FALSE;
  556. }
  557. return lReturn;
  558. }
  559. //-----------------------------------------------------------------------------
  560. //
  561. // Callback functions PropertySheet can use
  562. //
  563. INT_PTR CALLBACK
  564. GeneralPageProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  565. {
  566. CGeneralDlg * pcgd = (CGeneralDlg * )GetWindowLongPtr(hDlg, DWLP_USER);
  567. switch (message)
  568. {
  569. case WM_INITDIALOG:
  570. ASSERT(!pcgd);
  571. ASSERT(lParam);
  572. if (((LPPROPSHEETPAGE)lParam)->lParam)
  573. {
  574. GENERAL_ADVDLG_INITPARAMS * pInitParams = (GENERAL_ADVDLG_INITPARAMS *) ((LPPROPSHEETPAGE)lParam)->lParam;
  575. pcgd = new CGeneralDlg(pInitParams);
  576. if(pcgd)
  577. {
  578. // now we need to init
  579. pcgd->InitGeneralDlg(hDlg);
  580. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)pcgd);
  581. return TRUE;
  582. }
  583. }
  584. break;
  585. case WM_DESTROY:
  586. if (pcgd)
  587. {
  588. SetWindowLongPtr(hDlg, DWLP_USER, NULL);
  589. delete pcgd;
  590. }
  591. break;
  592. default:
  593. if (pcgd)
  594. return pcgd->WndProc(hDlg, message, wParam, lParam);
  595. break;
  596. }
  597. return FALSE;
  598. }
  599. /*--------------------------------------------------------------------------*
  600. *--------------------------------------------------------------------------*/
  601. INT_PTR CALLBACK AskDynaCDSProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
  602. {
  603. int *pTemp;
  604. switch (msg)
  605. {
  606. case WM_INITDIALOG:
  607. if ((pTemp = (int *)lp) != NULL)
  608. {
  609. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pTemp);
  610. CheckDlgButton(hDlg, (*pTemp & DCDSF_DYNA)?
  611. IDC_YESDYNA : IDC_NODYNA, BST_CHECKED);
  612. }
  613. else
  614. EndDialog(hDlg, -1);
  615. break;
  616. case WM_COMMAND:
  617. switch (GET_WM_COMMAND_ID(wp, lp))
  618. {
  619. case IDOK:
  620. if ((pTemp = (int *)GetWindowLongPtr(hDlg, DWLP_USER)) != NULL)
  621. {
  622. *pTemp = IsDlgButtonChecked(hDlg, IDC_YESDYNA)? DCDSF_DYNA : 0;
  623. if (!IsDlgButtonChecked(hDlg, IDC_SHUTUP))
  624. *pTemp |= DCDSF_ASK;
  625. SetDisplayCPLPreference(REGSTR_VAL_DYNASETTINGSCHANGE, *pTemp);
  626. }
  627. EndDialog(hDlg, TRUE);
  628. break;
  629. case IDCANCEL:
  630. EndDialog(hDlg, FALSE);
  631. break;
  632. default:
  633. return FALSE;
  634. }
  635. break;
  636. default:
  637. return FALSE;
  638. }
  639. return TRUE;
  640. }
  641. int AskDynaCDS(HWND hOwner)
  642. {
  643. int val = GetDynaCDSPreference();
  644. if (val & DCDSF_ASK)
  645. {
  646. switch (DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(DLG_ASKDYNACDS),
  647. hOwner, AskDynaCDSProc, (LPARAM)(int *)&val))
  648. {
  649. case 0: // user cancelled
  650. return -1;
  651. case -1: // dialog could not be displayed
  652. val = DCDSF_NO;
  653. break;
  654. }
  655. }
  656. return ((val & DCDSF_DYNA) == DCDSF_DYNA);
  657. }
  658. BOOL IsUserAdmin(VOID)
  659. /*++
  660. Routine Description:
  661. This routine returns TRUE if the caller is an administrator.
  662. --*/
  663. {
  664. BOOL bStatus = FALSE, bIsAdmin = FALSE;
  665. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  666. PSID AdministratorsSid;
  667. bStatus = AllocateAndInitializeSid(&NtAuthority,
  668. 2,
  669. SECURITY_BUILTIN_DOMAIN_RID,
  670. DOMAIN_ALIAS_RID_ADMINS,
  671. 0, 0, 0, 0, 0, 0,
  672. &AdministratorsSid);
  673. if (bStatus)
  674. {
  675. bStatus = CheckTokenMembership(NULL, AdministratorsSid, &bIsAdmin);
  676. FreeSid(AdministratorsSid);
  677. }
  678. return (bStatus && bIsAdmin);
  679. }