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.

399 lines
11 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // oemads.c
  8. //
  9. // Description:
  10. // This is the dialog proc for the OEM Ads page.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "pch.h"
  14. #include "resource.h"
  15. const TCHAR TEXT_EXTENSION[] = _T("bmp");
  16. static TCHAR *StrBitmapFiles;
  17. static TCHAR *StrAllFiles;
  18. static TCHAR g_szTextFileFilter[MAX_PATH + 1];
  19. //---------------------------------------------------------------------------
  20. //
  21. // Function: OnOemAdsInitDialog
  22. //
  23. // Purpose:
  24. //
  25. // Arguments: IN HWND hwnd - handle to the dialog
  26. //
  27. // Returns: VOID
  28. //
  29. //---------------------------------------------------------------------------
  30. static VOID
  31. OnOemAdsInitDialog( IN HWND hwnd )
  32. {
  33. HRESULT hrPrintf;
  34. //
  35. // Load the resource strings
  36. //
  37. StrBitmapFiles = MyLoadString( IDS_BITMAP_FILES );
  38. StrAllFiles = MyLoadString( IDS_ALL_FILES );
  39. //
  40. // Build the text file filter string
  41. //
  42. //
  43. // The question marks (?) are just placehoders for where the NULL char
  44. // will be inserted.
  45. //
  46. hrPrintf=StringCchPrintf( g_szTextFileFilter, AS(g_szTextFileFilter),
  47. _T("%s(*.bmp)?*.bmp?%s(*.*)?*.*?"),
  48. StrBitmapFiles,
  49. StrAllFiles );
  50. ConvertQuestionsToNull( g_szTextFileFilter );
  51. }
  52. //---------------------------------------------------------------------------
  53. //
  54. // Function: OnSetActiveOemAds
  55. //
  56. // Purpose:
  57. //
  58. // Arguments: IN HWND hwnd - handle to the dialog
  59. //
  60. // Returns: VOID
  61. //
  62. //---------------------------------------------------------------------------
  63. static VOID
  64. OnSetActiveOemAds( IN HWND hwnd)
  65. {
  66. //
  67. // Set the window text for Logo Bitmap and Background Bitmap
  68. //
  69. SendDlgItemMessage(hwnd,
  70. IDC_LOGOBITMAP,
  71. WM_SETTEXT,
  72. (WPARAM) MAX_PATH,
  73. (LPARAM) GenSettings.lpszLogoBitmap);
  74. SendDlgItemMessage(hwnd,
  75. IDC_BACKGROUNDBITMAP,
  76. WM_SETTEXT,
  77. (WPARAM) MAX_PATH,
  78. (LPARAM) GenSettings.lpszBackgroundBitmap);
  79. PropSheet_SetWizButtons(GetParent(hwnd), PSWIZB_BACK | PSWIZB_NEXT);
  80. }
  81. //----------------------------------------------------------------------------
  82. //
  83. // Function: OnBrowseLoadBitmap
  84. //
  85. // Purpose: Creates a browse window for the user to select a bitmap and
  86. // stores the path in the appropriate string (logo or background)
  87. //
  88. //----------------------------------------------------------------------------
  89. VOID
  90. OnBrowseLoadBitmap( IN HWND hwnd, IN WORD wControlID ) {
  91. TCHAR szBitmapString[MAX_PATH] = _T("");
  92. OPENFILENAME ofn;
  93. DWORD dwFlags;
  94. TCHAR PathBuffer[MAX_PATH];
  95. INT iRet;
  96. dwFlags = OFN_HIDEREADONLY |
  97. OFN_PATHMUSTEXIST;
  98. GetCurrentDirectory(MAX_PATH, PathBuffer);
  99. ofn.lStructSize = sizeof(OPENFILENAME);
  100. ofn.hwndOwner = hwnd;
  101. ofn.hInstance = NULL;
  102. ofn.lpstrFilter = g_szTextFileFilter;
  103. ofn.lpstrCustomFilter = NULL;
  104. ofn.nMaxCustFilter = 0L;
  105. ofn.nFilterIndex = 1;
  106. ofn.lpstrFile = szBitmapString;
  107. ofn.nMaxFile = MAX_PATH;
  108. ofn.lpstrFileTitle = NULL;
  109. ofn.nMaxFileTitle = 0;
  110. ofn.lpstrInitialDir = PathBuffer;
  111. ofn.lpstrTitle = NULL;
  112. ofn.Flags = dwFlags;
  113. ofn.nFileOffset = 0;
  114. ofn.nFileExtension = 0;
  115. ofn.lpstrDefExt = TEXT_EXTENSION;
  116. iRet = GetOpenFileName(&ofn);
  117. if ( ! iRet )
  118. return; // user pressed cancel on the dialog
  119. //
  120. // Now that we have the bitmap, store it in the proper string and fill
  121. // the appropriate edit field
  122. //
  123. if( wControlID == IDC_LOGOBITMAP ) {
  124. SendDlgItemMessage(hwnd,
  125. IDC_LOGOBITMAP,
  126. WM_SETTEXT,
  127. (WPARAM) MAX_PATH,
  128. (LPARAM) szBitmapString);
  129. }
  130. else {
  131. SendDlgItemMessage(hwnd,
  132. IDC_BACKGROUNDBITMAP,
  133. WM_SETTEXT,
  134. (WPARAM) MAX_PATH,
  135. (LPARAM) szBitmapString);
  136. }
  137. }
  138. //----------------------------------------------------------------------------
  139. //
  140. // Function: OnWizNextOemAds
  141. //
  142. // Purpose: Called when the Next button is pushed. Copies the bitmaps, if
  143. // any chosen to the distribution share
  144. //
  145. //----------------------------------------------------------------------------
  146. BOOL OnWizNextOemAds( IN HWND hwnd ) {
  147. TCHAR szLogoDestination[MAX_PATH + 1] = _T("");
  148. TCHAR szBackgroundDestination[MAX_PATH + 1] = _T("");
  149. TCHAR szBitmapDestPath[MAX_PATH + 1] = _T("");
  150. TCHAR szBackSlash[] = _T("\\");
  151. BOOL bStayHere = FALSE;
  152. DWORD dwReturnValue;
  153. //
  154. // If OemFilesPath doesn't have a value, give it one.
  155. //
  156. if ( WizGlobals.OemFilesPath[0] == _T('\0') ) {
  157. ConcatenatePaths( WizGlobals.OemFilesPath,
  158. WizGlobals.DistFolder,
  159. _T("$oem$"),
  160. NULL );
  161. }
  162. //
  163. // Force creation of the $oem$ dir (if it doesn't exist already)
  164. //
  165. if ( ! EnsureDirExists(WizGlobals.OemFilesPath) ) {
  166. ReportErrorId(hwnd,
  167. MSGTYPE_ERR | MSGTYPE_WIN32,
  168. IDS_ERR_CREATE_FOLDER,
  169. WizGlobals.OemFilesPath);
  170. }
  171. //
  172. // Fill the global structs with the edit box data
  173. //
  174. SendDlgItemMessage(hwnd,
  175. IDC_LOGOBITMAP,
  176. WM_GETTEXT,
  177. (WPARAM) MAX_PATH,
  178. (LPARAM) GenSettings.lpszLogoBitmap);
  179. SendDlgItemMessage(hwnd,
  180. IDC_BACKGROUNDBITMAP,
  181. WM_GETTEXT,
  182. (WPARAM) MAX_PATH,
  183. (LPARAM) GenSettings.lpszBackgroundBitmap);
  184. //
  185. // Set the path where the bitmaps are to be copied to
  186. // On a sysprep they go into the sysprep dir
  187. // On a regular install they go to the $OEM$ dir
  188. //
  189. if( WizGlobals.iProductInstall == PRODUCT_SYSPREP )
  190. {
  191. ExpandEnvironmentStrings( _T("%SystemDrive%"),
  192. szBitmapDestPath,
  193. MAX_PATH );
  194. lstrcatn( szBitmapDestPath, _T("\\sysprep"), MAX_PATH );
  195. }
  196. else
  197. {
  198. lstrcpyn( szBitmapDestPath, WizGlobals.OemFilesPath, MAX_PATH + 1 );
  199. }
  200. if( GenSettings.lpszLogoBitmap[0] != _T('\0') ) {
  201. //
  202. // Build up the destination path
  203. //
  204. ConcatenatePaths( szLogoDestination,
  205. szBitmapDestPath,
  206. MyGetFullPath( GenSettings.lpszLogoBitmap ),
  207. NULL );
  208. if( ! DoesFileExist( szLogoDestination ) ) {
  209. if ( ! CopyFile(GenSettings.lpszLogoBitmap, szLogoDestination, TRUE) ) {
  210. ReportErrorId(hwnd,
  211. MSGTYPE_ERR | MSGTYPE_WIN32,
  212. IDS_ERR_COPY_FILE,
  213. GenSettings.lpszLogoBitmap, szLogoDestination);
  214. bStayHere = TRUE;
  215. }
  216. }
  217. }
  218. if( GenSettings.lpszBackgroundBitmap[0] != _T('\0') ) {
  219. //
  220. // Build up the destination path
  221. //
  222. ConcatenatePaths( szBackgroundDestination,
  223. szBitmapDestPath,
  224. MyGetFullPath( GenSettings.lpszBackgroundBitmap ),
  225. NULL);
  226. if( ! DoesFileExist( szBackgroundDestination ) ) {
  227. if ( ! CopyFile( GenSettings.lpszBackgroundBitmap,
  228. szBackgroundDestination,
  229. TRUE ) ) {
  230. ReportErrorId(hwnd,
  231. MSGTYPE_ERR | MSGTYPE_WIN32,
  232. IDS_ERR_COPY_FILE,
  233. GenSettings.lpszBackgroundBitmap,
  234. szBackgroundDestination);
  235. bStayHere = TRUE;
  236. }
  237. }
  238. }
  239. //
  240. // Route the wizard
  241. //
  242. return (!bStayHere );
  243. }
  244. //----------------------------------------------------------------------------
  245. //
  246. // Function: DlgOemAdsPage
  247. //
  248. // Purpose: This is the dialog procedure for the OEM Ads page.
  249. //
  250. //----------------------------------------------------------------------------
  251. INT_PTR CALLBACK DlgOemAdsPage(
  252. IN HWND hwnd,
  253. IN UINT uMsg,
  254. IN WPARAM wParam,
  255. IN LPARAM lParam)
  256. {
  257. BOOL bStatus = TRUE;
  258. switch (uMsg) {
  259. case WM_INITDIALOG:
  260. OnOemAdsInitDialog( hwnd );
  261. break;
  262. case WM_COMMAND:
  263. switch ( LOWORD(wParam) ) {
  264. case IDC_LOGOBITMAPBROWSE:
  265. if ( HIWORD(wParam) == BN_CLICKED )
  266. OnBrowseLoadBitmap( hwnd, IDC_LOGOBITMAP );
  267. break;
  268. case IDC_BACKGROUNDBITMAPBROWSE:
  269. if ( HIWORD(wParam) == BN_CLICKED )
  270. OnBrowseLoadBitmap( hwnd, IDC_BACKGROUNDBITMAP );
  271. break;
  272. default:
  273. bStatus = FALSE;
  274. break;
  275. }
  276. break;
  277. case WM_NOTIFY:
  278. {
  279. LPNMHDR pnmh = (LPNMHDR)lParam;
  280. switch( pnmh->code ) {
  281. case PSN_QUERYCANCEL:
  282. CancelTheWizard( hwnd );
  283. break;
  284. case PSN_SETACTIVE:
  285. OnSetActiveOemAds( hwnd );
  286. break;
  287. case PSN_WIZBACK:
  288. break;
  289. case PSN_WIZNEXT:
  290. if ( !OnWizNextOemAds( hwnd ))
  291. WIZ_FAIL(hwnd);
  292. break;
  293. default:
  294. bStatus = FALSE;
  295. break;
  296. }
  297. }
  298. break;
  299. default:
  300. bStatus = FALSE;
  301. break;
  302. }
  303. return bStatus;
  304. }