Splash.cpp
上传用户:deligs
上传日期:2007-01-08
资源大小:43k
文件大小:3k
源码类别:

网络编程

开发平台:

Visual C++

  1. // CG: This file was added by the Splash Screen component.
  2. // Splash.cpp : implementation file
  3. //
  4. #include "stdafx.h"  // e. g. stdafx.h
  5. #include "resource.h"  // e.g. resource.h
  6. #include "Splash.h"  // e.g. splash.h
  7. #include "mainfrm.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. return TRUE; // message handled here
  64. }
  65. return FALSE; // message not handled
  66. }
  67. BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
  68. {
  69. if (!m_bitmap.LoadBitmap(IDB_SPLASH))
  70. return FALSE;
  71. BITMAP bm;
  72. m_bitmap.GetBitmap(&bm);
  73. return CreateEx(0,
  74. AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
  75. NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
  76. }
  77. void CSplashWnd::HideSplashScreen()
  78. {
  79. // Destroy the window, and update the mainframe.
  80. DestroyWindow();
  81. AfxGetMainWnd()->UpdateWindow();
  82. }
  83. void CSplashWnd::PostNcDestroy()
  84. {
  85. // Free the C++ class.
  86. delete this;
  87. }
  88. int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  89. {
  90. if (CWnd::OnCreate(lpCreateStruct) == -1)
  91. return -1;
  92. // Center the window.
  93. CenterWindow();
  94. // Set a timer to destroy the splash screen.
  95. SetTimer(TIMER_ID_SPLASH, PERIOD_LOGO, NULL);
  96. return 0;
  97. }
  98. void CSplashWnd::OnPaint()
  99. {
  100. CPaintDC dc(this);
  101. CDC dcImage;
  102. if (!dcImage.CreateCompatibleDC(&dc))
  103. return;
  104. BITMAP bm;
  105. m_bitmap.GetBitmap(&bm);
  106. // Paint the image.
  107. CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
  108. dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
  109. dcImage.SelectObject(pOldBitmap);
  110. }
  111. void CSplashWnd::OnTimer(UINT nIDEvent)
  112. {
  113. // Destroy the splash screen window.
  114. switch (nIDEvent)
  115. {
  116. case TIMER_ID_SPLASH :
  117. KillTimer(TIMER_ID_SPLASH);
  118. HideSplashScreen();
  119. break;
  120. default :
  121. break;
  122. }
  123. }