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.

205 lines
4.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows NT Secure Server Roles Security Configuration Wizard
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 2002
  7. //
  8. // File: misc.cxx
  9. //
  10. // Contents: Security Configuration wizard.
  11. //
  12. // History: 13-Sep-01 EricB created
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #include "resource.h"
  17. #include "misc.h"
  18. //+----------------------------------------------------------------------------
  19. //
  20. // Function: InitFonts
  21. //
  22. // Creates the fonts for setLargeFonts().
  23. //
  24. // hDialog - handle to a dialog to be used to retrieve a device
  25. // context.
  26. //
  27. // bigBoldFont - receives the handle of the big bold font created.
  28. //-----------------------------------------------------------------------------
  29. void
  30. InitFonts(
  31. HWND hDialog,
  32. HFONT& bigBoldFont)
  33. {
  34. ASSERT(Win::IsWindow(hDialog));
  35. HRESULT hr = S_OK;
  36. do
  37. {
  38. NONCLIENTMETRICS ncm;
  39. memset(&ncm, 0, sizeof(ncm));
  40. ncm.cbSize = sizeof(ncm);
  41. hr = Win::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  42. BREAK_ON_FAILED_HRESULT(hr);
  43. LOGFONT bigBoldLogFont = ncm.lfMessageFont;
  44. bigBoldLogFont.lfWeight = FW_BOLD;
  45. String fontName = String::load(IDS_BIG_BOLD_FONT_NAME);
  46. // ensure null termination 260237
  47. memset(bigBoldLogFont.lfFaceName, 0, LF_FACESIZE * sizeof(TCHAR));
  48. size_t fnLen = fontName.length();
  49. fontName.copy(
  50. bigBoldLogFont.lfFaceName,
  51. // don't copy over the last null
  52. min(LF_FACESIZE - 1, fnLen));
  53. unsigned fontSize = 0;
  54. String::load(IDS_BIG_BOLD_FONT_SIZE).convert(fontSize);
  55. ASSERT(fontSize);
  56. HDC hdc = 0;
  57. hr = Win::GetDC(hDialog, hdc);
  58. BREAK_ON_FAILED_HRESULT(hr);
  59. bigBoldLogFont.lfHeight =
  60. - ::MulDiv(
  61. static_cast<int>(fontSize),
  62. Win::GetDeviceCaps(hdc, LOGPIXELSY),
  63. 72);
  64. hr = Win::CreateFontIndirect(bigBoldLogFont, bigBoldFont);
  65. BREAK_ON_FAILED_HRESULT(hr);
  66. Win::ReleaseDC(hDialog, hdc);
  67. }
  68. while (0);
  69. }
  70. void
  71. SetControlFont(HWND parentDialog, int controlID, HFONT font)
  72. {
  73. ASSERT(Win::IsWindow(parentDialog));
  74. ASSERT(controlID);
  75. ASSERT(font);
  76. HWND control = Win::GetDlgItem(parentDialog, controlID);
  77. if (control)
  78. {
  79. Win::SetWindowFont(control, font, true);
  80. }
  81. }
  82. //+----------------------------------------------------------------------------
  83. //
  84. // Function: SetLargeFont
  85. //
  86. // Sets the font of a control to a large point bold font as per Wizard '97
  87. // spec.
  88. //
  89. // dialog - handle to the dialog that is the parent of the control
  90. //
  91. // bigBoldResID - resource id of the control to change
  92. //-----------------------------------------------------------------------------
  93. void
  94. SetLargeFont(HWND dialog, int bigBoldResID)
  95. {
  96. ASSERT(Win::IsWindow(dialog));
  97. ASSERT(bigBoldResID);
  98. static HFONT bigBoldFont = 0;
  99. if (!bigBoldFont)
  100. {
  101. InitFonts(dialog, bigBoldFont);
  102. }
  103. SetControlFont(dialog, bigBoldResID, bigBoldFont);
  104. }
  105. //+----------------------------------------------------------------------------
  106. //
  107. // Function: GetNodeText
  108. //
  109. // Returns the text value for the named node that is a child of the passed in
  110. // Node. Returns S_FALSE if the named node cannot be found or contains no text.
  111. // Will only return the first instance of a child node with the given name.
  112. //
  113. //-----------------------------------------------------------------------------
  114. HRESULT
  115. GetNodeText(IXMLDOMNode * pNode, PCWSTR pwzNodeName, String & strText)
  116. {
  117. HRESULT hr = S_OK;
  118. IXMLDOMNode * pNameNode = NULL;
  119. hr = pNode->selectSingleNode(CComBSTR(pwzNodeName), &pNameNode);
  120. if (FAILED(hr))
  121. {
  122. LOG(String::format(L"Getting named node %1 failed with error %2!x!",
  123. pwzNodeName, hr));
  124. return hr;
  125. }
  126. DOMNodeType NodeType;
  127. hr = pNameNode->get_nodeType(&NodeType);
  128. if (NODE_ELEMENT != NodeType)
  129. {
  130. ASSERT(false);
  131. return S_FALSE;
  132. }
  133. IXMLDOMNode * pNameText = NULL;
  134. hr = pNameNode->get_firstChild(&pNameText);
  135. pNameNode->Release();
  136. if (S_FALSE == hr || !pNameText)
  137. {
  138. LOG(L"No name node value!");
  139. return S_FALSE;
  140. }
  141. if (FAILED(hr))
  142. {
  143. LOG(String::format(L"Getting node child failed with error %1!x!", hr));
  144. return hr;
  145. }
  146. CComVariant var;
  147. hr = pNameText->get_nodeValue(&var);
  148. pNameText->Release();
  149. if (S_FALSE == hr)
  150. {
  151. LOG(L"No name node value!");
  152. return hr;
  153. }
  154. if (FAILED(hr))
  155. {
  156. LOG(String::format(L"Getting node value failed with error %1!x!", hr));
  157. return hr;
  158. }
  159. ASSERT(var.vt == VT_BSTR);
  160. strText = var.bstrVal;
  161. strText.strip(String::BOTH, L' ');
  162. return S_OK;
  163. }