Splash.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. // CG: This file was added by the Splash Screen component.
  2. // Splash2.cpp : implementation file
  3. //
  4. #include "stdafx.h"  // e. g. stdafx.h
  5. #include "resource.h"  // e.g. resource.h
  6. #include "Splash.h"
  7. #include "WizardDlg.h" // e.g. splash.h
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. //   Splash Screen class
  15. BOOL CSplashWnd::c_bShowSplashWnd;
  16. CSplashWnd* CSplashWnd::c_pSplashWnd;
  17. CSplashWnd::CSplashWnd()
  18. {
  19. }
  20. CSplashWnd::~CSplashWnd()
  21. {
  22. // Clear the static window pointer.
  23. ASSERT(c_pSplashWnd == this);
  24. c_pSplashWnd = NULL;
  25. }
  26. BEGIN_MESSAGE_MAP(CSplashWnd, CWnd)
  27. //{{AFX_MSG_MAP(CSplashWnd)
  28. ON_WM_CREATE()
  29. ON_WM_PAINT()
  30. ON_WM_TIMER()
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. void CSplashWnd::EnableSplashScreen(BOOL bEnable /*= TRUE*/)
  34. {
  35. c_bShowSplashWnd = bEnable;
  36. }
  37. void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd /*= NULL*/)
  38. {
  39. if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
  40. return;
  41. // Allocate a new splash screen, and create the window.
  42. c_pSplashWnd = new CSplashWnd;
  43. if (!c_pSplashWnd->Create(pParentWnd))
  44. delete c_pSplashWnd;
  45. else
  46. c_pSplashWnd->UpdateWindow();
  47. }
  48. BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
  49. {
  50. if (c_pSplashWnd == NULL)
  51. return FALSE;
  52. // If we get a keyboard or mouse message, hide the splash screen.
  53. if (pMsg->message == WM_KEYDOWN ||
  54.     pMsg->message == WM_SYSKEYDOWN ||
  55.     pMsg->message == WM_LBUTTONDOWN ||
  56.     pMsg->message == WM_RBUTTONDOWN ||
  57.     pMsg->message == WM_MBUTTONDOWN ||
  58.     pMsg->message == WM_NCLBUTTONDOWN ||
  59.     pMsg->message == WM_NCRBUTTONDOWN ||
  60.     pMsg->message == WM_NCMBUTTONDOWN)
  61. {
  62. c_pSplashWnd->HideSplashScreen();
  63.        
  64. return TRUE; // message handled here
  65. }
  66. return FALSE; // message not handled
  67. }
  68. BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
  69. {
  70. if (!m_bitmap.LoadBitmap(IDB_SPLASH))
  71. return FALSE;
  72. BITMAP bm;
  73. m_bitmap.GetBitmap(&bm);
  74. return CreateEx(0,
  75. AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
  76. NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
  77. }
  78. void CSplashWnd::HideSplashScreen()
  79. {
  80. // Destroy the window, and update the mainframe.
  81. DestroyWindow();
  82. AfxGetMainWnd()->UpdateWindow();
  83.     CWizardDlg dlg;
  84.     dlg.DoModal();
  85. }
  86. void CSplashWnd::PostNcDestroy()
  87. {
  88. // Free the C++ class.
  89. delete this;
  90. }
  91. int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  92. {
  93. if (CWnd::OnCreate(lpCreateStruct) == -1)
  94. return -1;
  95. // Center the window.
  96. CenterWindow();
  97. // Set a timer to destroy the splash screen.
  98. SetTimer(1, 10000, NULL);
  99. return 0;
  100. }
  101. void CSplashWnd::OnPaint()
  102. {
  103. CPaintDC dc(this);
  104. CDC dcImage;
  105. if (!dcImage.CreateCompatibleDC(&dc))
  106. return;
  107. BITMAP bm;
  108. m_bitmap.GetBitmap(&bm);
  109. // Paint the image.
  110. CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
  111. dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
  112. dcImage.SelectObject(pOldBitmap);
  113. }
  114. void CSplashWnd::OnTimer(UINT nIDEvent)
  115. {
  116. // Destroy the splash screen window.
  117.     
  118. HideSplashScreen();
  119. }