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.

117 lines
2.4 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // code common to several pages
  4. //
  5. // 12-16-97 sburns
  6. #include "headers.hxx"
  7. #include "common.hpp"
  8. #include "resource.h"
  9. //#include "state.hpp"
  10. //#include "ds.hpp"
  11. //#include <DiagnoseDcNotFound.hpp>
  12. // Creates the fonts for setLargeFonts().
  13. //
  14. // hDialog - handle to a dialog to be used to retrieve a device
  15. // context.
  16. //
  17. // bigBoldFont - receives the handle of the big bold font created.
  18. void
  19. InitFonts(
  20. HWND hDialog,
  21. HFONT& bigBoldFont)
  22. {
  23. LOG_FUNCTION(InitFonts);
  24. ASSERT(Win::IsWindow(hDialog));
  25. HRESULT hr = S_OK;
  26. do
  27. {
  28. NONCLIENTMETRICS ncm;
  29. memset(&ncm, 0, sizeof(ncm));
  30. ncm.cbSize = sizeof(ncm);
  31. hr = Win::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  32. BREAK_ON_FAILED_HRESULT(hr);
  33. LOGFONT bigBoldLogFont = ncm.lfMessageFont;
  34. bigBoldLogFont.lfWeight = FW_BOLD;
  35. String fontName = String::load(IDS_BIG_BOLD_FONT_NAME);
  36. // ensure null termination 260237
  37. memset(bigBoldLogFont.lfFaceName, 0, LF_FACESIZE * sizeof(TCHAR));
  38. size_t fnLen = fontName.length();
  39. fontName.copy(
  40. bigBoldLogFont.lfFaceName,
  41. // don't copy over the last null
  42. min(LF_FACESIZE - 1, fnLen));
  43. unsigned fontSize = 0;
  44. String::load(IDS_BIG_BOLD_FONT_SIZE).convert(fontSize);
  45. ASSERT(fontSize);
  46. HDC hdc = 0;
  47. hr = Win::GetDC(hDialog, hdc);
  48. BREAK_ON_FAILED_HRESULT(hr);
  49. bigBoldLogFont.lfHeight =
  50. - ::MulDiv(
  51. static_cast<int>(fontSize),
  52. Win::GetDeviceCaps(hdc, LOGPIXELSY),
  53. 72);
  54. hr = Win::CreateFontIndirect(bigBoldLogFont, bigBoldFont);
  55. BREAK_ON_FAILED_HRESULT(hr);
  56. Win::ReleaseDC(hDialog, hdc);
  57. }
  58. while (0);
  59. }
  60. void
  61. SetControlFont(HWND parentDialog, int controlID, HFONT font)
  62. {
  63. LOG_FUNCTION(SetControlFont);
  64. ASSERT(Win::IsWindow(parentDialog));
  65. ASSERT(controlID);
  66. ASSERT(font);
  67. HWND control = Win::GetDlgItem(parentDialog, controlID);
  68. if (control)
  69. {
  70. Win::SetWindowFont(control, font, true);
  71. }
  72. }
  73. void
  74. SetLargeFont(HWND dialog, int bigBoldResID)
  75. {
  76. LOG_FUNCTION(SetLargeFont);
  77. ASSERT(Win::IsWindow(dialog));
  78. ASSERT(bigBoldResID);
  79. static HFONT bigBoldFont = 0;
  80. if (!bigBoldFont)
  81. {
  82. InitFonts(dialog, bigBoldFont);
  83. }
  84. SetControlFont(dialog, bigBoldResID, bigBoldFont);
  85. }