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.

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