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.

304 lines
8.5 KiB

  1. #include <shlobj.h>
  2. #include <windowsx.h>
  3. #include <shellapi.h>
  4. #include <shlwapi.h>
  5. #include <resource.h>
  6. #include <regstr.h>
  7. #include <shpriv.h>
  8. #include <ccstock.h>
  9. #include <strsafe.h>
  10. // device bit entries
  11. #ifndef ARRAYSIZE
  12. #define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
  13. #endif
  14. #define NUMPAGES 1
  15. HFONT g_hTitleFont = NULL;
  16. HINSTANCE g_hInstance = NULL;
  17. ////////////////////////////////////////////////////////
  18. HRESULT _LoadPath(BOOL fFlash, LPTSTR pszBuffer, UINT cchBuffer)
  19. {
  20. HRESULT hr;
  21. if (!GetWindowsDirectory(pszBuffer, cchBuffer))
  22. {
  23. hr = E_FAIL;
  24. }
  25. else
  26. {
  27. TCHAR szTemp[MAX_PATH];
  28. if (!LoadString(g_hInstance, fFlash ? IDS_DIR_FLASH : IDS_DIR_HTML, szTemp, ARRAYSIZE(szTemp)))
  29. {
  30. hr = E_FAIL;
  31. }
  32. else
  33. {
  34. if (!PathAppend(pszBuffer, szTemp))
  35. {
  36. hr = E_FAIL;
  37. }
  38. else
  39. {
  40. if (GetSystemDefaultUILanguage() == GetUserDefaultUILanguage()) // not on MUI
  41. {
  42. hr = S_OK;
  43. }
  44. else
  45. {
  46. TCHAR szMUITemplate[16];
  47. LANGID langid = GetUserDefaultUILanguage();
  48. hr = StringCchPrintf(szMUITemplate, ARRAYSIZE(szMUITemplate), TEXT("mui\\%04lx"), langid);
  49. if (SUCCEEDED(hr))
  50. {
  51. if (!PathAppend(pszBuffer, szMUITemplate))
  52. {
  53. hr = E_FAIL;
  54. }
  55. else
  56. {
  57. hr = S_OK;
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. return hr;
  65. }
  66. HRESULT _DeleteTourBalloon()
  67. {
  68. IShellReminderManager* psrm;
  69. HRESULT hr = CoCreateInstance(CLSID_PostBootReminder, NULL, CLSCTX_INPROC_SERVER,
  70. IID_PPV_ARG(IShellReminderManager, &psrm));
  71. if (SUCCEEDED(hr))
  72. {
  73. hr = psrm->Delete(L"Microsoft.OfferTour");
  74. psrm->Release();
  75. }
  76. return hr;
  77. }
  78. HRESULT _ExecuteTour(BOOL fFlash)
  79. {
  80. TCHAR szDir[MAX_PATH];
  81. HRESULT hr = _LoadPath(fFlash, szDir, ARRAYSIZE(szDir));
  82. if (SUCCEEDED(hr))
  83. {
  84. TCHAR szTarget[MAX_PATH];
  85. if (!LoadString(g_hInstance, fFlash ? IDS_EXE_FLASH : IDS_EXE_HTML, szTarget, ARRAYSIZE(szTarget)))
  86. {
  87. hr = E_FAIL;
  88. }
  89. else
  90. {
  91. if (32 < (INT_PTR)ShellExecute(NULL, NULL, szTarget, NULL, szDir, SW_SHOWNORMAL))
  92. {
  93. hr = S_OK;
  94. }
  95. else
  96. {
  97. hr = E_FAIL;
  98. }
  99. }
  100. }
  101. return hr;
  102. }
  103. HRESULT _HaveFlashTour()
  104. {
  105. HRESULT hr;
  106. TCHAR szHaveLocalizedTour[6];
  107. if (!LoadString(g_hInstance, IDS_FLASH_LOCALIZED, szHaveLocalizedTour, ARRAYSIZE(szHaveLocalizedTour)))
  108. {
  109. hr = E_FAIL;
  110. }
  111. else
  112. {
  113. // if the string in the .rc is not "TRUE", then we know we don't have a flash tour
  114. if (0 != StrCmp(szHaveLocalizedTour, TEXT("TRUE")))
  115. {
  116. hr = S_FALSE;
  117. }
  118. else
  119. {
  120. // if the string in the .rc is "TRUE", then we still check if the tour.exe is there
  121. TCHAR szPath[MAX_PATH];
  122. hr = _LoadPath(TRUE, szPath, ARRAYSIZE(szPath));
  123. if (SUCCEEDED(hr))
  124. {
  125. TCHAR szTarget[MAX_PATH];
  126. if (!LoadString(g_hInstance, IDS_EXE_FLASH, szTarget, ARRAYSIZE(szTarget)))
  127. {
  128. hr = E_FAIL;
  129. }
  130. else
  131. {
  132. if (!PathAppend(szPath, szTarget))
  133. {
  134. hr = E_FAIL;
  135. }
  136. else
  137. {
  138. if (PathFileExists(szPath))
  139. {
  140. hr = S_OK;
  141. }
  142. else
  143. {
  144. hr = S_FALSE;
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. return hr;
  152. }
  153. ///////////////////////////////////////////////////////////
  154. INT_PTR _IntroDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  155. {
  156. INT_PTR ipRet = FALSE;
  157. switch (wMsg)
  158. {
  159. case WM_INITDIALOG:
  160. {
  161. SetWindowFont(GetDlgItem(hDlg, IDC_TEXT_WELCOME), g_hTitleFont, TRUE);
  162. }
  163. break;
  164. case WM_NOTIFY :
  165. {
  166. LPNMHDR lpnm = (LPNMHDR) lParam;
  167. switch (lpnm->code)
  168. {
  169. case PSN_SETACTIVE:
  170. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
  171. SendMessage(GetDlgItem(hDlg, IDC_RADIO_FLASH), BM_CLICK, 0, 0);
  172. break;
  173. case PSN_WIZNEXT:
  174. if (BST_CHECKED == SendMessage(GetDlgItem(hDlg, IDC_RADIO_FLASH), BM_GETCHECK, 0, 0))
  175. {
  176. _ExecuteTour(TRUE);
  177. }
  178. else
  179. {
  180. _ExecuteTour(FALSE);
  181. }
  182. PropSheet_PressButton(GetParent(hDlg), PSBTN_CANCEL);
  183. break;
  184. }
  185. break;
  186. }
  187. }
  188. return ipRet;
  189. }
  190. ///////////////////////////////////////////////////////////
  191. HRESULT Run()
  192. {
  193. // Disable the balloon tip
  194. DWORD dwCount = 0;
  195. SHRegSetUSValue(REGSTR_PATH_SETUP TEXT("\\Applets\\Tour"), TEXT("RunCount"), REG_DWORD, &dwCount, sizeof(DWORD), SHREGSET_FORCE_HKCU);
  196. _DeleteTourBalloon();
  197. // Before we do anything, check to see if we have the choice of a FLASH tour. If we don't,
  198. // then we don't need to launch any wizard.
  199. if (S_OK == _HaveFlashTour())
  200. {
  201. // Init common controls
  202. INITCOMMONCONTROLSEX icex;
  203. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  204. icex.dwICC = ICC_USEREX_CLASSES;
  205. InitCommonControlsEx(&icex);
  206. //
  207. //Create the Wizard page
  208. //
  209. PROPSHEETPAGE psp = {0}; //defines the property sheet page
  210. HPROPSHEETPAGE rghpsp[NUMPAGES]; // an array to hold the page's HPROPSHEETPAGE handles
  211. psp.dwSize = sizeof(psp);
  212. psp.hInstance = g_hInstance;
  213. psp.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
  214. psp.pszHeaderTitle = NULL;
  215. psp.pszHeaderSubTitle = NULL;
  216. psp.pszTemplate = MAKEINTRESOURCE(IDD_INTRO);
  217. psp.pfnDlgProc = _IntroDlgProc;
  218. rghpsp[0] = CreatePropertySheetPage(&psp);
  219. // create the font
  220. NONCLIENTMETRICS ncm = {0};
  221. ncm.cbSize = sizeof(ncm);
  222. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  223. LOGFONT TitleLogFont = ncm.lfMessageFont;
  224. TitleLogFont.lfWeight = FW_BOLD;
  225. LoadString(g_hInstance, IDS_TITLELOGFONT, TitleLogFont.lfFaceName, LF_FACESIZE);
  226. HDC hdc = GetDC(NULL); //gets the screen DC
  227. if (hdc)
  228. {
  229. TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * 12 / 72;
  230. g_hTitleFont = CreateFontIndirect(&TitleLogFont);
  231. ReleaseDC(NULL, hdc);
  232. }
  233. //Create the property sheet
  234. PROPSHEETHEADER _psh;
  235. _psh.hInstance = g_hInstance;
  236. _psh.hwndParent = NULL;
  237. _psh.phpage = rghpsp;
  238. _psh.dwSize = sizeof(_psh);
  239. _psh.dwFlags = PSH_WIZARD97|PSH_WATERMARK|PSH_USEICONID;
  240. _psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
  241. _psh.pszIcon = MAKEINTRESOURCE(IDI_WIZ_ICON);
  242. _psh.nStartPage = 0;
  243. _psh.nPages = NUMPAGES;
  244. // run property sheet
  245. PropertySheet(&_psh);
  246. // clean up font
  247. if (g_hTitleFont)
  248. {
  249. DeleteObject(g_hTitleFont);
  250. }
  251. }
  252. else
  253. {
  254. _ExecuteTour(FALSE);
  255. }
  256. return S_OK;
  257. }
  258. ///////////////////////////////////////////////////////////
  259. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT nCmdShow)
  260. {
  261. OleInitialize(NULL);
  262. g_hInstance = hInstance;
  263. Run();
  264. OleUninitialize();
  265. return 0;
  266. }