SPLASH.CPP
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:5k
源码类别:

SNMP编程

开发平台:

MultiPlatform

  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 "MemDC.h"  // e.g. 
  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. {
  41. c_pSplashWnd->DestroyWindow();
  42. }
  43. // Allocate a new splash screen, and create the window.
  44. c_pSplashWnd = new CSplashWnd;
  45. if (!c_pSplashWnd->Create(pParentWnd))
  46. delete c_pSplashWnd;
  47. else
  48. {
  49. c_pSplashWnd->UpdateWindow();
  50. }
  51. }
  52. BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
  53. {
  54. if (c_pSplashWnd == NULL)
  55. return FALSE;
  56. // If we get a keyboard or mouse message, hide the splash screen.
  57. if (pMsg->message == WM_KEYDOWN ||
  58.     pMsg->message == WM_SYSKEYDOWN ||
  59.     pMsg->message == WM_LBUTTONDOWN ||
  60.     pMsg->message == WM_RBUTTONDOWN ||
  61.     pMsg->message == WM_MBUTTONDOWN ||
  62.     pMsg->message == WM_NCLBUTTONDOWN ||
  63.     pMsg->message == WM_NCRBUTTONDOWN ||
  64.     pMsg->message == WM_NCMBUTTONDOWN)
  65. {
  66. c_pSplashWnd->HideSplashScreen();
  67. return TRUE; // message handled here
  68. }
  69. return FALSE; // message not handled
  70. }
  71. BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
  72. {
  73. imageList.Load("splash.bmp", 1, RGB(255,0,255));
  74. // if (!m_bitmap.LoadBitmap(IDB_SPLASH))
  75. // return FALSE;
  76. // BITMAP bm;
  77. // m_bitmap.GetBitmap(&bm);
  78. if(CreateEx(0,
  79. AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
  80. NULL, WS_POPUP | WS_VISIBLE, 0, 0, imageList.m_nEveryCx, imageList.m_nEveryCy,
  81. pParentWnd->GetSafeHwnd(), NULL)
  82.  == FALSE)
  83.  return FALSE;
  84. // CRgn rgn;
  85. // BOOL bRegRet = rgn.CreateEllipticRgn(0, 0, imageList.m_nEveryCx, imageList.m_nEveryCy);
  86. // SetWindowRgn(rgn.operator HRGN( ), FALSE);
  87. return TRUE;
  88. }
  89. void CSplashWnd::HideSplashScreen()
  90. {
  91. // Destroy the window, and update the mainframe.
  92. DestroyWindow();
  93. CWnd * pWnd = AfxGetMainWnd();
  94. if(pWnd && ::IsWindow(pWnd->m_hWnd))
  95. pWnd->UpdateWindow();
  96. }
  97. void CSplashWnd::PostNcDestroy()
  98. {
  99. // Free the C++ class.
  100. delete this;
  101. }
  102. int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  103. {
  104. if (CWnd::OnCreate(lpCreateStruct) == -1)
  105. return -1;
  106. m_wndAnimate.Create(WS_CHILD|WS_VISIBLE,CRect(0,40,100,100),this,-1);
  107. BOOL q = m_wndAnimate.Open(IDR_VC6);
  108. m_wndAnimate.Play(0,-1,-1);
  109. // Center the window.
  110. CenterWindow();
  111. // Set a timer to destroy the splash screen.
  112. SetTimer(1, 5000, NULL);
  113. return 0;
  114. }
  115. void CSplashWnd::OnPaint()
  116. {
  117. CPaintDC dc(this);
  118. /* CRect rect;
  119. GetClientRect(rect);
  120. dc.SetBkColor(::GetSysColor(COLOR_3DHIGHLIGHT));
  121. dc.ExtTextOut(0,0,ETO_OPAQUE,rect,NULL,0,NULL);
  122. CRgn rgn;
  123. BOOL bRegRet = rgn.CreateEllipticRgn(0, 0, imageList.m_nEveryCx, imageList.m_nEveryCy);
  124. dc.FillRgn( &rgn, &CBrush(::GetSysColor(COLOR_3DHIGHLIGHT)));
  125. */
  126. /* CDC dcImage;
  127. if (!dcImage.CreateCompatibleDC(&dc))
  128. return;
  129. BITMAP bm;
  130. m_bitmap.GetBitmap(&bm);
  131. // Paint the image.
  132. CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
  133. dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
  134. dcImage.SelectObject(pOldBitmap);
  135. */
  136. CRect rect;
  137. GetClientRect(rect);
  138. // CStretchDC dcEx(&dc,CRect(0,0,imageList.m_nEveryCx, imageList.m_nEveryCy),rect);
  139. imageList.Draw(&dc,0,CPoint(0,0),ILD_TRANSPARENT);
  140. dc.SetBkMode(TRANSPARENT);
  141. dc.SetTextColor(RGB(0,255,255));
  142. dc.SelectObject(&m_fontSys);
  143. dc.TextOut(10,10,m_strHint);
  144. }
  145. void CSplashWnd::OnTimer(UINT nIDEvent)
  146. {
  147. // Destroy the splash screen window.
  148. HideSplashScreen();
  149. }
  150. void CSplashWnd::ShowHint(LPCSTR strShow)
  151. {
  152. if (!c_bShowSplashWnd || c_pSplashWnd == NULL)
  153. {
  154. CSplashWnd::ShowSplashScreen(NULL);
  155. if (!c_bShowSplashWnd || c_pSplashWnd == NULL)
  156. return;
  157. }
  158. c_pSplashWnd->m_strHint = strShow;
  159. c_pSplashWnd->RedrawWindow(CRect(10,10,400,30));
  160. }
  161. BOOL CSplashWnd::IsExistence()
  162. {
  163. return (c_pSplashWnd != NULL);
  164. }