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.

2597 lines
65 KiB

  1. /*---------------------------------------------------------------------------
  2. **
  3. **-------------------------------------------------------------------------*/
  4. #include <pch.h>
  5. #include <commctrl.h>
  6. #include "dibutil.h"
  7. #include "billbrd.h"
  8. #include "animate.h"
  9. #ifdef DBG
  10. void _BB_Assert(LPCTSTR strFile, unsigned uLine)
  11. {
  12. TCHAR buf[512];
  13. wsprintf(buf, TEXT("Assertion failed: %s, line %u\n"),
  14. strFile, uLine);
  15. OutputDebugString(buf);
  16. }
  17. #endif
  18. #define BILLBRD_TEXT_TIMERID 1
  19. #define WHISTLER_PROGRESS_TIMERID 2
  20. // For how long is the text for the Billboard displayed
  21. // before switching to the next text
  22. #define BB_TEXT_DISPLAY 36000
  23. // For how long is the whistler status move, in millis seconds
  24. #define BB_WHISTLER_MOVE 100
  25. // Name to the INI file which discribes the billboards
  26. TCHAR g_szFileName[MAX_PATH];
  27. // Path where to find the billboard bitmaps.
  28. TCHAR g_szPath[MAX_PATH];
  29. // this application instance
  30. HINSTANCE g_hInstance = NULL;
  31. // charset properties of font used by this application
  32. BYTE g_bCharSet = 0;
  33. BOOL g_bBiDi = FALSE;
  34. /**********************************************************************************
  35. -----------------------------------------------------------------------------------
  36. (LOGO) (banner)
  37. -----------------------------------------------------------------------------------
  38. STEP |BILLBRD (GetBBHwd)
  39. |
  40. |
  41. |
  42. -----------------------------|
  43. ESTIMATE (TimeEstimate) |
  44. -----------------------------|
  45. PROGRESSTEXT (ProgressText) |
  46. -----------------------------|
  47. GAUGE (ProgressGauge) |
  48. -----------------------------|
  49. INFOTEXT (InfoText) |
  50. |
  51. -----------------------------------------------------------------------------------
  52. (banner)
  53. -----------------------------------------------------------------------------------
  54. INFOBAR = STEP, ESTIMATE, GAUGE, PROGRESSTEXT and INFOTEXT
  55. NOTE:
  56. Position of setup wizard is dependent on the the size and position of
  57. BILLBRD.
  58. ***********************************************************************************/
  59. UINT g_cyBannerHeight = 0;
  60. UINT g_cxLogo = 0;
  61. UINT g_cyLogo = 0;
  62. UINT g_cxInfoBarWidth = 0;
  63. UINT g_cyInfoBarHeight = 0;
  64. UINT g_cxSteps = 0;
  65. UINT g_cySteps = 0;
  66. UINT g_cxStepsWidth = 0;
  67. UINT g_cyStepsHeight = 0;
  68. UINT g_cxProgressText = 0;
  69. UINT g_cyProgressText = 0;
  70. UINT g_cxProgressTextWidth = 0;
  71. UINT g_cyProgressTextHeight = 0;
  72. UINT g_cxGauge = 0;
  73. UINT g_cyGauge = 0;
  74. UINT g_cxGaugeWidth = 0;
  75. UINT g_cyGaugeHeight = 0;
  76. UINT g_cxEstimate = 0;
  77. UINT g_cyEstimate = 0;
  78. UINT g_cxEstimateWidth = 0;
  79. UINT g_cyEstimateHeight = 0;
  80. UINT g_cxInfoText = 0;
  81. UINT g_cyInfoText = 0;
  82. UINT g_cxInfoTextWidth = 0;
  83. UINT g_cyInfoTextHeight = 0;
  84. UINT g_cxBillBrd = 0;
  85. UINT g_cyBillBrd = 0;
  86. UINT g_cxBillBrdWidth = 0;
  87. UINT g_cyBillBrdHeight = 0;
  88. UINT g_cxBillBrdHMargin = 0;
  89. UINT g_cyBillBrdVMargin = 0;
  90. UINT g_cxBillBrdTitleWidth = 0;
  91. UINT g_cyBillBrdTitleTop = 0;
  92. UINT g_cxBillBrdBodyWidth = 0;
  93. HWND g_hwndParent = NULL; // Parent of g_hwnd
  94. HWND g_hwnd = NULL; // Parent of all the following windows
  95. HWND g_hwndTimeEstimate = NULL; // 'TIMEESTIMATE'
  96. HWND g_hwndProgressText = NULL; // 'PROGRESSTEXT'
  97. HWND g_hwndProgressGauge= NULL; // 'GAUGE'
  98. HWND g_hwndInfoText = NULL; // 'INFOTEXT'
  99. HWND g_hwndBB = NULL; // 'BILLBRD'
  100. HWND g_hwndSteps = NULL; // 'STEP'
  101. HWND g_hwndLogo = NULL; // 'LOGO'
  102. HWND g_hwndStatus = NULL;
  103. UINT g_idbLogo = 0;
  104. UINT g_numBackground = 0;
  105. UINT g_idbBackground[3] = {0, 0, 0};
  106. UINT g_idbSelectedBullet = 0;
  107. UINT g_idbReleasedBullet = 0;
  108. UINT g_idbCurrentBullet = 0;
  109. const TCHAR g_cszClassName[] = TEXT("RedCarpetWndClass");
  110. const TCHAR g_szStepsClassName[] = TEXT("InfoStepsWnd_Class");
  111. const TCHAR g_szBillBoardClassName[]= TEXT("BillBoardWnd_Class");
  112. const TCHAR g_szStatusClassName[] = TEXT("BB_WhistlerStatus_Class");
  113. LRESULT CALLBACK RedCarpetWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  114. LRESULT CALLBACK BillBoardWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  115. LRESULT CALLBACK AnimationWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  116. LRESULT CALLBACK StatusSubClassWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  117. LRESULT CALLBACK ProgressSubClassWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  118. //----------
  119. // BILLBRD
  120. //----------
  121. TCHAR g_szTFont[32];
  122. int g_nTFontHeight;
  123. int g_nTFontWidth;
  124. int g_nTFontWeight;
  125. BOOL g_bTitleShadow = TRUE;
  126. TCHAR g_szBFont[32];
  127. int g_nBFontHeight;
  128. int g_nBFontWidth;
  129. int g_nBFontWeight;
  130. BOOL g_bTextShadow = FALSE;
  131. int g_nBLineSpace;
  132. int g_nAnimID = 0;
  133. int g_iCurPanel = -1; // Current billboard to show
  134. int g_nPanelCount = 0; // how many billboards are there
  135. int g_nLogPixelsY = 1;
  136. COLORREF g_colTitle = 0;
  137. COLORREF g_colTitleShadow = 0;
  138. COLORREF g_colText = 0;
  139. COLORREF g_colTextShadow = 0;
  140. BB_TEXT bb_text_Personal[] = {
  141. {IDS_TITLE1_PER, IDS_TEXT1_PER, IDB_COLL1},
  142. {IDS_TITLE2_PER, IDS_TEXT2_PER, IDB_COLL2},
  143. {IDS_TITLE3_PER, IDS_TEXT3_PER, IDB_COLL2},
  144. {IDS_TITLE4_PER, IDS_TEXT4_PER, IDB_COLL3},
  145. {IDS_TITLE5_PER, IDS_TEXT5_PER, IDB_COLL3},
  146. {IDS_TITLE22_PER, IDS_TEXT22_PER, IDB_COLL10},
  147. {IDS_TITLE6_PER, IDS_TEXT6_PER, IDB_COLL4},
  148. {IDS_TITLE7_PER, IDS_TEXT7_PER, IDB_COLL4},
  149. {IDS_TITLE8_PER, IDS_TEXT8_PER, IDB_COLL5},
  150. {IDS_TITLE9_PER, IDS_TEXT9_PER, IDB_COLL5},
  151. {IDS_TITLE10_PER, IDS_TEXT10_PER, IDB_COLL6},
  152. {IDS_TITLE11_PER, IDS_TEXT11_PER, IDB_COLL6},
  153. {IDS_TITLE12_PER, IDS_TEXT12_PER, IDB_COLL7},
  154. {IDS_TITLE13_PER, IDS_TEXT13_PER, IDB_COLL7},
  155. {IDS_TITLE14_PER, IDS_TEXT14_PER, IDB_COLL8},
  156. {IDS_TITLE15_PER, IDS_TEXT15_PER, IDB_COLL8},
  157. {IDS_TITLE16_PER, IDS_TEXT16_PER, IDB_COLL9},
  158. {IDS_TITLE17_PER, IDS_TEXT17_PER, IDB_COLL9},
  159. {IDS_TITLE18_PER, IDS_TEXT18_PER, IDB_COLL10},
  160. {IDS_TITLE19_PER, IDS_TEXT19_PER, IDB_COLL10},
  161. {IDS_TITLE20_PER, IDS_TEXT20_PER, IDB_COLL10},
  162. {IDS_TITLE21_PER, IDS_TEXT21_PER, IDB_COLL10},
  163. {0,0,0}
  164. };
  165. BB_TEXT bb_text_Professional[] = {
  166. {IDS_TITLE1, IDS_TEXT1, IDB_COLL1},
  167. {IDS_TITLE2, IDS_TEXT2, IDB_COLL2},
  168. {IDS_TITLE3, IDS_TEXT3, IDB_COLL2},
  169. {IDS_TITLE4, IDS_TEXT4, IDB_COLL3},
  170. {IDS_TITLE5, IDS_TEXT5, IDB_COLL3},
  171. {IDS_TITLE6, IDS_TEXT6, IDB_COLL4},
  172. {IDS_TITLE7, IDS_TEXT7, IDB_COLL4},
  173. {IDS_TITLE8, IDS_TEXT8, IDB_COLL5},
  174. {IDS_TITLE9, IDS_TEXT9, IDB_COLL5},
  175. {IDS_TITLE18, IDS_TEXT18, IDB_COLL9},
  176. {IDS_TITLE10, IDS_TEXT10, IDB_COLL6},
  177. {IDS_TITLE11, IDS_TEXT11, IDB_COLL6},
  178. {IDS_TITLE12, IDS_TEXT12, IDB_COLL7},
  179. {IDS_TITLE13, IDS_TEXT13, IDB_COLL7},
  180. {IDS_TITLE14, IDS_TEXT14, IDB_COLL8},
  181. {IDS_TITLE15, IDS_TEXT15, IDB_COLL8},
  182. {IDS_TITLE16, IDS_TEXT16, IDB_COLL9},
  183. {IDS_TITLE17, IDS_TEXT17, IDB_COLL9},
  184. {0,0,0}
  185. };
  186. BB_TEXT bb_text_Blade[] = {
  187. {IDS_TITLE1_S, IDS_TEXT1_S, IDB_COLL1},
  188. {IDS_TITLE2_S, IDS_TEXT2_S, IDB_COLL2},
  189. {IDS_TITLE3_S, IDS_TEXT3_S, IDB_COLL2},
  190. {IDS_TITLE4_S, IDS_TEXT4_S, IDB_COLL3},
  191. {IDS_TITLE5_S, IDS_TEXT5_S, IDB_COLL3},
  192. {IDS_TITLE6_S, IDS_TEXT6_S, IDB_COLL4},
  193. {IDS_TITLE7_S, IDS_TEXT7_S, IDB_COLL4},
  194. {IDS_TITLE8_S, IDS_TEXT8_S, IDB_COLL5},
  195. {IDS_TITLE9_S, IDS_TEXT9_S, IDB_COLL5},
  196. {0,0,0}
  197. };
  198. BB_TEXT bb_text_Server[] = {
  199. {IDS_TITLE1_S, IDS_TEXT1_S, IDB_COLL1},
  200. {IDS_TITLE2_S, IDS_TEXT2_S, IDB_COLL2},
  201. {IDS_TITLE3_S, IDS_TEXT3_S, IDB_COLL2},
  202. {IDS_TITLE4_S, IDS_TEXT4_S, IDB_COLL3},
  203. {IDS_TITLE5_S, IDS_TEXT5_S, IDB_COLL3},
  204. {IDS_TITLE6_S, IDS_TEXT6_S, IDB_COLL4},
  205. {IDS_TITLE7_S, IDS_TEXT7_S, IDB_COLL4},
  206. {IDS_TITLE8_S, IDS_TEXT8_S, IDB_COLL5},
  207. {IDS_TITLE9_S, IDS_TEXT9_S, IDB_COLL5},
  208. {0,0,0}
  209. };
  210. BB_TEXT bb_text_AdvancedServer[] = {
  211. {IDS_TITLE1_S, IDS_TEXT1_S, IDB_COLL1},
  212. {IDS_TITLE2_S, IDS_TEXT2_S, IDB_COLL2},
  213. {IDS_TITLE3_S, IDS_TEXT3_S, IDB_COLL2},
  214. {IDS_TITLE4_S, IDS_TEXT4_S, IDB_COLL3},
  215. {IDS_TITLE5_S, IDS_TEXT5_S, IDB_COLL3},
  216. {IDS_TITLE6_S, IDS_TEXT6_S, IDB_COLL4},
  217. {IDS_TITLE7_S, IDS_TEXT7_S, IDB_COLL4},
  218. {IDS_TITLE8_S, IDS_TEXT8_S, IDB_COLL5},
  219. {IDS_TITLE9_S, IDS_TEXT9_S, IDB_COLL5},
  220. {0,0,0}
  221. };
  222. BB_TEXT bb_text_DataCenter[] = {
  223. {IDS_TITLE1_S, IDS_TEXT1_S, IDB_COLL1},
  224. {IDS_TITLE2_S, IDS_TEXT2_S, IDB_COLL2},
  225. {IDS_TITLE3_S, IDS_TEXT3_S, IDB_COLL2},
  226. {IDS_TITLE4_S, IDS_TEXT4_S, IDB_COLL3},
  227. {IDS_TITLE5_S, IDS_TEXT5_S, IDB_COLL3},
  228. {IDS_TITLE6_S, IDS_TEXT6_S, IDB_COLL4},
  229. {IDS_TITLE7_S, IDS_TEXT7_S, IDB_COLL4},
  230. {IDS_TITLE8_S, IDS_TEXT8_S, IDB_COLL5},
  231. {IDS_TITLE9_S, IDS_TEXT9_S, IDB_COLL5},
  232. {0,0,0}
  233. };
  234. BB_TEXT bb_text_Professional_IA64[] = {
  235. {IDS_TITLE1_64PRO, IDS_TEXT1_64PRO, IDB_COLL1},
  236. {IDS_TITLE2_64PRO, IDS_TEXT2_64PRO, IDB_COLL2},
  237. {IDS_TITLE3_64PRO, IDS_TEXT3_64PRO, IDB_COLL2},
  238. {IDS_TITLE4_64PRO, IDS_TEXT4_64PRO, IDB_COLL3},
  239. {IDS_TITLE5_64PRO, IDS_TEXT5_64PRO, IDB_COLL3},
  240. {IDS_TITLE6_64PRO, IDS_TEXT6_64PRO, IDB_COLL4},
  241. {IDS_TITLE7_64PRO, IDS_TEXT7_64PRO, IDB_COLL4},
  242. {IDS_TITLE8_64PRO, IDS_TEXT8_64PRO, IDB_COLL5},
  243. {IDS_TITLE9_64PRO, IDS_TEXT9_64PRO, IDB_COLL5},
  244. {IDS_TITLE10_64PRO, IDS_TEXT10_64PRO, IDB_COLL6},
  245. {IDS_TITLE11_64PRO, IDS_TEXT11_64PRO, IDB_COLL6},
  246. {IDS_TITLE12_64PRO, IDS_TEXT12_64PRO, IDB_COLL7},
  247. {IDS_TITLE13_64PRO, IDS_TEXT13_64PRO, IDB_COLL7},
  248. {0,0,0}
  249. };
  250. // 0 - professional,
  251. // 1 - Server,
  252. // 2 - Advanced Server,
  253. // 3 - Data Center,
  254. // 4 - for personal
  255. // 5 - for Blade
  256. DWORD dwBBTextType = 0;
  257. // Be careful with this order. It has to be the same as
  258. // *_PRODUCTTYPE in winnt32.h
  259. #ifdef _X86_
  260. BB_TEXT* bb_text[] = { bb_text_Professional,
  261. bb_text_Server,
  262. bb_text_AdvancedServer,
  263. bb_text_DataCenter,
  264. bb_text_Personal,
  265. bb_text_Blade};
  266. #else
  267. BB_TEXT* bb_text[] = { bb_text_Professional_IA64,
  268. bb_text_Server,
  269. bb_text_AdvancedServer,
  270. bb_text_DataCenter,
  271. bb_text_Personal };
  272. #endif
  273. HDC g_hdcBbMem = NULL;
  274. HBITMAP g_hbmpBbMemOld = NULL;
  275. HDC
  276. GetBillboardBuffer();
  277. BOOL
  278. BufferBillboard(
  279. IN HWND hwnd,
  280. IN HDC hdc
  281. );
  282. VOID
  283. DestroyBillboardBuffer();
  284. //---------
  285. // INFOBAR
  286. //---------
  287. COLORREF g_colInfoText = 0;
  288. COLORREF g_colStepsTxt = 0;
  289. COLORREF g_colStepsMarkTxt = 0;
  290. COLORREF g_colStepsCurrentTxt = 0;
  291. COLORREF g_colStepsTitle = 0;
  292. COLORREF g_colGaugeBg = 0;
  293. COLORREF g_colGauge = 0;
  294. COLORREF g_colBulletTrans = 0;
  295. //-------------
  296. // TIMEESTIMATE
  297. //-------------
  298. // Original position of the progress text window
  299. // Since we want the text adjusted to the bottom of the window
  300. // we resize the window as needed, but should not grow it
  301. // beyond the original size.
  302. RECT g_rcProgressText;
  303. //-----
  304. // LOGO
  305. //-----
  306. HBITMAP g_hbmWinLogo = NULL;
  307. COLORREF g_colLogoTransparency = RGB(0, 0, 0);
  308. COLORREF g_colStatusTransperency = RGB(0, 0, 0);
  309. //-----------
  310. // background
  311. //-----------
  312. HDC g_hdcMem = NULL;
  313. HBITMAP g_hbmpMemOld = NULL;
  314. INT g_iStretchMode = STRETCH_ANDSCANS;
  315. BOOL
  316. BufferBackground(
  317. IN HWND hwnd
  318. );
  319. LRESULT
  320. OnEraseBkgnd(
  321. HWND hwnd,
  322. WPARAM wParam,
  323. LPARAM lParam
  324. );
  325. VOID
  326. DestroyBackgroundBuffer();
  327. HBITMAP
  328. MyLoadImage(
  329. IN HDC hdc,
  330. IN UINT* idbBackground,
  331. IN int iNumImage
  332. );
  333. void SetFontCharSet(void)
  334. {
  335. HFONT hFont = NULL;
  336. LOGFONT lf;
  337. //init font charset
  338. hFont = GetStockObject(SYSTEM_FONT);
  339. if(hFont)
  340. {
  341. if(GetObject(hFont, sizeof(lf), &lf))
  342. g_bCharSet = lf.lfCharSet;
  343. DeleteObject(hFont);
  344. }
  345. }
  346. void SetFontColor(HWND hwnd)
  347. {
  348. HDC hdc;
  349. UINT uiBitsPixel;
  350. hdc = GetDC(hwnd);
  351. uiBitsPixel = (UINT) GetDeviceCaps(hdc, BITSPIXEL);
  352. if (uiBitsPixel > 8)
  353. {
  354. g_colTitle = COLOR_TITLE_C16BIT;
  355. g_colTitleShadow = COLOR_SHADOW_C16BIT;
  356. g_colText = COLOR_TEXT_C16BIT;
  357. g_colTextShadow = COLOR_SHADOW_C16BIT;
  358. g_colInfoText = UI_INFOTEXT_COLOR_C16BIT;
  359. g_colStepsTxt = UI_STEPSTEXT_COLOR_C16BIT;
  360. g_colStepsMarkTxt = UI_STEPSTEXT_MARK_COLOR_C16BIT;
  361. g_colStepsCurrentTxt = UI_STEPSTEXT_CURRENT_COLOR_C16BIT;
  362. g_colStepsTitle = UI_STEPSTITLE_COLOR_C16BIT;
  363. g_colGaugeBg = UI_GAUGE_BACKGROUND_COLOR_C16BIT;
  364. g_colGauge = UI_GAUGE_COLOR_C16BIT;
  365. g_colStatusTransperency = UI_STATUS_TRANSPARENT_COLOR_C16BIT;
  366. g_colLogoTransparency = UI_LOGO_TRANSPARENT_COLOR_C16BIT;
  367. g_colBulletTrans = UI_BULLET_TRANPARENT_COLOR_C16BIT;
  368. } else {
  369. g_colTitle = COLOR_TITLE_C4BIT;
  370. g_colTitleShadow = COLOR_SHADOW_C4BIT;
  371. g_colText = COLOR_TEXT_C4BIT;
  372. g_colTextShadow = COLOR_SHADOW_C4BIT;
  373. g_colInfoText = UI_INFOTEXT_COLOR_C4BIT;
  374. g_colStepsTxt = UI_STEPSTEXT_COLOR_C4BIT;
  375. g_colStepsCurrentTxt = UI_STEPSTEXT_CURRENT_COLOR_C4BIT;
  376. g_colStepsMarkTxt = UI_STEPSTEXT_MARK_COLOR_C4BIT;
  377. g_colStepsTitle = UI_STEPSTITLE_COLOR_C4BIT;
  378. g_colGaugeBg = UI_GAUGE_BACKGROUND_COLOR_C4BIT;
  379. g_colGauge = UI_GAUGE_COLOR_C4BIT;
  380. g_colStatusTransperency = UI_STATUS_TRANSPARENT_COLOR_C4BIT;
  381. g_colLogoTransparency = UI_LOGO_TRANSPARENT_COLOR_C4BIT;
  382. g_colBulletTrans = UI_BULLET_TRANPARENT_COLOR_C4BIT;
  383. }
  384. ReleaseDC(hwnd, hdc);
  385. }
  386. typedef struct _RES_FONTSIZES {
  387. UINT uiID;
  388. UINT uiDefault;
  389. } RES_FONTSIZES;
  390. RES_FONTSIZES res_1024[] = {
  391. {IDS_TITLEFONTSIZE_1024, 24},
  392. {IDS_TITLEFONTWIDTH_1024, 0},
  393. {IDS_TEXTFONTSIZE_1024, 11},
  394. {IDS_TEXTFONTWIDTH_1024, 0}
  395. };
  396. RES_FONTSIZES res_800[] = {
  397. {IDS_TITLEFONTSIZE_800, 21},
  398. {IDS_TITLEFONTWIDTH_800, 0},
  399. {IDS_TEXTFONTSIZE_800, 10},
  400. {IDS_TEXTFONTWIDTH_800, 0}
  401. };
  402. RES_FONTSIZES res_640[] = {
  403. {IDS_TITLEFONTSIZE_640, 18},
  404. {IDS_TITLEFONTWIDTH_640, 0},
  405. {IDS_TEXTFONTSIZE_640, 9},
  406. {IDS_TEXTFONTWIDTH_640, 0}
  407. };
  408. void GetMyFontsFromFile()
  409. {
  410. RECT rc;
  411. int iSize = 0;
  412. TCHAR szBuf[25];
  413. RES_FONTSIZES *pres_fontsize = NULL;
  414. iSize = GetSystemMetrics(SM_CXSCREEN);
  415. if (iSize >= 1024)
  416. {
  417. pres_fontsize = res_1024;
  418. }
  419. else if (iSize == 800)
  420. {
  421. pres_fontsize = res_800;
  422. }
  423. else
  424. {
  425. pres_fontsize = res_640;
  426. }
  427. if (LoadString(g_hInstance, pres_fontsize[0].uiID, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  428. g_nTFontHeight = MyAtoI((const TCHAR*)szBuf);
  429. else
  430. g_nTFontHeight = pres_fontsize[0].uiDefault;
  431. if (LoadString(g_hInstance, pres_fontsize[1].uiID, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  432. g_nTFontWidth = MyAtoI((const TCHAR*)szBuf);
  433. else
  434. g_nTFontWidth = pres_fontsize[1].uiDefault;
  435. if (LoadString(g_hInstance, pres_fontsize[2].uiID, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  436. g_nBFontHeight = MyAtoI((const TCHAR*)szBuf);
  437. else
  438. g_nBFontHeight = pres_fontsize[2].uiDefault;
  439. if (LoadString(g_hInstance, pres_fontsize[3].uiID, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  440. g_nBFontWidth = MyAtoI((const TCHAR*)szBuf);
  441. else
  442. g_nBFontWidth = pres_fontsize[3].uiDefault;
  443. if (!(LoadString(g_hInstance, IDS_TITLEFONTNAME, (LPTSTR)g_szTFont, sizeof(g_szTFont)/sizeof(TCHAR))))
  444. lstrcpy(g_szTFont, TEXT("Arial"));
  445. if (LoadString(g_hInstance, IDD_TITLEFONTWEIGHT, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  446. g_nTFontWeight = MyAtoI((const TCHAR*)szBuf);
  447. else
  448. g_nTFontWeight = FW_BOLD;
  449. if (!(LoadString(g_hInstance, IDS_TEXTFONTNAME, (LPTSTR)g_szBFont, sizeof(g_szBFont)/sizeof(TCHAR))))
  450. lstrcpy(g_szBFont, TEXT("Arial"));
  451. if (LoadString(g_hInstance, IDD_TEXTFONTWEIGHT, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  452. g_nBFontWeight = MyAtoI((const TCHAR*)szBuf);
  453. else
  454. g_nBFontWeight = FW_BOLD;
  455. if (LoadString(g_hInstance, IDD_BIDI, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  456. g_bBiDi = (0 != MyAtoI((const TCHAR*)szBuf));
  457. else
  458. g_bBiDi = FALSE;
  459. if (LoadString(g_hInstance, IDS_TEXTFONT_LINESPACING, (LPTSTR)szBuf, sizeof(szBuf)/sizeof(TCHAR)))
  460. g_nBLineSpace = MyAtoI((const TCHAR*)szBuf);
  461. else
  462. g_nBLineSpace = 0;
  463. return;
  464. }
  465. void GetMyImagesFromFile(HWND hwnd)
  466. {
  467. HDC hdc;
  468. UINT cxScreen;
  469. UINT uiBitsPixel;
  470. cxScreen = (UINT) GetSystemMetrics(SM_CXSCREEN);
  471. hdc = GetDC(hwnd);
  472. if (hdc != NULL)
  473. {
  474. uiBitsPixel = (UINT) GetDeviceCaps(hdc, BITSPIXEL);
  475. ReleaseDC(hwnd, hdc);
  476. }
  477. else
  478. {
  479. uiBitsPixel = 4;
  480. }
  481. if (uiBitsPixel > 8)
  482. {
  483. g_idbBackground[0] = IDB_BACKGROUND_C16BIT;
  484. g_numBackground = 1;
  485. g_iStretchMode = STRETCH_HALFTONE;
  486. g_idbSelectedBullet = IDB_SELECTEDBULLET_C16BIT;
  487. g_idbReleasedBullet = IDB_RELEASEDBULLET_C16BIT;
  488. g_idbCurrentBullet = IDB_CURRENTBULLET_C16BIT;
  489. if (cxScreen >= 1024)
  490. g_idbLogo = IDB_LOGO1024_C16BIT;
  491. else if (cxScreen >= 800)
  492. g_idbLogo = IDB_LOGO800_C16BIT;
  493. else
  494. g_idbLogo = IDB_LOGO640_C16BIT;
  495. }
  496. else
  497. {
  498. g_idbBackground[0] = IDB_BACKGROUND_C4BIT;
  499. g_numBackground = 1;
  500. g_iStretchMode = STRETCH_ANDSCANS;
  501. g_idbSelectedBullet = IDB_SELECTEDBULLET_C4BIT;
  502. g_idbReleasedBullet = IDB_RELEASEDBULLET_C4BIT;
  503. g_idbCurrentBullet = IDB_CURRENTBULLET_C4BIT;
  504. if (cxScreen >= 1024)
  505. g_idbLogo = IDB_LOGO1024_C4BIT;
  506. else if (cxScreen >= 800)
  507. g_idbLogo = IDB_LOGO800_C4BIT;
  508. else
  509. g_idbLogo = IDB_LOGO640_C4BIT;
  510. }
  511. }
  512. /****************************************************************************
  513. * SetLayoutParams()
  514. *
  515. * Set all the layout parameter for Billboard. All the floating point numbers
  516. * come the design specification. This function uses the values of
  517. * g_nBFontHeight and g_nTFontHeight.
  518. * NOTE: Call this function again and MoveWindow afterward, in case of
  519. * resolution changes
  520. *
  521. *****************************************************************************/
  522. void
  523. SetLayoutParams()
  524. {
  525. int cxScreen;
  526. int cyScreen;
  527. int iCommentLeft;
  528. int iCommonWidth;
  529. int iFontHeight;
  530. RECT rcSteps;
  531. UINT cySteps;
  532. cxScreen = GetSystemMetrics(SM_CXSCREEN);
  533. cyScreen = GetSystemMetrics(SM_CYSCREEN);
  534. iFontHeight = abs(GetInfoBarFontHeight());
  535. g_cyBannerHeight = cyScreen * 13 / 200;
  536. g_cxLogo = (UINT) (cxScreen * 0.0195);
  537. g_cyLogo = (UINT) (cyScreen * 0.0053);
  538. g_cxInfoBarWidth = (cxScreen) * 28 / 100;
  539. g_cyInfoBarHeight = (cyScreen) - g_cyBannerHeight * 2;
  540. if (cxScreen < 800)
  541. {
  542. rcSteps.left = g_cxInfoBarWidth * 3 / 20;
  543. rcSteps.top = g_cyBannerHeight * 2;
  544. rcSteps.right = g_cxInfoBarWidth - rcSteps.left;
  545. // Use 1.5 line height and reserve 2 lines for each step text, hence 7 / 2
  546. rcSteps.bottom = rcSteps.top + (iFontHeight * 7 / 2) * (UI_INFOBAR_NUM_STEPS) +
  547. (UINT) ((0.068) * cyScreen);
  548. iCommentLeft = rcSteps.left;
  549. iCommonWidth = g_cxInfoBarWidth - 2 * rcSteps.left;
  550. }
  551. else
  552. {
  553. rcSteps.left = (UINT) (0.039 * cxScreen);
  554. rcSteps.top = (UINT) (0.059 * cyScreen) + g_cyBannerHeight +
  555. g_nTFontHeight + g_nBFontHeight;
  556. rcSteps.right = rcSteps.left + (UINT) (0.2005 * cxScreen);
  557. // Use 1.5 line height and reserve 1 line for each step text, hence 5 / 2
  558. rcSteps.bottom = rcSteps.top + (iFontHeight * 5 / 2) * (UI_INFOBAR_NUM_STEPS) +
  559. (UINT) ((0.068) * cyScreen);
  560. iCommentLeft = rcSteps.left;
  561. iCommonWidth = (UINT) (0.1705 * cxScreen);
  562. }
  563. if (GetStepsHeight(g_cxInfoBarWidth, cyScreen, rcSteps, &cySteps))
  564. {
  565. rcSteps.bottom = cySteps;
  566. }
  567. g_cxSteps = rcSteps.left;
  568. g_cySteps = rcSteps.top;
  569. g_cxStepsWidth = rcSteps.right - rcSteps.left;
  570. g_cyStepsHeight = rcSteps.bottom - rcSteps.top;
  571. g_cxEstimate = iCommentLeft;
  572. if (cxScreen < 800)
  573. {
  574. g_cyEstimate = g_cyStepsHeight + g_cySteps + 3 * iFontHeight / 2;
  575. }
  576. else
  577. {
  578. g_cyEstimate = g_cyStepsHeight + g_cySteps + (UINT) (0.063 * cyScreen);
  579. }
  580. g_cxEstimateWidth = iCommonWidth;
  581. g_cyEstimateHeight = iFontHeight * 5;
  582. g_cxProgressText = iCommentLeft;
  583. g_cyProgressText = g_cyEstimateHeight + g_cyEstimate;
  584. g_cxProgressTextWidth = iCommonWidth;
  585. g_cyProgressTextHeight = iFontHeight * 3;
  586. g_cxGauge = iCommentLeft;
  587. g_cyGauge = g_cyProgressTextHeight + g_cyProgressText + iFontHeight / 3;
  588. g_cxGaugeWidth = iCommonWidth;
  589. g_cyGaugeHeight = iFontHeight * 3 / 2;
  590. g_cxInfoText = iCommentLeft;
  591. if (cxScreen < 800)
  592. {
  593. g_cyInfoText = g_cyGauge + g_cyGaugeHeight + iFontHeight;
  594. g_cyInfoTextHeight = cyScreen - g_cyInfoText - g_cyBannerHeight;
  595. }
  596. else
  597. {
  598. g_cyInfoTextHeight = (cyScreen - g_cyGaugeHeight - iFontHeight / 3 -
  599. g_cyGauge - g_cyBannerHeight) * 2 / 3 + iFontHeight;
  600. g_cyInfoText = cyScreen - g_cyBannerHeight - g_cyInfoTextHeight;
  601. }
  602. g_cxInfoTextWidth = iCommonWidth;
  603. if (g_bBiDi)
  604. {
  605. // mirroring along the center of infobar.
  606. int shiftAmt = g_cxInfoBarWidth - 2 * g_cxEstimate - g_cxEstimateWidth;
  607. if (shiftAmt < 0)
  608. {
  609. shiftAmt = 0;
  610. }
  611. g_cxSteps = g_cxInfoBarWidth - g_cxSteps - g_cxStepsWidth - shiftAmt;
  612. g_cxEstimate = g_cxInfoBarWidth - g_cxEstimate - g_cxEstimateWidth - shiftAmt;
  613. g_cxProgressText = g_cxInfoBarWidth - g_cxProgressText - g_cxProgressTextWidth - shiftAmt;
  614. g_cxGauge = g_cxInfoBarWidth - g_cxGauge - g_cxGaugeWidth - shiftAmt;
  615. g_cxInfoText = g_cxInfoBarWidth - g_cxInfoText - g_cxInfoTextWidth - shiftAmt;
  616. }
  617. g_cxBillBrd = g_cxInfoBarWidth;
  618. g_cyBillBrd = g_cyBannerHeight;
  619. g_cxBillBrdWidth = cxScreen - g_cxBillBrd;
  620. g_cyBillBrdHeight = g_cyInfoBarHeight;
  621. g_cxBillBrdHMargin = (UINT) (cxScreen * 0.06);
  622. g_cyBillBrdVMargin = 0;
  623. // Only substract 2*margin for the area for the billboard title
  624. // otherwise the new text does not fit on 640x480
  625. g_cxBillBrdTitleWidth = g_cxBillBrdWidth - (2 * g_cxBillBrdHMargin);
  626. g_cyBillBrdTitleTop = g_cySteps - g_cyBillBrd;
  627. // Only substract 2*margin for the area for the billboard text
  628. // otherwise the new text does not fit on 640x480
  629. g_cxBillBrdBodyWidth = g_cxBillBrdWidth - (2 * g_cxBillBrdHMargin);
  630. }
  631. HDC
  632. GetBackgroundBuffer()
  633. {
  634. return g_hdcMem;
  635. }
  636. VOID
  637. DestroyBackgroundBuffer()
  638. {
  639. HBITMAP hbmpMem;
  640. hbmpMem = SelectObject(g_hdcMem, g_hbmpMemOld);
  641. if (hbmpMem)
  642. {
  643. DeleteObject(hbmpMem);
  644. }
  645. g_hbmpMemOld = NULL;
  646. DeleteDC(g_hdcMem);
  647. g_hdcMem = NULL;
  648. }
  649. BOOL
  650. StretchBitmapAndDisplay(
  651. HDC hdcDest,
  652. int nXOriginDest,
  653. int nYOriginDest,
  654. int nWidthDest,
  655. int nHeightDest,
  656. HDC hdcSrc,
  657. int nXOriginSrc,
  658. int nYOriginSrc,
  659. int nWidthSrc,
  660. int nHeightSrc,
  661. DWORD fdwRop
  662. )
  663. /*++
  664. Routine Description:
  665. This function takes a bitmap that needs to be displayed and stretches it
  666. using GDI. Once the bitmap is stretched to the required dimentions we display
  667. it using BitBlt. We have to do this decause some buggy video drivers and or
  668. hardware hang on using StretchBlt.
  669. Or the StretchBlt would generate a corupted bitmap.
  670. Arguments:
  671. hdcDest destination device-context handle
  672. nXOriginDest x-coordinate of origin of destination rectangle
  673. nYOriginDest y-coordinate of origin of destination rectangle
  674. nWidthDest width of destination rectangle
  675. nHeightDest height of destination rectangle
  676. hdcSrc source device-context handle
  677. nXOriginSrc x-coordinate of origin of source rectangle
  678. nYOriginSrc y-coordinate of origin of source rectangle
  679. nWidthSrc width of source rectangle
  680. nHeightSrc height of source rectangle
  681. fdwRop raster operation
  682. Return value:
  683. TRUE == SUCCESS
  684. Changes:
  685. 10/11/97 hanumany Created
  686. 04/30/01 chunhoc Modified
  687. --*/
  688. {
  689. HDC hdcTemp = NULL;
  690. BOOL bRet = FALSE;
  691. int iOldStretchMode = 0;
  692. HBITMAP hBmp = NULL;
  693. HBITMAP hBmpOld = NULL;
  694. UINT uiNumColors = 0;
  695. //Create the temp DC
  696. hdcTemp = CreateCompatibleDC(hdcDest);
  697. //Create a bitmap
  698. hBmp = CreateCompatibleBitmap(hdcSrc, nWidthDest, nHeightDest);
  699. if(hdcTemp && hBmp)
  700. {
  701. // Select it into the temp DC
  702. hBmpOld = SelectObject(hdcTemp, hBmp);
  703. //set stretch blt mode
  704. iOldStretchMode = SetStretchBltMode(hdcTemp, g_iStretchMode);
  705. //StretchBlt
  706. bRet = StretchBlt(hdcTemp,
  707. 0,
  708. 0,
  709. nWidthDest,
  710. nHeightDest,
  711. hdcSrc,
  712. nXOriginSrc,
  713. nYOriginSrc,
  714. nWidthSrc,
  715. nHeightSrc,
  716. fdwRop);
  717. // restore the old stretch mode
  718. SetStretchBltMode(hdcTemp, iOldStretchMode);
  719. if(bRet)
  720. {
  721. //We succeeded in stretching the bitmap on the temp DC. Now lets BitBlt it.
  722. bRet = BitBlt(hdcDest,
  723. nXOriginDest,
  724. nYOriginDest,
  725. nWidthDest,
  726. nHeightDest,
  727. hdcTemp,
  728. 0,
  729. 0,
  730. SRCCOPY);
  731. }
  732. }
  733. //CleanUp
  734. if(hBmpOld)
  735. {
  736. SelectObject(hdcTemp, hBmpOld);
  737. }
  738. if(hBmp)
  739. {
  740. DeleteObject(hBmp);
  741. }
  742. if(hdcTemp)
  743. {
  744. DeleteDC(hdcTemp);
  745. }
  746. return bRet;
  747. }
  748. BOOL
  749. BufferBackground(
  750. IN HWND hwnd
  751. )
  752. /*++
  753. Routine Description:
  754. Create a memory buffer for the stretched bitmap to improve performance.
  755. Arguments:
  756. hwnd - Handle to the window on which the background bitmap is drawn
  757. Return Value:
  758. TRUE - if the buffered background image is created successfully
  759. FALSE - otherwise
  760. g_hdcMem - The memory DC to receive the buffered bitmap if succeeeds,
  761. NULL if fails.
  762. g_hbmpMemOld - Save the old memory buffer of g_hdcMem
  763. --*/
  764. {
  765. BOOL bRet = FALSE;
  766. HDC hdcMem = NULL;
  767. HBITMAP hbmpMemOld= NULL;
  768. HBITMAP hbmpMem = NULL;
  769. HDC hdc = NULL;
  770. HDC hdcImgSrc = NULL;
  771. BITMAP bm;
  772. HBITMAP hbmBackground = NULL;
  773. HBITMAP hBitmapOld = NULL;
  774. RECT rcBackground;
  775. if (!GetClientRect(hwnd, &rcBackground))
  776. {
  777. goto cleanup;
  778. }
  779. hdc = GetDC(hwnd);
  780. if (!hdc)
  781. {
  782. goto cleanup;
  783. }
  784. hbmpMem = CreateCompatibleBitmap(hdc,
  785. rcBackground.right - rcBackground.left,
  786. rcBackground.bottom - rcBackground.top);
  787. hdcMem = CreateCompatibleDC(hdc);
  788. if (!hdcMem || !hbmpMem)
  789. {
  790. goto cleanup;
  791. }
  792. hbmpMemOld = SelectObject(hdcMem, hbmpMem);
  793. if (g_numBackground > 1)
  794. {
  795. hbmBackground = MyLoadImage(hdc, g_idbBackground, g_numBackground);
  796. }
  797. else
  798. {
  799. hbmBackground = (HBITMAP) LoadImage(g_hInstance,
  800. MAKEINTRESOURCE(g_idbBackground[0]),
  801. IMAGE_BITMAP,
  802. 0,
  803. 0,
  804. LR_DEFAULTSIZE);
  805. }
  806. hdcImgSrc = CreateCompatibleDC(hdc);
  807. if (!hbmBackground || !hdcImgSrc)
  808. {
  809. goto cleanup;
  810. }
  811. hBitmapOld = (HBITMAP) SelectObject(hdcImgSrc, hbmBackground);
  812. GetObject(hbmBackground , sizeof(BITMAP), &bm);
  813. bRet = StretchBitmapAndDisplay(hdcMem,
  814. 0,
  815. 0,
  816. rcBackground.right - rcBackground.left,
  817. rcBackground.bottom - rcBackground.top,
  818. hdcImgSrc,
  819. 0,
  820. 0,
  821. bm.bmWidth,
  822. bm.bmHeight,
  823. SRCCOPY);
  824. SelectObject(hdcImgSrc, hBitmapOld);
  825. if (bRet)
  826. {
  827. g_hdcMem = hdcMem;
  828. g_hbmpMemOld = hbmpMemOld;
  829. hdcMem = NULL;
  830. hbmpMemOld = NULL;
  831. hbmpMem = NULL;
  832. }
  833. cleanup:
  834. if (hdcImgSrc)
  835. {
  836. DeleteDC(hdcImgSrc);
  837. }
  838. if (hbmBackground)
  839. {
  840. DeleteObject(hbmBackground);
  841. }
  842. if (hbmpMemOld != NULL)
  843. {
  844. SelectObject(hdcMem, hbmpMemOld);
  845. }
  846. if (hbmpMem != NULL)
  847. {
  848. DeleteObject(hbmpMem);
  849. }
  850. if (hdcMem != NULL)
  851. {
  852. DeleteDC(hdcMem);
  853. }
  854. if (hdc)
  855. {
  856. ReleaseDC(hwnd, hdc);
  857. }
  858. return bRet;
  859. }
  860. LRESULT
  861. OnEraseBkgnd(
  862. HWND hwnd,
  863. WPARAM wParam,
  864. LPARAM lParam
  865. )
  866. /*++
  867. Routine Description:
  868. Handle the WM_ERASEBKGND for the child windows of the main window,
  869. RedCarpetWndClass
  870. Arguments:
  871. hwnd - hwnd to a child window of RedCarpetWndClass
  872. wParam - same as the wParam pass to WM_ERASEBKGND (see MSDN)
  873. lParam - same as the lParam pass to WM_ERASEBKGND (see MSDN)
  874. Return Value:
  875. 1 if the background is erased successfully, 0 otherwise. (see MSDN)
  876. --*/
  877. {
  878. LRESULT lRet = 0;
  879. RECT rc;
  880. RECT rcToParent;
  881. if (GetClientRect(hwnd, &rc))
  882. {
  883. HDC hdc = (HDC) wParam;
  884. HDC hdcMem;
  885. hdcMem = GetBackgroundBuffer();
  886. GetRectInParent(hwnd, &rc, &rcToParent);
  887. lRet = (LRESULT) BitBlt(hdc,
  888. rc.left,
  889. rc.top,
  890. rc.right - rc.left,
  891. rc.bottom - rc.top,
  892. hdcMem,
  893. rcToParent.left,
  894. rcToParent.top,
  895. SRCCOPY);
  896. }
  897. return lRet;
  898. }
  899. HDC
  900. GetBillboardBuffer()
  901. {
  902. return g_hdcBbMem;
  903. }
  904. VOID
  905. DestroyBillboardBuffer()
  906. {
  907. HBITMAP hbmpMem;
  908. hbmpMem = SelectObject(g_hdcBbMem, g_hbmpBbMemOld);
  909. if (hbmpMem)
  910. {
  911. DeleteObject(hbmpMem);
  912. }
  913. g_hbmpBbMemOld = NULL;
  914. DeleteDC(g_hdcBbMem);
  915. g_hdcBbMem = NULL;
  916. }
  917. HBITMAP
  918. MyLoadImage(
  919. IN HDC hdc,
  920. IN UINT* idbBackground,
  921. IN int iNumImage
  922. )
  923. /*++
  924. Routine Description:
  925. OR all the specified bitmaps in the resource file and return the result
  926. image handle. This is particularly useful when we want to use RLE on a
  927. 16 or 24-bit bitmap, because DIB format only permits RLE of 4bpp or 8bpp
  928. bitmap.
  929. Arguments:
  930. hdc - a device context
  931. idbBackground - list of bitmap resource id's
  932. iNumImage - number of id in idbBackground
  933. Return Values:
  934. the result image handle on success; NULL on failure
  935. Note:
  936. Assume all the bitmaps have the same dimension.
  937. --*/
  938. {
  939. HBITMAP hbmBackground[] = {NULL, NULL, NULL};
  940. HBITMAP hbmpImgSrcOld = NULL;
  941. HDC hdcImgSrc = NULL;
  942. HBITMAP hbmpMem = NULL;
  943. HBITMAP hbmpMemOld = NULL;
  944. HDC hdcMem = NULL;
  945. HBITMAP hbmpRet = NULL;
  946. DWORD dwRop;
  947. int i;
  948. BITMAP bm;
  949. for (i = 0; i < iNumImage; i++)
  950. {
  951. hbmBackground[i] = (HBITMAP) LoadImage(g_hInstance,
  952. MAKEINTRESOURCE(idbBackground[i]),
  953. IMAGE_BITMAP,
  954. 0,
  955. 0,
  956. LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
  957. if (hbmBackground[i] == NULL)
  958. {
  959. goto cleanup;
  960. }
  961. }
  962. hdcImgSrc = CreateCompatibleDC(hdc);
  963. if (hdcImgSrc == NULL)
  964. {
  965. goto cleanup;
  966. }
  967. if (!GetObject(hbmBackground[0], sizeof(BITMAP), &bm))
  968. {
  969. goto cleanup;
  970. }
  971. hbmpMem = CreateCompatibleBitmap(hdc, bm.bmWidth, bm.bmHeight);
  972. hdcMem = CreateCompatibleDC(hdc);
  973. if (!hdcMem || !hbmpMem)
  974. {
  975. goto cleanup;
  976. }
  977. i = 0;
  978. dwRop = SRCCOPY;
  979. hbmpMemOld = SelectObject(hdcMem, hbmpMem);
  980. hbmpImgSrcOld = (HBITMAP) SelectObject(hdcImgSrc, hbmBackground[i]);
  981. while (TRUE)
  982. {
  983. if (!BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcImgSrc, 0, 0, dwRop))
  984. {
  985. goto cleanup;
  986. }
  987. i++;
  988. if (i >= iNumImage)
  989. {
  990. break;
  991. }
  992. dwRop = SRCPAINT;
  993. SelectObject(hdcImgSrc, hbmBackground[i]);
  994. }
  995. hbmpRet = hbmpMem;
  996. hbmpMem = NULL;
  997. cleanup:
  998. if (hbmpImgSrcOld)
  999. {
  1000. SelectObject(hdcImgSrc, hbmpImgSrcOld);
  1001. }
  1002. if (hbmpMemOld)
  1003. {
  1004. SelectObject(hdcMem, hbmpMemOld);
  1005. }
  1006. if (hdcMem)
  1007. {
  1008. DeleteDC(hdcMem);
  1009. }
  1010. if (hbmpMem)
  1011. {
  1012. DeleteObject(hbmpMem);
  1013. }
  1014. if (hdcImgSrc)
  1015. {
  1016. DeleteDC(hdcImgSrc);
  1017. }
  1018. for (i = 0; i < iNumImage; i++)
  1019. {
  1020. if (hbmBackground[i])
  1021. {
  1022. DeleteObject(hbmBackground[i]);
  1023. }
  1024. }
  1025. return hbmpRet;
  1026. }
  1027. BOOL
  1028. BufferBillboard(
  1029. IN HWND hwnd,
  1030. IN HDC hdc
  1031. )
  1032. /*++
  1033. Routine Description:
  1034. Create a memory buffer for the billboard.
  1035. Arguments:
  1036. hwnd - Handle to the window on which the Billboard bitmap is drawn
  1037. hdc - Handle to the screen DC of billboard
  1038. Return Value:
  1039. TRUE - if the buffered background image is created successfully
  1040. FALSE - otherwise
  1041. g_hdcBbMem - The memory DC to receive the buffered bitmap if succeeeds,
  1042. NULL if fails.
  1043. g_hbmpBbMem - Save the old memory buffer of g_hdcBbMem
  1044. --*/
  1045. {
  1046. BOOL bRet = FALSE;
  1047. HDC hdcMem = NULL;
  1048. HBITMAP hbmpMem = NULL;
  1049. RECT rcBillboard;
  1050. if (!GetClientRect(hwnd, &rcBillboard))
  1051. {
  1052. goto cleanup;
  1053. }
  1054. hbmpMem = CreateCompatibleBitmap(hdc,
  1055. rcBillboard.right - rcBillboard.left,
  1056. rcBillboard.bottom - rcBillboard.top);
  1057. hdcMem = CreateCompatibleDC(hdc);
  1058. if (!hdcMem || !hbmpMem)
  1059. {
  1060. goto cleanup;
  1061. }
  1062. g_hbmpBbMemOld = SelectObject(hdcMem, hbmpMem);
  1063. Animate(hdcMem);
  1064. bRet = TRUE;
  1065. g_hdcBbMem = hdcMem;
  1066. hdcMem = NULL;
  1067. hbmpMem = NULL;
  1068. cleanup:
  1069. if (hbmpMem != NULL)
  1070. {
  1071. SelectObject(hdcMem, g_hbmpBbMemOld);
  1072. DeleteObject(hbmpMem);
  1073. g_hbmpBbMemOld = NULL;
  1074. }
  1075. if (hdcMem != NULL) {
  1076. DeleteDC(hdcMem);
  1077. }
  1078. return bRet;
  1079. }
  1080. /*****************************************************************************
  1081. *
  1082. * GetRectInParent(hwndChild, prcClip, pRect)
  1083. *
  1084. * This function gets the rect of child window relative to the client
  1085. * coordinate of the parent
  1086. *
  1087. ******************************************************************************/
  1088. void GetRectInParent(HWND hwndChild, LPRECT prcClip, LPRECT pRect)
  1089. {
  1090. RECT rcChild;
  1091. POINT ptChild;
  1092. HWND hwnd;
  1093. hwnd = GetParent(hwndChild);
  1094. if (hwnd == NULL)
  1095. {
  1096. hwnd = hwndChild;
  1097. }
  1098. if ( prcClip == NULL ) {
  1099. GetClientRect( hwndChild, &rcChild );
  1100. } else {
  1101. rcChild = *prcClip;
  1102. }
  1103. ptChild.x = rcChild.left;
  1104. ptChild.y = rcChild.top;
  1105. ClientToScreen( hwndChild, &ptChild );
  1106. ScreenToClient( hwnd, &ptChild );
  1107. pRect->left = ptChild.x;
  1108. pRect->top = ptChild.y;
  1109. ptChild.x = rcChild.right;
  1110. ptChild.y = rcChild.bottom;
  1111. ClientToScreen( hwndChild, &ptChild );
  1112. ScreenToClient( hwnd, &ptChild );
  1113. pRect->right = ptChild.x;
  1114. pRect->bottom = ptChild.y;
  1115. }
  1116. BOOL WINAPI InitRealBillBoard(HWND hwndParent)
  1117. {
  1118. WNDCLASS wc;
  1119. RECT rc1;
  1120. wc.style = (UINT)CS_BYTEALIGNWINDOW;
  1121. wc.lpfnWndProc = (WNDPROC)BillBoardWndProc;
  1122. wc.cbClsExtra = 0;
  1123. wc.cbWndExtra = 0;
  1124. wc.hInstance = g_hInstance;
  1125. wc.hIcon = NULL;
  1126. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1127. wc.hbrBackground = NULL;
  1128. wc.lpszMenuName = NULL;
  1129. wc.lpszClassName = g_szBillBoardClassName;
  1130. if (!RegisterClass (&wc))
  1131. return FALSE;
  1132. GetWindowRect(hwndParent, &rc1);
  1133. rc1.left = rc1.left + g_cxBillBrd;
  1134. rc1.top = rc1.top + g_cyBillBrd;
  1135. rc1.bottom = rc1.top + g_cyBillBrdHeight;
  1136. g_hwndBB = CreateWindow(
  1137. g_szBillBoardClassName,
  1138. TEXT(""),
  1139. WS_CHILD,
  1140. rc1.left,
  1141. rc1.top,
  1142. rc1.right - rc1.left,
  1143. rc1.bottom - rc1.top,
  1144. hwndParent,
  1145. NULL,
  1146. g_hInstance,
  1147. NULL);
  1148. if (g_hwndBB == NULL)
  1149. {
  1150. UnregisterClass(g_szBillBoardClassName, g_hInstance);
  1151. return FALSE;
  1152. }
  1153. ShowWindow( g_hwndBB, SW_HIDE );
  1154. return TRUE;
  1155. }
  1156. BOOL WINAPI InitStatus(HWND hwndParent)
  1157. {
  1158. WNDCLASS wc;
  1159. RECT rc1;
  1160. wc.style = (UINT)CS_BYTEALIGNWINDOW;
  1161. wc.lpfnWndProc = (WNDPROC)AnimationWndProc;
  1162. wc.cbClsExtra = 0;
  1163. wc.cbWndExtra = 0;
  1164. wc.hInstance = g_hInstance;
  1165. wc.hIcon = NULL;
  1166. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1167. wc.hbrBackground = NULL;
  1168. wc.lpszMenuName = NULL;
  1169. wc.lpszClassName = g_szStatusClassName;
  1170. if (!RegisterClass (&wc))
  1171. {
  1172. return FALSE;
  1173. }
  1174. GetWindowRect(hwndParent, &rc1);
  1175. g_hwndStatus = CreateWindowEx(
  1176. WS_EX_TRANSPARENT,
  1177. g_szStatusClassName,
  1178. TEXT(""),
  1179. WS_CHILD,
  1180. 0,
  1181. 0,
  1182. 0,
  1183. 0,
  1184. hwndParent,
  1185. NULL,
  1186. g_hInstance,
  1187. NULL );
  1188. if (g_hwndStatus == NULL)
  1189. {
  1190. UnregisterClass(g_szStatusClassName, g_hInstance);
  1191. return FALSE;
  1192. }
  1193. ShowWindow( g_hwndStatus, SW_HIDE );
  1194. return TRUE;
  1195. }
  1196. BOOL WINAPI InitProgressBar(HWND hwndParent)
  1197. {
  1198. RECT rc1;
  1199. GetWindowRect(hwndParent, &rc1);
  1200. g_hwndTimeEstimate = CreateWindowEx(
  1201. (g_bBiDi?WS_EX_RTLREADING:0),
  1202. TEXT("STATIC"),
  1203. NULL,
  1204. WS_CHILD | (g_bBiDi?SS_RIGHT:SS_LEFT)| SS_NOPREFIX,
  1205. rc1.left + g_cxEstimate,
  1206. rc1.top + g_cyEstimate,
  1207. g_cxEstimateWidth,
  1208. g_cyEstimateHeight,
  1209. hwndParent,
  1210. NULL,
  1211. g_hInstance,
  1212. NULL );
  1213. if (g_hwndTimeEstimate)
  1214. {
  1215. // Set the font for the text in this window
  1216. SendMessage(g_hwndTimeEstimate, WM_SETFONT, (WPARAM)g_hfont ,0L);
  1217. SetWindowLongPtr(g_hwndTimeEstimate, GWLP_WNDPROC, (LONG_PTR) StatusSubClassWndProc);
  1218. ShowWindow(g_hwndTimeEstimate, SW_SHOW);
  1219. UpdateWindow(g_hwndTimeEstimate);
  1220. }
  1221. g_hwndProgressText = CreateWindowEx(
  1222. (g_bBiDi?WS_EX_RTLREADING:0),
  1223. TEXT("STATIC"),
  1224. NULL,
  1225. WS_CHILD | (g_bBiDi?SS_RIGHT:SS_LEFT)| SS_NOPREFIX,
  1226. rc1.left + g_cxProgressText,
  1227. rc1.top + g_cyProgressText,
  1228. g_cxProgressTextWidth,
  1229. g_cyProgressTextHeight,
  1230. hwndParent,
  1231. NULL,
  1232. g_hInstance,
  1233. NULL );
  1234. if (g_hwndProgressText)
  1235. {
  1236. // Save the original position
  1237. GetWindowRect(g_hwndProgressText , &g_rcProgressText);
  1238. SendMessage( g_hwndProgressText, WM_SETFONT, (WPARAM)g_hfont ,0L );
  1239. SetWindowLongPtr(g_hwndProgressText, GWLP_WNDPROC, (LONG_PTR) StatusSubClassWndProc);
  1240. ShowWindow( g_hwndProgressText, SW_SHOW );
  1241. UpdateWindow( g_hwndProgressText );
  1242. }
  1243. g_hwndProgressGauge = CreateWindow(
  1244. PROGRESS_CLASS,
  1245. NULL,
  1246. WS_CHILD | PBS_SMOOTH ,
  1247. rc1.left + g_cxGauge,
  1248. rc1.top + g_cyGauge,
  1249. g_cxGaugeWidth,
  1250. g_cyGaugeHeight,
  1251. hwndParent,
  1252. NULL,
  1253. g_hInstance,
  1254. NULL );
  1255. if (g_hwndProgressGauge)
  1256. {
  1257. SetWindowLongPtr(g_hwndProgressGauge, GWLP_WNDPROC, (LONG_PTR) ProgressSubClassWndProc);
  1258. SendMessage( g_hwndProgressGauge, PBM_SETBKCOLOR, 0L, (LPARAM) g_colGaugeBg );
  1259. SendMessage( g_hwndProgressGauge, PBM_SETBARCOLOR, 0L, (LPARAM) g_colGauge );
  1260. }
  1261. g_hwndInfoText = CreateWindowEx(
  1262. (g_bBiDi?WS_EX_RTLREADING:0),
  1263. TEXT("STATIC"),
  1264. NULL,
  1265. WS_CHILD | (g_bBiDi?SS_RIGHT:SS_LEFT)| SS_NOPREFIX,
  1266. rc1.left + g_cxInfoText,
  1267. rc1.top + g_cyInfoText,
  1268. g_cxInfoTextWidth,
  1269. g_cyInfoTextHeight,
  1270. hwndParent,
  1271. NULL,
  1272. g_hInstance,
  1273. NULL);
  1274. if (g_hwndInfoText)
  1275. {
  1276. // Set the font for the text in this window
  1277. SendMessage(g_hwndInfoText, WM_SETFONT, (WPARAM)g_hfont ,0L);
  1278. SetWindowLongPtr(g_hwndInfoText, GWLP_WNDPROC, (LONG_PTR) StatusSubClassWndProc);
  1279. ShowWindow(g_hwndInfoText, SW_SHOW);
  1280. UpdateWindow(g_hwndInfoText);
  1281. }
  1282. g_hbmWinLogo = LoadImage(
  1283. g_hInstance,
  1284. MAKEINTRESOURCE(g_idbLogo),
  1285. IMAGE_BITMAP,
  1286. 0,
  1287. 0,
  1288. LR_DEFAULTCOLOR );
  1289. if (g_hbmWinLogo)
  1290. {
  1291. BITMAP bm;
  1292. if (GetObject(g_hbmWinLogo, sizeof(BITMAP), &bm))
  1293. {
  1294. g_hwndLogo = CreateWindow(TEXT("STATIC"),
  1295. NULL,
  1296. WS_VISIBLE | WS_CHILD | SS_OWNERDRAW,
  1297. rc1.left + g_cxLogo,
  1298. rc1.top + g_cyLogo,
  1299. bm.bmWidth,
  1300. bm.bmHeight,
  1301. hwndParent,
  1302. NULL,
  1303. g_hInstance,
  1304. NULL);
  1305. if (g_hwndLogo)
  1306. {
  1307. SetWindowLongPtr(g_hwndLogo,
  1308. GWLP_WNDPROC,
  1309. (LONG_PTR) StatusSubClassWndProc);
  1310. }
  1311. }
  1312. }
  1313. return TRUE;
  1314. }
  1315. LRESULT CALLBACK
  1316. StatusSubClassWndProc(
  1317. HWND hwnd,
  1318. UINT msg,
  1319. WPARAM wParam,
  1320. LPARAM lParam)
  1321. /*++
  1322. Routine Description:
  1323. Subclass the Static Text control used in Billboard and override the
  1324. WM_ERASEBKGND message, so that the bitmap background can be shown
  1325. behind the text.
  1326. Arguments:
  1327. hwnd - hwnd to a static text window, which must be a child window of
  1328. the main billboard window
  1329. msg - (see MSDN)
  1330. wParam - (see MSDN)
  1331. lParam - (see MSDN)
  1332. Return Value:
  1333. (see MSDN)
  1334. --*/
  1335. {
  1336. LRESULT lRet;
  1337. // don't process any message before the CreateWindow of the
  1338. // main window return and g_hwnd is set.
  1339. if (g_hwnd != NULL && msg == WM_ERASEBKGND)
  1340. {
  1341. lRet = OnEraseBkgnd(hwnd, wParam, lParam);
  1342. }
  1343. else
  1344. {
  1345. WNDPROC fpStaticWndProc = (WNDPROC) GetClassLongPtr(hwnd, GCLP_WNDPROC);
  1346. lRet = CallWindowProc(fpStaticWndProc, hwnd, msg, wParam, lParam);
  1347. }
  1348. return lRet;
  1349. }
  1350. LRESULT CALLBACK
  1351. ProgressSubClassWndProc(
  1352. HWND hwnd,
  1353. UINT msg,
  1354. WPARAM wParam,
  1355. LPARAM lParam)
  1356. /*++
  1357. Routine Description:
  1358. Subclass the Progress bar control used in Billboard and override the
  1359. WM_NCPAINT message, so as to draw a flat progress bar.
  1360. Arguments:
  1361. hwnd - hwnd to a progress bar window
  1362. msg - (see MSDN)
  1363. wParam - (see MSDN)
  1364. lParam - (see MSDN)
  1365. Return Value:
  1366. (see MSDN)
  1367. --*/
  1368. {
  1369. LRESULT lRet;
  1370. if (msg == WM_NCPAINT)
  1371. {
  1372. RECT rc;
  1373. if (GetWindowRect(hwnd, &rc))
  1374. {
  1375. HDC hdc = GetWindowDC(hwnd);
  1376. if (hdc != NULL)
  1377. {
  1378. HBRUSH hbrOld;
  1379. HPEN hpnOld;
  1380. hbrOld = SelectObject(hdc, GetStockObject(NULL_BRUSH));
  1381. hpnOld = SelectObject(hdc, GetStockObject(BLACK_PEN));
  1382. Rectangle(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top);
  1383. SelectObject(hdc, hpnOld);
  1384. SelectObject(hdc, hbrOld);
  1385. ReleaseDC(hwnd, hdc);
  1386. }
  1387. }
  1388. lRet = 0;
  1389. }
  1390. else
  1391. {
  1392. WNDPROC fpStaticWndProc = (WNDPROC) GetClassLongPtr(hwnd, GCLP_WNDPROC);
  1393. if (fpStaticWndProc)
  1394. {
  1395. lRet = CallWindowProc(fpStaticWndProc, hwnd, msg, wParam, lParam);
  1396. }
  1397. }
  1398. return lRet;
  1399. }
  1400. //---------------------------------------------------------------------------
  1401. //
  1402. // RedCarpetWndProc
  1403. //
  1404. //---------------------------------------------------------------------------
  1405. LRESULT CALLBACK RedCarpetWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1406. {
  1407. static HBRUSH hbr = NULL;
  1408. switch (msg)
  1409. {
  1410. case WM_CREATE:
  1411. {
  1412. HDC hdc;
  1413. hbr = (HBRUSH) GetStockObject( HOLLOW_BRUSH );
  1414. // The order of the following function matters, because some
  1415. // required global variables being initialized before it is
  1416. // called
  1417. SetFontCharSet();
  1418. SetFontColor(hwnd);
  1419. GetMyFontsFromFile();
  1420. CreateInfoBarFonts();
  1421. GetMyImagesFromFile(hwnd);
  1422. if (BufferBackground(hwnd) == FALSE)
  1423. {
  1424. return -1;
  1425. }
  1426. SetLayoutParams();
  1427. if (InitRealBillBoard(hwnd) == FALSE) {
  1428. return -1;
  1429. }
  1430. if (InitInfoBar(hwnd) == FALSE) {
  1431. return -1;
  1432. }
  1433. if (InitProgressBar(hwnd) == FALSE) {
  1434. return -1;
  1435. }
  1436. if (InitStatus(hwnd) == FALSE) {
  1437. return -1;
  1438. }
  1439. return 0;
  1440. }
  1441. case WM_DISPLAYCHANGE:
  1442. // NOTE: Only top level window can receive this message
  1443. // i.e. Assertion failure can't be caught if g_hwnd is not
  1444. // a top-level window
  1445. BB_ASSERT(FALSE);
  1446. break;
  1447. case WM_PAINT:
  1448. {
  1449. HDC hdc;
  1450. PAINTSTRUCT ps;
  1451. HDC hdcMem;
  1452. hdc = BeginPaint(hwnd, &ps);
  1453. if (hdc != NULL)
  1454. {
  1455. hdcMem = GetBackgroundBuffer();
  1456. BitBlt(hdc,
  1457. ps.rcPaint.left,
  1458. ps.rcPaint.top,
  1459. ps.rcPaint.right - ps.rcPaint.left,
  1460. ps.rcPaint.bottom - ps.rcPaint.top,
  1461. hdcMem,
  1462. ps.rcPaint.left,
  1463. ps.rcPaint.top,
  1464. SRCCOPY);
  1465. EndPaint(hwnd, &ps);
  1466. }
  1467. return(0);
  1468. }
  1469. case WM_CTLCOLORSTATIC:
  1470. {
  1471. HWND hwndChild;
  1472. HDC hdcChild;
  1473. hwndChild = (HWND) lParam;
  1474. hdcChild = (HDC) wParam;
  1475. SetTextColor(hdcChild, g_colInfoText);
  1476. SetBkMode( hdcChild, TRANSPARENT );
  1477. if (hwndChild == g_hwndTimeEstimate || hwndChild == g_hwndInfoText) {
  1478. SelectObject(hdcChild, g_hfontBold);
  1479. }
  1480. return (LRESULT)(HBRUSH)hbr;
  1481. }
  1482. case WM_DRAWITEM:
  1483. {
  1484. LPDRAWITEMSTRUCT pDi = (LPDRAWITEMSTRUCT) lParam;
  1485. RECT rc;
  1486. if (GetClientRect(pDi->hwndItem, &rc))
  1487. {
  1488. DrawTransparentBitmap(pDi->hDC,
  1489. g_hbmWinLogo,
  1490. rc.left,
  1491. rc.top,
  1492. g_colLogoTransparency);
  1493. }
  1494. return TRUE;
  1495. }
  1496. case WM_DESTROY:
  1497. if (GetBackgroundBuffer() != NULL)
  1498. {
  1499. DestroyBackgroundBuffer();
  1500. }
  1501. if (g_hbmWinLogo)
  1502. {
  1503. DeleteObject(g_hbmWinLogo);
  1504. g_hbmWinLogo = NULL;
  1505. }
  1506. hbr = NULL;
  1507. break;
  1508. default:
  1509. return DefWindowProc(hwnd, msg, wParam, lParam);
  1510. }
  1511. return 0;
  1512. }
  1513. LRESULT CALLBACK BillBoardWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1514. {
  1515. static BOOL fTimerOn = FALSE;
  1516. static BOOL fAnimate = FALSE;
  1517. HDC hdc;
  1518. switch (msg)
  1519. {
  1520. case WM_CREATE:
  1521. {
  1522. hdc = GetDC(NULL);
  1523. g_nLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
  1524. ReleaseDC(NULL, hdc);
  1525. break;
  1526. }
  1527. case WM_PAINT:
  1528. {
  1529. PAINTSTRUCT ps;
  1530. hdc = BeginPaint(hwnd, &ps);
  1531. if (hdc)
  1532. {
  1533. HDC hdcBillboardMem;
  1534. if (fAnimate)
  1535. {
  1536. if (GetBillboardBuffer())
  1537. {
  1538. DestroyBillboardBuffer();
  1539. }
  1540. if (InitAnimate(hwnd, hdc))
  1541. {
  1542. BufferBillboard(hwnd, hdc);
  1543. }
  1544. fAnimate = FALSE;
  1545. }
  1546. hdcBillboardMem = GetBillboardBuffer();
  1547. if (hdcBillboardMem)
  1548. {
  1549. BitBlt(hdc,
  1550. ps.rcPaint.left,
  1551. ps.rcPaint.top,
  1552. ps.rcPaint.right - ps.rcPaint.left,
  1553. ps.rcPaint.bottom - ps.rcPaint.top,
  1554. hdcBillboardMem,
  1555. ps.rcPaint.left,
  1556. ps.rcPaint.top,
  1557. SRCCOPY);
  1558. }
  1559. }
  1560. EndPaint(hwnd, &ps);
  1561. return(0);
  1562. }
  1563. case WM_START_TIMER:
  1564. if (!fTimerOn)
  1565. {
  1566. if (g_uiLastAnimateIndex == (UINT)-1)
  1567. g_uiAnimateIndex = 0;
  1568. else
  1569. g_uiAnimateIndex = g_uiLastAnimateIndex;
  1570. if (SetTimer(hwnd, BILLBRD_TEXT_TIMERID, BB_TEXT_DISPLAY, NULL))
  1571. {
  1572. fTimerOn = TRUE;
  1573. fAnimate = TRUE;
  1574. ShowWindow(hwnd, SW_SHOW);
  1575. }
  1576. }
  1577. return fTimerOn;
  1578. case WM_STOP_TIMER:
  1579. if (fTimerOn)
  1580. {
  1581. fTimerOn = FALSE;
  1582. g_uiLastAnimateIndex = g_uiAnimateIndex;
  1583. g_uiAnimateIndex = (UINT)-1;
  1584. KillTimer(hwnd, BILLBRD_TEXT_TIMERID);
  1585. ShowWindow(hwnd, SW_HIDE);
  1586. }
  1587. return fTimerOn == FALSE;
  1588. case WM_TIMER:
  1589. {
  1590. AnimateNext();
  1591. fAnimate = TRUE;
  1592. InvalidateRect(hwnd, NULL, FALSE);
  1593. UpdateWindow(hwnd);
  1594. }
  1595. break;
  1596. case WM_DESTROY:
  1597. TerminateAnimate();
  1598. if (fTimerOn)
  1599. {
  1600. fTimerOn = FALSE;
  1601. g_uiLastAnimateIndex = g_uiAnimateIndex;
  1602. g_uiAnimateIndex = (UINT) -1;
  1603. KillTimer(hwnd, BILLBRD_TEXT_TIMERID);
  1604. }
  1605. if (GetBillboardBuffer() != NULL)
  1606. {
  1607. DestroyBillboardBuffer();
  1608. }
  1609. break;
  1610. default:
  1611. return DefWindowProc(hwnd, msg, wParam, lParam);
  1612. }
  1613. return 0;
  1614. }
  1615. LRESULT CALLBACK
  1616. AnimationWndProc(
  1617. HWND hwnd,
  1618. UINT msg,
  1619. WPARAM wParam,
  1620. LPARAM lParam
  1621. )
  1622. {
  1623. //
  1624. // Hardcoded animation properties
  1625. //
  1626. static const DWORD BitmapIds[][4] =
  1627. {
  1628. {
  1629. IDB_INTENSITY1_C16BIT,
  1630. IDB_INTENSITY2_C16BIT,
  1631. IDB_INTENSITY3_C16BIT,
  1632. IDB_INTENSITY4_C16BIT
  1633. },
  1634. {
  1635. IDB_INTENSITY1_C4BIT,
  1636. IDB_INTENSITY2_C4BIT,
  1637. IDB_INTENSITY3_C4BIT,
  1638. IDB_INTENSITY4_C4BIT
  1639. }
  1640. };
  1641. static const int OriginalBitmapSize = 9;
  1642. static BOOL fTimerOn = FALSE;
  1643. static HBITMAP Bitmaps[] = {NULL, NULL, NULL, NULL};
  1644. static const int NumBitmaps = sizeof(Bitmaps) / sizeof(HBITMAP);
  1645. static int BoxToFade = 0;
  1646. static int BoxBitmapIndex[] = {0, 0, 0, 0, 0};
  1647. static const int NumBoxes = sizeof(BoxBitmapIndex) / sizeof(DWORD);
  1648. static int BitmapSize = 0;
  1649. switch (msg)
  1650. {
  1651. case WM_CREATE:
  1652. {
  1653. int Set;
  1654. int i;
  1655. int Ret = 0;
  1656. HDC hdc;
  1657. hdc = GetDC(hwnd);
  1658. if (hdc != NULL)
  1659. {
  1660. Set = (GetDeviceCaps(hdc, BITSPIXEL) > 8) ? 0 : 1;
  1661. ReleaseDC(hwnd, hdc);
  1662. }
  1663. else
  1664. {
  1665. Set = 1;
  1666. }
  1667. //
  1668. // The bitmaps are designed for 640 x 480. We want to scale them by
  1669. // 80% of the ratio between the current screen with and 640
  1670. //
  1671. BitmapSize = OriginalBitmapSize * GetSystemMetrics(SM_CXSCREEN) * 8 / 6400;
  1672. for (i = 0; i < NumBitmaps; i++)
  1673. {
  1674. Bitmaps[i] = LoadImage(
  1675. g_hInstance,
  1676. MAKEINTRESOURCE(BitmapIds[Set][i]),
  1677. IMAGE_BITMAP,
  1678. BitmapSize,
  1679. BitmapSize,
  1680. LR_DEFAULTCOLOR);
  1681. if (!Bitmaps[i])
  1682. {
  1683. Ret = -1;
  1684. break;
  1685. }
  1686. }
  1687. if (Ret == 0)
  1688. {
  1689. int Width;
  1690. int Height;
  1691. BoxBitmapIndex[0] = NumBitmaps - 1;
  1692. for (i = 1; i < NumBoxes; i++)
  1693. {
  1694. BoxBitmapIndex[i] = 0;
  1695. }
  1696. BoxToFade = 0;
  1697. Width = BitmapSize * (NumBoxes * 2 - 1);
  1698. Height = BitmapSize;
  1699. MoveWindow(
  1700. hwnd,
  1701. GetSystemMetrics(SM_CXSCREEN) - g_cxSteps - Width,
  1702. g_cyBillBrd + g_cyBillBrdHeight + (g_cyBannerHeight - Height) / 2,
  1703. Width,
  1704. Height,
  1705. FALSE
  1706. );
  1707. }
  1708. else
  1709. {
  1710. int j;
  1711. for (j = 0; j < i; j++)
  1712. {
  1713. DeleteObject(Bitmaps[j]);
  1714. }
  1715. }
  1716. return Ret;
  1717. }
  1718. case WM_ERASEBKGND:
  1719. {
  1720. return OnEraseBkgnd(hwnd, wParam, lParam);
  1721. }
  1722. case WM_PAINT:
  1723. {
  1724. PAINTSTRUCT ps;
  1725. HDC hdc = NULL;
  1726. int i = 0;
  1727. hdc = BeginPaint(hwnd, &ps);
  1728. if (hdc != NULL)
  1729. {
  1730. for (i = 0; i < NumBoxes; i++)
  1731. {
  1732. DrawBitmap(
  1733. hdc,
  1734. Bitmaps[BoxBitmapIndex[i]],
  1735. i * (BitmapSize * 2),
  1736. 0
  1737. );
  1738. }
  1739. }
  1740. EndPaint(hwnd, &ps);
  1741. return(0);
  1742. }
  1743. case WM_START_TIMER:
  1744. if (!fTimerOn)
  1745. {
  1746. if (SetTimer(hwnd, WHISTLER_PROGRESS_TIMERID, BB_WHISTLER_MOVE, NULL))
  1747. {
  1748. fTimerOn = TRUE;
  1749. ShowWindow(hwnd, SW_SHOW);
  1750. }
  1751. }
  1752. return fTimerOn;
  1753. case WM_STOP_TIMER:
  1754. if (fTimerOn)
  1755. {
  1756. fTimerOn = FALSE;
  1757. KillTimer(hwnd, WHISTLER_PROGRESS_TIMERID);
  1758. ShowWindow(hwnd, SW_HIDE);
  1759. }
  1760. return fTimerOn == FALSE;
  1761. case WM_TIMER:
  1762. {
  1763. if (BoxBitmapIndex[BoxToFade] == 0)
  1764. {
  1765. BoxToFade = (BoxToFade + 1) % NumBoxes;
  1766. }
  1767. else
  1768. {
  1769. DWORD BoxToGrow = (BoxToFade + 1) % NumBoxes;
  1770. BoxBitmapIndex[BoxToFade]--;
  1771. BoxBitmapIndex[BoxToGrow]++;
  1772. }
  1773. InvalidateRect(hwnd, NULL, FALSE);
  1774. UpdateWindow(hwnd);
  1775. }
  1776. break;
  1777. case WM_DESTROY:
  1778. {
  1779. int i;
  1780. if (fTimerOn)
  1781. {
  1782. fTimerOn = FALSE;
  1783. KillTimer(hwnd, WHISTLER_PROGRESS_TIMERID);
  1784. }
  1785. for (i = 0; i < NumBitmaps; i++)
  1786. {
  1787. if (Bitmaps[i])
  1788. {
  1789. DeleteObject(Bitmaps[i]);
  1790. }
  1791. }
  1792. }
  1793. break;
  1794. default:
  1795. return DefWindowProc(hwnd, msg, wParam, lParam);
  1796. }
  1797. return 0;
  1798. }
  1799. //---------------------
  1800. // DLL export functions
  1801. //---------------------
  1802. BOOL WINAPI TermBillBoard()
  1803. {
  1804. BOOL b = TRUE;
  1805. if (g_hwnd)
  1806. {
  1807. if (!DestroyWindow(g_hwnd)) {
  1808. return FALSE;
  1809. }
  1810. g_hwnd = NULL;
  1811. b = UnregisterClass(g_szStepsClassName, g_hInstance);
  1812. b = b && UnregisterClass(g_szBillBoardClassName, g_hInstance);
  1813. b = b && UnregisterClass(g_cszClassName, g_hInstance);
  1814. b = b && UnregisterClass(g_szStatusClassName, g_hInstance);
  1815. }
  1816. return b;
  1817. }
  1818. BOOL WINAPI InitBillBoard(HWND hwndParent, LPCTSTR lpszPath, DWORD dwInstallType)
  1819. {
  1820. WNDCLASS wc;
  1821. HWND hwnd;
  1822. TCHAR Buffer[128];
  1823. if (dwInstallType <= sizeof(bb_text))
  1824. {
  1825. dwBBTextType = dwInstallType;
  1826. }
  1827. if (LoadString(g_hInstance, IDD_PANELCOUNT, (LPTSTR)Buffer, sizeof(Buffer)/sizeof(TCHAR)))
  1828. g_nPanelCount = MyAtoI((const TCHAR*)Buffer);
  1829. else
  1830. g_nPanelCount = 0;
  1831. g_nPanelCount++;
  1832. if (LoadString(g_hInstance, IDD_ANIMATION, (LPTSTR)Buffer, sizeof(Buffer)/sizeof(TCHAR)))
  1833. g_nAnimID = MyAtoI((const TCHAR*)Buffer);
  1834. else
  1835. g_nAnimID = 0;
  1836. if ((g_szPath[0] == '\0') && (lpszPath == NULL)) //can't go on without path
  1837. return FALSE;
  1838. if (hwndParent == NULL)
  1839. hwnd = GetDesktopWindow();
  1840. else
  1841. hwnd = hwndParent;
  1842. if(g_szPath[0] == '\0')
  1843. {
  1844. lstrcpy((LPTSTR)g_szPath, (LPCTSTR)lpszPath);
  1845. AddPath(g_szPath, TEXT("BILLBRD"));
  1846. lstrcpy(g_szFileName, g_szPath);
  1847. //append .ini filename to path
  1848. AddPath(g_szFileName, TEXT("winntbb.ini"));
  1849. }
  1850. wc.style = (UINT)CS_BYTEALIGNWINDOW;
  1851. wc.lpfnWndProc = (WNDPROC)RedCarpetWndProc;
  1852. wc.cbClsExtra = 0;
  1853. wc.cbWndExtra = 0;
  1854. wc.hInstance = g_hInstance;
  1855. wc.hIcon = LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_SETUP));
  1856. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1857. wc.hbrBackground = NULL;
  1858. wc.lpszMenuName = NULL;
  1859. wc.lpszClassName = g_cszClassName;
  1860. if (!RegisterClass (&wc))
  1861. return FALSE;
  1862. LoadString(g_hInstance,IDS_WINNT_SETUP,(LPTSTR)Buffer,sizeof(Buffer)/sizeof(TCHAR));
  1863. // If we have a parent, be a child window.
  1864. // If not be a main window.
  1865. g_hwnd = CreateWindow(
  1866. g_cszClassName,
  1867. (LPTSTR)Buffer,
  1868. (hwndParent ? WS_CHILD : WS_POPUP) | WS_CLIPCHILDREN,
  1869. 0,
  1870. 0,
  1871. GetSystemMetrics(SM_CXSCREEN),
  1872. GetSystemMetrics(SM_CYSCREEN),
  1873. hwnd,
  1874. NULL,
  1875. g_hInstance,
  1876. NULL );
  1877. if (g_hwnd == NULL)
  1878. {
  1879. UnregisterClass(g_cszClassName, g_hInstance);
  1880. return FALSE;
  1881. }
  1882. ShowWindow( g_hwnd, SW_SHOW );
  1883. UpdateWindow( g_hwnd );
  1884. g_hwndParent = hwnd;
  1885. return TRUE;
  1886. }
  1887. HWND WINAPI GetBBMainHwnd()
  1888. {
  1889. return g_hwnd;
  1890. }
  1891. HWND WINAPI GetBBHwnd()
  1892. {
  1893. return g_hwndBB;
  1894. }
  1895. BOOL WINAPI ShowPanel(int iPanel)
  1896. {
  1897. if (g_iCurPanel == iPanel)
  1898. return FALSE;
  1899. if ((iPanel >= 0) && (iPanel < g_nPanelCount))
  1900. {
  1901. if (g_hwndBB == NULL)
  1902. return(FALSE);
  1903. g_iCurPanel = iPanel;
  1904. }
  1905. else
  1906. {
  1907. if (g_hwnd)
  1908. {
  1909. DestroyWindow(g_hwnd);
  1910. g_hwnd = NULL;
  1911. g_iCurPanel = -1;
  1912. }
  1913. }
  1914. return(TRUE);
  1915. }
  1916. int WINAPI GetPanelCount()
  1917. {
  1918. return(g_nPanelCount);
  1919. }
  1920. void WINAPI BB_Refresh(void)
  1921. {
  1922. if(g_hwnd)
  1923. {
  1924. RedrawWindow(
  1925. g_hwnd,
  1926. NULL,
  1927. NULL,
  1928. RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_INVALIDATE);
  1929. }
  1930. }
  1931. BOOL WINAPI SetProgress(WORD wProgress)
  1932. {
  1933. if (wProgress == 0xffff)
  1934. {
  1935. // Kill the last panel...
  1936. return ShowPanel(wProgress);
  1937. }
  1938. else if (wProgress & 0x8000)
  1939. {
  1940. // Display a specific panel
  1941. return ShowPanel(wProgress & 0x7fff);
  1942. }
  1943. else
  1944. {
  1945. // Normal case of a percentage...
  1946. return ShowPanel((g_nPanelCount * wProgress)/100);
  1947. }
  1948. }
  1949. BOOL WINAPI StartBillBoard()
  1950. {
  1951. BOOL retval = FALSE;
  1952. if(g_hwnd && g_hwndBB)
  1953. {
  1954. retval = (BOOL) SendMessage(g_hwndBB, WM_START_TIMER, 0, 0L);
  1955. if (g_hwndStatus) {
  1956. SendMessage(g_hwndStatus, WM_START_TIMER, 0, 0L);
  1957. }
  1958. }
  1959. return retval;
  1960. }
  1961. BOOL WINAPI StopBillBoard()
  1962. {
  1963. BOOL retval = FALSE;
  1964. if(g_hwnd && g_hwndBB)
  1965. {
  1966. retval = (BOOL) SendMessage(g_hwndBB, WM_STOP_TIMER, 0, 0L);
  1967. if (g_hwndStatus) {
  1968. SendMessage(g_hwndStatus, WM_STOP_TIMER, 0, 0L);
  1969. }
  1970. }
  1971. return retval;
  1972. }
  1973. BOOL WINAPI ShowProgressGaugeWindow(UINT uiShow)
  1974. {
  1975. BOOL bRet;
  1976. if (uiShow == SW_HIDE)
  1977. {
  1978. bRet = ShowWindow(g_hwndProgressGauge, uiShow);
  1979. // If we hide the progress bar, reset the progress position
  1980. // OC manager does a PBM_SETRANGE, but does not call PBM_SETPOS
  1981. SendMessage(g_hwndProgressGauge, PBM_SETPOS, 0, 0);
  1982. }
  1983. else
  1984. {
  1985. bRet = ShowWindow(g_hwndProgressGauge, uiShow);
  1986. }
  1987. return bRet;
  1988. }
  1989. BOOL AdjustProgressTextWindow(HWND hwnd, LPCTSTR szText)
  1990. {
  1991. BOOL rc;
  1992. HDC hdc;
  1993. RECT rect;
  1994. RECT rect2;
  1995. LONG height1,height2,delta;
  1996. HFONT hFontOld = NULL;
  1997. // Use the original position to calc the new position
  1998. rect.top = g_rcProgressText.top;
  1999. rect.bottom = g_rcProgressText.bottom;
  2000. rect.left = g_rcProgressText.left;
  2001. rect.right = g_rcProgressText.right;
  2002. rect2.top = g_rcProgressText.top;
  2003. rect2.bottom = g_rcProgressText.bottom;
  2004. rect2.left = g_rcProgressText.left;
  2005. rect2.right = g_rcProgressText.right;
  2006. hdc = GetDC(hwnd);
  2007. if (hdc == NULL)
  2008. {
  2009. rc = FALSE;
  2010. }
  2011. else
  2012. {
  2013. // Select the font into the DC so that DrawText can calc the size correct.
  2014. hFontOld = SelectObject(hdc, g_hfont);
  2015. DrawText(hdc, szText, -1, &rect2, DT_CALCRECT|DT_EXTERNALLEADING|DT_WORDBREAK);
  2016. if(hFontOld)
  2017. {
  2018. SelectObject(hdc, hFontOld);
  2019. }
  2020. ReleaseDC(hwnd, hdc);
  2021. // Calc the new height for the string
  2022. height2 = rect2.bottom - rect2.top;
  2023. // get the old height
  2024. height1 = rect.bottom - rect.top;
  2025. // See how far we have to change the top of the rect.
  2026. delta = (height1 - height2);
  2027. rect.top += delta;
  2028. // If we would get above the original position, don't
  2029. if (rect.top < g_rcProgressText.top)
  2030. {
  2031. rect.top = g_rcProgressText.top;
  2032. }
  2033. // Since the privous window position could be different from the original, always move
  2034. // the window.
  2035. MoveWindow(hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,TRUE);
  2036. rc = TRUE;
  2037. }
  2038. return rc;
  2039. }
  2040. BOOL WINAPI SetProgressText(LPCTSTR szText)
  2041. {
  2042. TCHAR Empty[] = TEXT("");
  2043. if (g_hwndProgressText)
  2044. {
  2045. ShowWindow(g_hwndProgressText, SW_HIDE);
  2046. if (szText)
  2047. {
  2048. AdjustProgressTextWindow(g_hwndProgressText, szText);
  2049. SendMessage(g_hwndProgressText, WM_SETTEXT, 0, (LPARAM) szText);
  2050. }
  2051. else
  2052. {
  2053. SendMessage(g_hwndProgressText, WM_SETTEXT, 0, (LPARAM) Empty);
  2054. }
  2055. ShowWindow(g_hwndProgressText, SW_SHOW);
  2056. }
  2057. return TRUE;
  2058. }
  2059. LRESULT WINAPI ProgressGaugeMsg(UINT msg, WPARAM wparam, LPARAM lparam)
  2060. {
  2061. LRESULT lresult = 0;
  2062. if (g_hwndProgressGauge) {
  2063. lresult = (LRESULT) SendMessage(g_hwndProgressGauge, msg, wparam, lparam);
  2064. }
  2065. return lresult;
  2066. }
  2067. BOOL WINAPI SetTimeEstimate(LPCTSTR szText)
  2068. {
  2069. TCHAR Empty[] = TEXT("");
  2070. if (g_hwndTimeEstimate )
  2071. {
  2072. ShowWindow(g_hwndTimeEstimate, SW_HIDE);
  2073. if (szText)
  2074. {
  2075. SendMessage(g_hwndTimeEstimate , WM_SETTEXT, 0, (LPARAM) szText);
  2076. }
  2077. else
  2078. {
  2079. SendMessage(g_hwndTimeEstimate , WM_SETTEXT, 0, (LPARAM) Empty);
  2080. }
  2081. ShowWindow(g_hwndTimeEstimate, SW_SHOW);
  2082. }
  2083. return TRUE;
  2084. }
  2085. BOOL WINAPI SetStep(int iPanel)
  2086. {
  2087. BOOL rc = FALSE;
  2088. if (g_hwndSteps)
  2089. {
  2090. rc = (BOOL) SendMessage(g_hwndSteps, WM_SETSTEP, 0, (LPARAM) iPanel);
  2091. }
  2092. return rc;
  2093. }
  2094. BOOL WINAPI SetInfoText(LPCTSTR szText)
  2095. {
  2096. TCHAR Empty[] = TEXT("");
  2097. if (g_hwndInfoText)
  2098. {
  2099. ShowWindow(g_hwndInfoText, SW_HIDE);
  2100. if (szText)
  2101. {
  2102. SendMessage(g_hwndInfoText, WM_SETTEXT, 0, (LPARAM) szText);
  2103. }
  2104. else
  2105. {
  2106. SendMessage(g_hwndInfoText, WM_SETTEXT, 0, (LPARAM) Empty);
  2107. }
  2108. ShowWindow(g_hwndInfoText, SW_SHOW);
  2109. }
  2110. return TRUE;
  2111. }