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.

245 lines
7.2 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // setupmgr.c
  8. //
  9. // Description:
  10. // This file has the setupmgr manager function that gets the wizard going.
  11. //
  12. //----------------------------------------------------------------------------
  13. #define _SMGR_DECLARE_GLOBALS_
  14. #include <locale.h>
  15. #include "setupmgr.h"
  16. #include "allres.h"
  17. //
  18. // Local prototypes
  19. //
  20. static VOID SetupFonts(IN HINSTANCE hInstance,
  21. IN HWND hwnd,
  22. IN HFONT *pBigBoldFont,
  23. IN HFONT *pBoldFont);
  24. static VOID DestroyFonts(IN HFONT hBigBoldFont,
  25. IN HFONT hBoldFont);
  26. static BOOL VerifyVersion(VOID);
  27. //----------------------------------------------------------------------------
  28. //
  29. // Function: setupmgr
  30. //
  31. // Purpose: This is the only export from setupmgr.dll. The stub loader
  32. // calls this function iff we're running on Windows Whistler. Note
  33. // that DllMain() runs before this function is called.
  34. //
  35. //----------------------------------------------------------------------------
  36. int APIENTRY WinMain(
  37. HINSTANCE hInstance,
  38. HINSTANCE hPrevInstance,
  39. LPSTR lpCmdLine,
  40. int nCmdShow)
  41. {
  42. // Zero out the global data.
  43. //
  44. ZeroMemory(&g_App, sizeof(GAPP));
  45. // This function checks to make sure that we are running the correct OS/Version
  46. //
  47. if (!VerifyVersion())
  48. return 1;
  49. //
  50. // Sets the locale to the default, which is the system-default ANSI code
  51. // page obtained from the operating system
  52. //
  53. setlocale(LC_CTYPE, "");
  54. // Set up the hInstance for the application
  55. //
  56. FixedGlobals.hInstance = hInstance;
  57. SetupFonts(FixedGlobals.hInstance,
  58. NULL,
  59. &FixedGlobals.hBigBoldFont,
  60. &FixedGlobals.hBoldFont);
  61. InitTheWizard();
  62. StartWizard(hInstance, lpCmdLine);
  63. DestroyFonts(FixedGlobals.hBigBoldFont, FixedGlobals.hBoldFont);
  64. return 0;
  65. }
  66. //----------------------------------------------------------------------------
  67. //
  68. // Function: SetupFonts
  69. //
  70. // Purpose: This function creates a BoldFont and a BigBoldFont and saves
  71. // handles to these in global vars.
  72. //
  73. //----------------------------------------------------------------------------
  74. static VOID SetupFonts(IN HINSTANCE hInstance,
  75. IN HWND hwnd,
  76. IN HFONT *pBigBoldFont,
  77. IN HFONT *pBoldFont)
  78. {
  79. NONCLIENTMETRICS ncm = {0};
  80. LOGFONT BigBoldLogFont = ncm.lfMessageFont;
  81. LOGFONT BoldLogFont = ncm.lfMessageFont;
  82. TCHAR FontSizeString[MAX_PATH],
  83. FontSizeSmallString[MAX_PATH];
  84. INT FontSize,
  85. FontSizeSmall;
  86. HDC hdc = GetDC( hwnd );
  87. //
  88. // Create the fonts we need based on the dialog font
  89. //
  90. // ISSUE-2002/02/28-stelo- Variable ncm is not being used any where
  91. ncm.cbSize = sizeof(ncm);
  92. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  93. //
  94. // Create Big Bold Font and Bold Font
  95. //
  96. BigBoldLogFont.lfWeight = FW_BOLD;
  97. BoldLogFont.lfWeight = FW_BOLD;
  98. //
  99. // Load size and name from resources, since these may change
  100. // from locale to locale based on the size of the system font, etc.
  101. //
  102. if(!LoadString(hInstance,IDS_LARGEFONTNAME,BigBoldLogFont.lfFaceName,LF_FACESIZE))
  103. {
  104. lstrcpyn(BigBoldLogFont.lfFaceName,TEXT("MS Shell Dlg"),AS(BigBoldLogFont.lfFaceName));
  105. }
  106. if(LoadString(hInstance,IDS_LARGEFONTSIZE,FontSizeString,sizeof(FontSizeString)/sizeof(TCHAR)))
  107. {
  108. FontSize = _tcstoul( FontSizeString, NULL, 10 );
  109. }
  110. else
  111. {
  112. FontSize = 12;
  113. }
  114. // Load the smaller sized font settings
  115. //
  116. if(!LoadString(hInstance,IDS_SMALLFONTNAME,BoldLogFont.lfFaceName,LF_FACESIZE))
  117. {
  118. lstrcpyn(BoldLogFont.lfFaceName,TEXT("MS Shell Dlg"),AS(BoldLogFont.lfFaceName));
  119. }
  120. if(LoadString(hInstance,IDS_SMALLFONTSIZE,FontSizeSmallString,sizeof(FontSizeSmallString)/sizeof(TCHAR)))
  121. {
  122. FontSizeSmall = _tcstoul( FontSizeSmallString, NULL, 10 );
  123. }
  124. else
  125. {
  126. FontSizeSmall = 12;
  127. }
  128. if( hdc )
  129. {
  130. BigBoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72);
  131. BoldLogFont.lfHeight = 0 - (GetDeviceCaps(hdc,LOGPIXELSY) * FontSizeSmall / 72);
  132. *pBigBoldFont = CreateFontIndirect(&BigBoldLogFont);
  133. *pBoldFont = CreateFontIndirect(&BoldLogFont);
  134. ReleaseDC(hwnd,hdc);
  135. }
  136. }
  137. //----------------------------------------------------------------------------
  138. //
  139. // Function: DestroyFonts
  140. //
  141. // Purpose: Frees up the space used by loading the fonts
  142. //
  143. //----------------------------------------------------------------------------
  144. static VOID DestroyFonts(IN HFONT hBigBoldFont,
  145. IN HFONT hBoldFont)
  146. {
  147. if( hBigBoldFont ) {
  148. DeleteObject( hBigBoldFont );
  149. }
  150. if( hBoldFont ) {
  151. DeleteObject( hBoldFont );
  152. }
  153. }
  154. //----------------------------------------------------------------------------
  155. //
  156. // Function: VerifyVersion
  157. //
  158. // Purpose: Verifies that we are running on the correct Operating System
  159. // If we are not running on a supported OS, this function prompts
  160. // the user and returns FALSE
  161. //
  162. //----------------------------------------------------------------------------
  163. static BOOL VerifyVersion(VOID)
  164. {
  165. OSVERSIONINFOEXA osVersionInfo;
  166. BOOL bResult = FALSE;
  167. // Clean up the memory
  168. //
  169. ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));
  170. osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
  171. // This condition checks for the following:
  172. // Are we able to get system information
  173. // Are we running on NT
  174. // Is our version NT4 and Service Pack 5 or greater
  175. //
  176. if (GetVersionExA((LPOSVERSIONINFOA) &osVersionInfo))
  177. {
  178. if (osVersionInfo.dwPlatformId & VER_PLATFORM_WIN32_NT)
  179. {
  180. g_App.dwOsVer = MAKELONG(MAKEWORD(LOBYTE(osVersionInfo.wServicePackMajor), LOBYTE(LOWORD(osVersionInfo.dwMinorVersion))), LOWORD(osVersionInfo.dwMajorVersion));
  181. if ( g_App.dwOsVer > OS_NT4_SP5 )
  182. {
  183. bResult = TRUE;
  184. }
  185. else
  186. {
  187. // The OS is a non-supported NT platform, error out
  188. //
  189. MsgBox(NULL, IDS_ERROR_VERSION, IDS_APPNAME, MB_ERRORBOX);
  190. }
  191. }
  192. else
  193. {
  194. // The OS is a 9x platform, we must error out
  195. //
  196. CHAR szMessage[MAX_PATH],
  197. szTitle[MAX_PATH];
  198. LoadStringA(NULL, IDS_ERROR_VERSION, szMessage, STRSIZE(szMessage));
  199. LoadStringA(NULL, IDS_APPNAME, szTitle, STRSIZE(szTitle));
  200. MessageBoxA(NULL, szMessage, szTitle, MB_ERRORBOX);
  201. }
  202. }
  203. return bResult;
  204. }