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.

202 lines
5.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AtlBaseSheet.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CBaseSheetWindow class.
  10. //
  11. // Author:
  12. // David Potter (davidp) December 4, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "AtlBaseSheet.h"
  20. #include "AtlExtDll.h"
  21. /////////////////////////////////////////////////////////////////////////////
  22. // Global Variables
  23. /////////////////////////////////////////////////////////////////////////////
  24. static LPCTSTR g_pszDefaultFontFaceName = _T("MS Shell Dlg");
  25. /////////////////////////////////////////////////////////////////////////////
  26. // class CBaseSheetWindow
  27. /////////////////////////////////////////////////////////////////////////////
  28. /////////////////////////////////////////////////////////////////////////////
  29. //++
  30. //
  31. // CBaseSheetWindow::~CBaseSheetWindow
  32. //
  33. // Routine Description:
  34. // Destructor.
  35. //
  36. // Arguments:
  37. // None.
  38. //
  39. // Return Value:
  40. // None.
  41. //
  42. //--
  43. /////////////////////////////////////////////////////////////////////////////
  44. CBaseSheetWindow::~CBaseSheetWindow( void )
  45. {
  46. //
  47. // Delete the extension information.
  48. //
  49. delete m_pext;
  50. } //*** CBaseSheetWindow::~CBaseSheetWindow()
  51. /////////////////////////////////////////////////////////////////////////////
  52. //++
  53. //
  54. // static
  55. // CBaseSheetWindow::BCreateFont
  56. //
  57. // Routine Description:
  58. // Create a font with only point size and type face name.
  59. //
  60. // Arguments:
  61. // rfont [OUT] Font to create.
  62. // nPoints [IN] Point size.
  63. // pszFaceName [IN] Font face name. Defaults to "MS Shell Dlg".
  64. // bBold [IN] Font should be bold.
  65. // bItalic [IN] Font should be italic.
  66. // bUnderline [IN] Font should be underline.
  67. //
  68. // Return Value:
  69. // TRUE Font created successfully.
  70. // FALSE Error creating font. Call GetLastError() for more details.
  71. //
  72. //--
  73. /////////////////////////////////////////////////////////////////////////////
  74. BOOL CBaseSheetWindow::BCreateFont(
  75. OUT CFont & rfont,
  76. IN LONG nPoints,
  77. IN LPCTSTR pszFaceName, // = _T("MS Shell Dlg")
  78. IN BOOL bBold, // = FALSE
  79. IN BOOL bItalic, // = FALSE
  80. IN BOOL bUnderline // = FALSE
  81. )
  82. {
  83. //
  84. // Get non-client metrics for basing the new font off of.
  85. //
  86. NONCLIENTMETRICS ncm = { 0 };
  87. ncm.cbSize = sizeof( ncm );
  88. SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
  89. //
  90. // Copy the message font and set the face name and point size to what
  91. // was passed in. The point size needs to be multiplied by 10 due to how
  92. // the CFont::CreatePointFontIndirect calculates the actual font height.
  93. //
  94. LOGFONT lfNewFont = ncm.lfMessageFont;
  95. if ( pszFaceName == NULL )
  96. {
  97. pszFaceName = g_pszDefaultFontFaceName;
  98. } // if: no type face name specified
  99. ATLASSERT( lstrlen( pszFaceName ) + 1 < sizeof( lfNewFont.lfFaceName ) );
  100. lstrcpy( lfNewFont.lfFaceName, pszFaceName );
  101. lfNewFont.lfHeight = nPoints * 10;
  102. //
  103. // Set bold, italic, and underline values.
  104. //
  105. if ( bBold )
  106. {
  107. lfNewFont.lfWeight = FW_BOLD;
  108. } // if: bold font requested
  109. if ( bItalic )
  110. {
  111. lfNewFont.lfItalic = TRUE;
  112. } // if: italic font requested
  113. if ( bUnderline )
  114. {
  115. lfNewFont.lfUnderline = TRUE;
  116. } // if: underlined font requested
  117. //
  118. // Create the font.
  119. //
  120. HFONT hfont = rfont.CreatePointFontIndirect( &lfNewFont );
  121. return ( hfont != NULL );
  122. } //*** BCreateFont()
  123. /////////////////////////////////////////////////////////////////////////////
  124. //++
  125. //
  126. // static
  127. // CBaseSheetWindow::BCreateFont
  128. //
  129. // Routine Description:
  130. // Create a font with only point size and type face name.
  131. //
  132. // Arguments:
  133. // rfont [OUT] Font to create.
  134. // idsPoints [IN] Resource ID for the font point size.
  135. // idsFaceName [IN] Resource ID for the font face name. Defaults to "MS Shell Dlg".
  136. // bBold [IN] Font should be bold.
  137. // bItalic [IN] Font should be italic.
  138. // bUnderline [IN] Font should be underline.
  139. //
  140. // Return Value:
  141. // TRUE Font created successfully.
  142. // FALSE Error creating font. Call GetLastError() for more details.
  143. //
  144. //--
  145. /////////////////////////////////////////////////////////////////////////////
  146. BOOL CBaseSheetWindow::BCreateFont(
  147. OUT CFont & rfont,
  148. IN UINT idsPoints,
  149. IN UINT idsFaceName,
  150. IN BOOL bBold, // = FALSE
  151. IN BOOL bItalic, // = FALSE
  152. IN BOOL bUnderline // = FALSE
  153. )
  154. {
  155. BOOL bSuccess;
  156. CString strFaceName;
  157. CString strPoints;
  158. LONG nPoints;
  159. //
  160. // Load the face name.
  161. //
  162. bSuccess = strFaceName.LoadString( idsFaceName );
  163. ATLASSERT( bSuccess );
  164. if ( ! bSuccess )
  165. {
  166. strFaceName = g_pszDefaultFontFaceName;
  167. } // if: no errors loading the string
  168. //
  169. // Load the point size.
  170. //
  171. bSuccess = strPoints.LoadString( idsPoints );
  172. ATLASSERT( bSuccess );
  173. if ( ! bSuccess)
  174. {
  175. nPoints = 12;
  176. } // if: no errors loading the string
  177. else
  178. {
  179. nPoints = _tcstoul( strPoints, NULL, 10 );
  180. } // else: error loading the string
  181. //
  182. // Create the font.
  183. //
  184. return BCreateFont( rfont, nPoints, strFaceName, bBold, bItalic, bUnderline );
  185. } //*** CBaseSheetWindow::BCreateFont()