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.

212 lines
5.2 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: font.cpp
  4. //
  5. // Module: CMUTIL.DLL
  6. //
  7. // Synopsis: Font handling utility routines provided by CMUTIL
  8. //
  9. // Copyright (c) 1997-1999 Microsoft Corporation
  10. //
  11. // Author: quintinb Created 04/11/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. //
  15. // Moved these routines from cmutil\misc.cpp
  16. //
  17. #include "cmmaster.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Function: EnumChildProc
  21. //
  22. // Synopsis: Callback function to manipulate enumerated child windows.
  23. // Interprets lParam as a font and applies it to each child.
  24. //
  25. // Arguments: hwndChild - Handle of child control
  26. // lParam - App defined data (font)
  27. //
  28. // Returns: TRUE
  29. //
  30. // Note: This function is never exposed to clients of CMUTIL
  31. //
  32. // History: 5/13/97 - a-nichb - Created
  33. //
  34. //----------------------------------------------------------------------------
  35. BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
  36. {
  37. HFONT hFont = (HFONT) lParam;
  38. if (hFont)
  39. {
  40. SendMessageU(hwndChild, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
  41. }
  42. MYDBGTST(!hFont, (TEXT("EnumChildProc() - Invalid hFont - NULL lParam.")));
  43. return TRUE;
  44. }
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Function: MakeBold
  48. //
  49. // Synopsis: Bold the text in the given window (usually a control). The
  50. // caller is responsbile for calling ReleaseBold to free the
  51. // allocated font resources.
  52. //
  53. // Arguments: hwnd - Window handle of the page
  54. // fSize - If height should be changed proportionately
  55. //
  56. // Returns: ERROR_SUCCESS if successful
  57. // Otherwise error code
  58. //
  59. // History: 10/16/1996 VetriV Created
  60. // 01/12/2000 Quintinb Commonized for Cmmon and Profwiz
  61. //----------------------------------------------------------------------------
  62. CMUTILAPI HRESULT MakeBold (HWND hwnd, BOOL fSize)
  63. {
  64. HRESULT hr = ERROR_SUCCESS;
  65. HFONT hfont = NULL;
  66. HFONT hnewfont = NULL;
  67. LOGFONTA* plogfont = NULL;
  68. //
  69. // No window, no-op
  70. //
  71. if (!hwnd)
  72. {
  73. goto MakeBoldExit;
  74. }
  75. //
  76. // Get the current Font
  77. //
  78. hfont = (HFONT)SendMessageU(hwnd, WM_GETFONT, 0, 0);
  79. if (!hfont)
  80. {
  81. hr = GetLastError();
  82. goto MakeBoldExit;
  83. }
  84. //
  85. // Allocate a logical font struct to work with
  86. //
  87. plogfont = (LOGFONTA*) CmMalloc(sizeof(LOGFONTA));
  88. if (!plogfont)
  89. {
  90. hr = GetLastError();
  91. goto MakeBoldExit;
  92. }
  93. //
  94. // Get the logical font and make it bold and a larger size
  95. // if the caller specified the fSize flag as TRUE.
  96. //
  97. if (!GetObjectA(hfont, sizeof(LOGFONTA), (LPVOID)plogfont))
  98. {
  99. hr = GetLastError();
  100. goto MakeBoldExit;
  101. }
  102. if (abs(plogfont->lfHeight) < 24 && fSize)
  103. {
  104. plogfont->lfHeight = plogfont->lfHeight + (plogfont->lfHeight / 4);
  105. }
  106. plogfont->lfWeight = FW_BOLD;
  107. //
  108. // Create the new font
  109. //
  110. if (!(hnewfont = CreateFontIndirectA(plogfont)))
  111. {
  112. hr = GetLastError();
  113. goto MakeBoldExit;
  114. }
  115. //
  116. // Tell the window to use the new font
  117. //
  118. SendMessageU(hwnd, WM_SETFONT, (WPARAM)hnewfont, MAKELPARAM(TRUE,0)); //lint !e534 WM_SETFONT doesn't return anything
  119. MakeBoldExit:
  120. CmFree(plogfont);
  121. return hr;
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Function: ReleaseBold
  126. //
  127. // Synopsis: Release the bold font use for title of the page
  128. //
  129. // Arguments: hwnd - Window handle of the page
  130. //
  131. // Returns: ERROR_SUCCESS
  132. //
  133. // History: 10/16/96 VetriV Created
  134. //----------------------------------------------------------------------------
  135. CMUTILAPI HRESULT ReleaseBold(HWND hwnd)
  136. {
  137. HFONT hfont = NULL;
  138. hfont = (HFONT)SendMessageU(hwnd, WM_GETFONT, 0, 0);
  139. if (hfont)
  140. {
  141. DeleteObject(hfont);
  142. }
  143. return ERROR_SUCCESS;
  144. }
  145. //+---------------------------------------------------------------------------
  146. //
  147. // Function: UpdateFont
  148. //
  149. // Synopsis: Converts all child controls of the specified dialog to use
  150. // DBCS compatible font. Use this in WM_INITDIALOG.
  151. //
  152. // Arguments: hwnd - Window handle of the dialog
  153. //
  154. // Returns: Nothing
  155. //
  156. // History: 4/31/97 - a-frankh - Created
  157. // 5/13/97 - a-nichb - Revised to enum child windows
  158. //
  159. //----------------------------------------------------------------------------
  160. CMUTILAPI void UpdateFont(HWND hDlg)
  161. {
  162. BOOL bEnum = FALSE;
  163. HFONT hFont = NULL;
  164. //
  165. // Get the default UI font, or system font if that fails
  166. //
  167. hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
  168. if (hFont == NULL)
  169. {
  170. hFont = (HFONT) GetStockObject(SYSTEM_FONT);
  171. }
  172. //
  173. // Enum child windows and set new font
  174. //
  175. if (hFont)
  176. {
  177. bEnum = EnumChildWindows(hDlg, EnumChildProc, (LPARAM) hFont);
  178. MYDBGTST(!bEnum, (TEXT("UpdateFont() - EnumChildWindows() failed.")));
  179. }
  180. }