FlashControl.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include "stdafx.h"
  2. #include "FlashControl.h"
  3. /////////////////////////////////////////////////////////////////////////////
  4. // ShockwaveFlash
  5. IMPLEMENT_DYNCREATE(CFlashControl, CWnd)
  6. long CFlashControl::s_lCount = 0;
  7. CFlashControl::CFlashControl()
  8. {
  9. #if 0
  10. if (0 == InterlockedExchangeAdd((volatile long *)&s_lCount, 1))
  11. {
  12. TCHAR szWorkDirectory[MAX_PATH]={0};
  13. RenderEngine->GetWorkDirectory(szWorkDirectory,MAX_PATH);
  14. StrCat(szWorkDirectory,TEXT("\\Flash8.ocx"));
  15. HMODULE hmod=LoadLibrary (szWorkDirectory);
  16. ASSERT(hmod);
  17. if (hmod)
  18. {
  19. FARPROC pReg =GetProcAddress (hmod,"DllRegisterServer");
  20. (*pReg)();
  21. }
  22. }
  23. #endif
  24. m_bHasInit = FALSE;
  25. m_lOldProc = 0;
  26. m_pIFlashContrlSink = NULL;
  27. }
  28. CFlashControl::~CFlashControl()
  29. {
  30. #if 0
  31. if (1 == InterlockedExchangeAdd((volatile long *)&s_lCount, -1))
  32. {
  33. TCHAR szWorkDirectory[MAX_PATH]={0};
  34. RenderEngine->GetWorkDirectory(szWorkDirectory,MAX_PATH);
  35. StrCat(szWorkDirectory,TEXT("\\Flash8.ocx"));
  36. HMODULE hmod=LoadLibrary (szWorkDirectory);
  37. ASSERT(hmod);
  38. if (hmod)
  39. {
  40. FARPROC pReg =GetProcAddress (hmod,"DllUnregisterServer");
  41. (*pReg)();
  42. }
  43. }
  44. #endif
  45. }
  46. LRESULT CFlashControl::FlashWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  47. {
  48. CFlashControl *pFlashCtrl = (CFlashControl *)FromHandle(hWnd);
  49. ASSERT(pFlashCtrl);
  50. switch ( msg )
  51. {
  52. case WM_ERASEBKGND:
  53. {
  54. return TRUE;
  55. }
  56. case WM_PAINT:
  57. {
  58. if ( pFlashCtrl->m_pIFlashContrlSink != NULL )
  59. {
  60. CDC*pDC = pFlashCtrl->GetDC();
  61. CRect rcClient;
  62. pFlashCtrl->GetClientRect(&rcClient);
  63. pFlashCtrl->m_pIFlashContrlSink->OnDraw(pDC,rcClient.Width(),rcClient.Height());
  64. pFlashCtrl->ReleaseDC(pDC);
  65. }
  66. return 0;
  67. return CallWindowProc((WNDPROC)(pFlashCtrl->m_lOldProc), hWnd, msg, wParam, lParam);
  68. }
  69. case WM_RBUTTONDOWN:
  70. return 0;
  71. case WM_LBUTTONDOWN:
  72. {
  73. HWND hParentWnd = ::GetParent(hWnd);
  74. if ( hParentWnd != NULL )
  75. {
  76. UINT uID = pFlashCtrl->GetDlgCtrlID();
  77. ::PostMessage(hParentWnd,WM_COMMAND,uID,0);
  78. }
  79. break;
  80. }
  81. }
  82. if ( msg == 144 || msg == 8720 || msg == 24 || msg == 2 || msg == 130)
  83. {
  84. return 0;
  85. }
  86. //调用原来的窗口过程
  87. return CallWindowProc((WNDPROC)(pFlashCtrl->m_lOldProc), hWnd, msg, wParam, lParam);
  88. }
  89. BOOL CFlashControl::Init(IFlashContrlSink*pIFlashContrlSink)
  90. {
  91. if (FALSE == m_bHasInit)
  92. {
  93. m_lOldProc = SetWindowLong(m_hWnd, GWL_WNDPROC, (long)FlashWinProc);
  94. }
  95. m_pIFlashContrlSink = pIFlashContrlSink;
  96. m_bHasInit = TRUE;
  97. return TRUE;
  98. }
  99. BOOL CFlashControl::CreateControl( CWnd* pParentWnd )
  100. {
  101. if( !Create(NULL,WS_VISIBLE|WS_VISIBLE,CRect(0,0,0,0),pParentWnd,0) )
  102. return FALSE;
  103. m_pOwnWnd = this;
  104. return TRUE;
  105. }
  106. void CFlashControl::SetAttribute( LPCTSTR pstrName, LPCTSTR pstrValue )
  107. {
  108. ISkinControl::SetAttribute(pstrName,pstrValue);
  109. if( _tcscmp(pstrName, _T("path")) == 0 )
  110. {
  111. TCHAR szWorkDirectory[MAX_PATH]={0};
  112. RenderEngine->GetWorkDirectory(szWorkDirectory,MAX_PATH);
  113. StrCat(szWorkDirectory,TEXT("\\"));
  114. StrCat(szWorkDirectory,pstrValue);
  115. LoadMovie(0,szWorkDirectory);
  116. Play();
  117. }
  118. else if( _tcscmp(pstrName, _T("transparent")) == 0 )
  119. {
  120. if( _tcscmp(pstrValue, _T("true")) == 0 )
  121. put_WMode( _bstr_t(_T("Transparent") ) );
  122. }
  123. else if( _tcscmp(pstrName, _T("pos")) == 0 )
  124. {
  125. //TODO:必须初始化就先设置位置,否则不显示flash,原因没查
  126. tagPositionData _PositionData;
  127. LPTSTR pstr = NULL;
  128. _PositionData.nFixedPostion[0] = _tcstol(pstrValue, &pstr, 10); ASSERT(pstr);
  129. _PositionData.nFixedPostion[1] = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  130. _PositionData.ptPosition.x = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  131. _PositionData.ptPosition.y = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  132. _PositionData.szSize.cx = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  133. _PositionData.szSize.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  134. CRect rc;
  135. RenderEngine->GetRect(GetParent()->GetSafeHwnd(),&_PositionData,rc);
  136. SetWindowPos(NULL,rc.left,rc.top,rc.Width(),rc.Height(),SWP_NOACTIVATE);
  137. }
  138. }