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.

221 lines
6.2 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. // device bit entries
  10. #ifndef ARRAYSIZE
  11. #define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
  12. #endif
  13. #define NUMPAGES 1
  14. HFONT g_hTitleFont = NULL;
  15. ////////////////////////////////////////////////////////
  16. void _LoadPath(UINT idTarget, LPTSTR pszBuffer, UINT cchBuffer)
  17. {
  18. TCHAR szTemp[MAX_PATH];
  19. LoadString(NULL, idTarget, szTemp, ARRAYSIZE(szTemp));
  20. ExpandEnvironmentStrings(szTemp, pszBuffer, cchBuffer);
  21. if (GetSystemDefaultUILanguage() != GetUserDefaultUILanguage()) // are we on MUI?
  22. {
  23. StrCpyN(szTemp, pszBuffer, ARRAYSIZE(szTemp));
  24. PathRemoveFileSpec(szTemp);
  25. TCHAR szMUITemplate[16];
  26. wsprintf(szMUITemplate, TEXT("mui\\%04lx"), GetUserDefaultUILanguage());
  27. PathAppend(szTemp, szMUITemplate);
  28. PathAppend(szTemp, PathFindFileName(pszBuffer));
  29. if (PathFileExists(szTemp))
  30. {
  31. StrCpyN(pszBuffer, szTemp, cchBuffer);
  32. }
  33. }
  34. }
  35. void _DeleteTourBalloon()
  36. {
  37. IShellReminderManager* psrm;
  38. HRESULT hr = CoCreateInstance(CLSID_PostBootReminder, NULL, CLSCTX_INPROC_SERVER,
  39. IID_PPV_ARG(IShellReminderManager, &psrm));
  40. if (SUCCEEDED(hr))
  41. {
  42. psrm->Delete(L"Microsoft.OfferTour");
  43. psrm->Release();
  44. }
  45. }
  46. void _ExecuteTour(UINT idTarget)
  47. {
  48. TCHAR szTarget[MAX_PATH];
  49. _LoadPath(idTarget, szTarget, ARRAYSIZE(szTarget));
  50. ShellExecute(NULL, NULL, szTarget, NULL, NULL, SW_SHOWNORMAL);
  51. }
  52. BOOL _HaveFlashTour(HINSTANCE hInstance)
  53. {
  54. BOOL fRet = FALSE;
  55. TCHAR szHaveLocalizedTour[6];
  56. if (LoadString(hInstance, IDS_FLASH_LOCALIZED, szHaveLocalizedTour, ARRAYSIZE(szHaveLocalizedTour)) &&
  57. !StrCmp(szHaveLocalizedTour, TEXT("TRUE")))
  58. {
  59. TCHAR szTarget[MAX_PATH];
  60. _LoadPath(IDS_TARGET_FLASH, szTarget, ARRAYSIZE(szTarget));
  61. if (PathFileExists(szTarget))
  62. {
  63. fRet = TRUE;
  64. }
  65. }
  66. return fRet;
  67. }
  68. ///////////////////////////////////////////////////////////
  69. INT_PTR _IntroDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  70. {
  71. INT_PTR ipRet = FALSE;
  72. switch (wMsg)
  73. {
  74. case WM_INITDIALOG:
  75. {
  76. SetWindowFont(GetDlgItem(hDlg, IDC_TEXT_WELCOME), g_hTitleFont, TRUE);
  77. }
  78. break;
  79. case WM_NOTIFY :
  80. {
  81. LPNMHDR lpnm = (LPNMHDR) lParam;
  82. switch (lpnm->code)
  83. {
  84. case PSN_SETACTIVE:
  85. PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
  86. SendMessage(GetDlgItem(hDlg, IDC_RADIO_FLASH), BM_CLICK, 0, 0);
  87. break;
  88. case PSN_WIZNEXT:
  89. if (BST_CHECKED == SendMessage(GetDlgItem(hDlg, IDC_RADIO_FLASH), BM_GETCHECK, 0, 0))
  90. {
  91. _ExecuteTour(IDS_TARGET_FLASH);
  92. }
  93. else
  94. {
  95. _ExecuteTour(IDS_TARGET_HTML);
  96. }
  97. PropSheet_PressButton(GetParent(hDlg), PSBTN_CANCEL);
  98. break;
  99. }
  100. break;
  101. }
  102. }
  103. return ipRet;
  104. }
  105. ///////////////////////////////////////////////////////////
  106. HRESULT Run(HINSTANCE hInstance)
  107. {
  108. // Disable the balloon tip
  109. DWORD dwCount = 0;
  110. SHRegSetUSValue(REGSTR_PATH_SETUP TEXT("\\Applets\\Tour"), TEXT("RunCount"), REG_DWORD, &dwCount, sizeof(DWORD), SHREGSET_FORCE_HKCU);
  111. _DeleteTourBalloon();
  112. // Before we do anything, check to see if we have the choice of a FLASH tour. If we don't,
  113. // then we don't need to launch any wizard.
  114. if (_HaveFlashTour(hInstance))
  115. {
  116. // Init common controls
  117. INITCOMMONCONTROLSEX icex;
  118. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  119. icex.dwICC = ICC_USEREX_CLASSES;
  120. InitCommonControlsEx(&icex);
  121. //
  122. //Create the Wizard page
  123. //
  124. PROPSHEETPAGE psp = {0}; //defines the property sheet page
  125. HPROPSHEETPAGE rghpsp[NUMPAGES]; // an array to hold the page's HPROPSHEETPAGE handles
  126. psp.dwSize = sizeof(psp);
  127. psp.hInstance = hInstance;
  128. psp.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
  129. psp.pszHeaderTitle = NULL;
  130. psp.pszHeaderSubTitle = NULL;
  131. psp.pszTemplate = MAKEINTRESOURCE(IDD_INTRO);
  132. psp.pfnDlgProc = _IntroDlgProc;
  133. rghpsp[0] = CreatePropertySheetPage(&psp);
  134. // create the font
  135. NONCLIENTMETRICS ncm = {0};
  136. ncm.cbSize = sizeof(ncm);
  137. SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
  138. LOGFONT TitleLogFont = ncm.lfMessageFont;
  139. TitleLogFont.lfWeight = FW_BOLD;
  140. LoadString(hInstance, IDS_TITLELOGFONT, TitleLogFont.lfFaceName, LF_FACESIZE);
  141. HDC hdc = GetDC(NULL); //gets the screen DC
  142. if (hdc)
  143. {
  144. TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * 12 / 72;
  145. g_hTitleFont = CreateFontIndirect(&TitleLogFont);
  146. ReleaseDC(NULL, hdc);
  147. }
  148. //Create the property sheet
  149. PROPSHEETHEADER _psh;
  150. _psh.hInstance = hInstance;
  151. _psh.hwndParent = NULL;
  152. _psh.phpage = rghpsp;
  153. _psh.dwSize = sizeof(_psh);
  154. _psh.dwFlags = PSH_WIZARD97|PSH_WATERMARK|PSH_USEICONID;
  155. _psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
  156. _psh.pszIcon = MAKEINTRESOURCE(IDI_WIZ_ICON);
  157. _psh.nStartPage = 0;
  158. _psh.nPages = NUMPAGES;
  159. // run property sheet
  160. PropertySheet(&_psh);
  161. // clean up font
  162. if (g_hTitleFont)
  163. {
  164. DeleteObject(g_hTitleFont);
  165. }
  166. }
  167. else
  168. {
  169. _ExecuteTour(IDS_TARGET_HTML);
  170. }
  171. return S_OK;
  172. }
  173. ///////////////////////////////////////////////////////////
  174. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, INT nCmdShow)
  175. {
  176. OleInitialize(NULL);
  177. Run(hInstance);
  178. OleUninitialize();
  179. return 0;
  180. }