00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Wnd_Banner.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 #define IMGT_LOAD 1
00017
00018 #define IMGT_DRAW 2
00019
00020 #define IMGT_EXIT 4
00021
00022 CWnd_Banner::CWnd_Banner()
00023 {
00024 m_dwThrJob = 0;
00025 m_bRunning = FALSE;
00026 }
00027
00028 CWnd_Banner::~CWnd_Banner()
00029 {
00030 Shutdown ();
00031 }
00032
00033 BEGIN_MESSAGE_MAP(CWnd_Banner, CWnd)
00034
00035 ON_WM_PAINT()
00036 ON_WM_LBUTTONDOWN()
00037 ON_WM_TIMER()
00038 ON_WM_LBUTTONUP()
00039
00040 END_MESSAGE_MAP()
00041
00042 BOOL CWnd_Banner::Create(CWnd *pWndParent, int cy)
00043 {
00044 CWnd::Create (
00045 AfxRegisterWndClass (0, LoadCursor (AfxGetInstanceHandle (),
00046 MAKEINTRESOURCE (IDC_HAND_)),
00047 (HBRUSH)(COLOR_3DFACE+1), NULL),
00048 "", WS_CHILD|WS_VISIBLE,
00049 CRect (0, 0, 300, cy), pWndParent, 0);
00050
00051 Initialize ();
00052 return TRUE;
00053 }
00054
00055 void CWnd_Banner::OnPaint()
00056 {
00057 CPaintDC dc(this);
00058
00059 m_hDCNow = dc;
00060 m_dwThrJob |= IMGT_DRAW;
00061 while (m_dwThrJob & IMGT_DRAW)
00062 Sleep (10);
00063 }
00064
00065 void CWnd_Banner::SetBanner(LPCSTR pszFile, LPCSTR pszURL)
00066 {
00067 LOG ("CWB: SB: enter" << nl);
00068
00069 KillTimer (1);
00070
00071 if (m_bRunning == FALSE)
00072 Initialize ();
00073
00074 m_strImgFile = pszFile;
00075 m_strURL = pszURL;
00076
00077 LOG ("CWB: SB: load..." << nl);
00078
00079 m_dwThrJob |= IMGT_LOAD;
00080 while (m_dwThrJob & IMGT_LOAD)
00081 Sleep (10);
00082
00083 SetWindowPos (NULL, 0, 0, m_img.get_Size ().cx, m_img.get_Size ().cy, SWP_NOMOVE|SWP_NOZORDER);
00084
00085 if (m_img.get_FrameCount ())
00086 {
00087 m_iCurrentFrame = 0;
00088
00089 SetTimer (1, m_img.get_FrameDelay (0) * 10, NULL);
00090 }
00091
00092 Invalidate ();
00093
00094 LOG ("CWB: SB: done." << nl);
00095 }
00096
00097 DWORD WINAPI CWnd_Banner::_threadImage(LPVOID lp)
00098 {
00099 CoInitialize (NULL);
00100 CWnd_Banner* pThis = (CWnd_Banner*) lp;
00101
00102 pThis->m_bRunning = TRUE;
00103
00104 while ((pThis->m_dwThrJob & IMGT_EXIT) == 0)
00105 {
00106
00107 if (pThis->m_dwThrJob & IMGT_LOAD)
00108 {
00109 pThis->m_img.Load (pThis->m_strImgFile);
00110 pThis->m_dwThrJob &= ~IMGT_LOAD;
00111 }
00112
00113
00114 if (pThis->m_dwThrJob & IMGT_DRAW)
00115 {
00116 if (pThis->m_img.is_Loaded ())
00117 {
00118 CRect rc;
00119 pThis->GetClientRect (&rc);
00120 CSize size = pThis->m_img.get_Size ();
00121
00122
00123
00124 rc.bottom = size.cy;
00125
00126 if (rc.Width () <= size.cx)
00127 {
00128 rc.right = size.cx;
00129 }
00130 else
00131 {
00132 int w = (rc.Width () - size.cx) / 2;
00133 rc.left = w;
00134 rc.right = w + size.cx;
00135 }
00136
00137 pThis->m_img.Draw (pThis->m_hDCNow, rc);
00138 }
00139
00140 pThis->m_dwThrJob &= ~IMGT_DRAW;
00141 }
00142
00143 Sleep (50);
00144 }
00145
00146 LOG ("releasing img...");
00147
00148 pThis->m_img.Free ();
00149
00150 LOG ("ok." << nl);
00151
00152 pThis->m_bRunning = FALSE;
00153 pThis->m_dwThrJob &= ~IMGT_EXIT;
00154
00155 CoUninitialize ();
00156
00157 return 0;
00158 }
00159
00160 void CWnd_Banner::OnLButtonDown(UINT nFlags, CPoint point)
00161 {
00162
00163 CWnd::OnLButtonDown(nFlags, point);
00164 }
00165
00166 void CWnd_Banner::Shutdown()
00167 {
00168 if (m_bRunning)
00169 {
00170 m_dwThrJob = IMGT_EXIT;
00171 while (m_dwThrJob & IMGT_EXIT)
00172 Sleep (10);
00173 }
00174 }
00175
00176 void CWnd_Banner::Initialize()
00177 {
00178 if (m_bRunning == FALSE)
00179 {
00180 DWORD dw;
00181 m_bRunning = TRUE;
00182 CreateThread (NULL, 0, _threadImage, this, 0, &dw);
00183 }
00184 }
00185
00186 void CWnd_Banner::OnTimer(UINT nIDEvent)
00187 {
00188 if (m_iCurrentFrame == m_img.get_FrameCount ())
00189 m_iCurrentFrame = 0;
00190
00191
00192 KillTimer (1);
00193 SetTimer (1, m_img.get_FrameDelay (m_iCurrentFrame) * 10, NULL);
00194
00195 m_img.set_CurrentFrame (m_iCurrentFrame++);
00196
00197 CDC* dc = GetDC ();
00198 m_hDCNow = *dc;
00199 m_dwThrJob |= IMGT_DRAW;
00200 while (m_dwThrJob & IMGT_DRAW)
00201 Sleep (10);
00202 ReleaseDC (dc);
00203
00204 CWnd::OnTimer(nIDEvent);
00205 }
00206
00207 void CWnd_Banner::OnLButtonUp(UINT nFlags, CPoint point)
00208 {
00209 fsOpenUrlInBrowser (m_strURL);
00210 CWnd::OnLButtonUp(nFlags, point);
00211 }