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.

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