Splash.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:3k
源码类别:

远程控制编程

开发平台:

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