// MyAnimateWindow.cpp : implementation file // #include "stdafx.h" #include "LYFZIPManage.h" #include "MyAnimateWindow.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // MyAnimateWindow dialog bool SleepEx( DWORD dwMilliseconds ) { if( dwMilliseconds == 0 ) return TRUE; DWORD t1 = GetTickCount(); while(1) { DWORD t2 = GetTickCount(); if( t2 < t1 || (t2 - t1) > dwMilliseconds )break; MSG msg; if( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) ) { GetMessage( &msg, NULL, 0, 0 ); TranslateMessage(&msg); DispatchMessage(&msg); } else { Sleep(1); } } return TRUE; } //--------------------------------------------------- //from leftbottom to righttop //------------------------------------------------- bool MyAnimateWindow::MagicFun20( Image *hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep) { try { int nSize = nStep; int Max = width>height?width:height; Graphics graph(hDestDC); while( nSize < Max ) { if(m_bTerminate3)return 1; int nX = x+width-nSize; int nY = nSize; if( nX < 0 ) nX = 0; if( nY > height ) nY = height; // Rect desRect(xd , yd+height-nY , min(width,nSize) ,min(width,nSize)*height/width); Rect desRect(xd , yd+height-nY , min(width,nSize) ,min(width,nSize)*height/width); graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel); SleepEx( nDelay ); nSize += nStep; } if(m_bTerminate3)return 1; Rect desRect(xd , yd , width , height); graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel); return TRUE; } catch(...) { } } bool MyAnimateWindow::MagicFun16( Image *hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep ) { try { Graphics graph(hDestDC); for( int i=0; i< width/nStep; i++ ) { if(m_bTerminate2)return 1; Rect desRect(xd+width-(i+1)*nStep , yd , (i+1)*nStep , height); graph.DrawImage(hSrcDC, desRect, x , y , (i+1)*nStep, hSrcDC->GetHeight() ,UnitPixel); SleepEx( nDelay ); } if(m_bTerminate2)return 1; Rect desRect(xd , yd , width , height); graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel); /* ·­Κι Graphics graph(hDestDC); for( int i=0; i< width/nStep; i++ ) { Rect desRect(xd+width-(i+1)*nStep , yd , (i+1)*nStep , height); graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel); SleepEx( nDelay ); } Rect desRect(xd , yd , width , height); graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel); */ return TRUE; } catch(...) { } } MyAnimateWindow::MyAnimateWindow(CWnd* pParent /*=NULL*/) : CDialog(MyAnimateWindow::IDD, pParent) { //{{AFX_DATA_INIT(MyAnimateWindow) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_pImg=NULL; m_mode=-1; m_mode2=-1; m_time=3000; m_effect=1; m_bTerminate=false; m_bRunning=false; m_hThread = NULL; m_bTerminate2=false; m_bRunning2=false; m_hThread2 = NULL; m_bTerminate3=false; m_bRunning3=false; m_hThread3 = NULL; } void MyAnimateWindow::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(MyAnimateWindow) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(MyAnimateWindow, CDialog) //{{AFX_MSG_MAP(MyAnimateWindow) ON_WM_ERASEBKGND() ON_WM_PAINT() ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // MyAnimateWindow message handlers BOOL MyAnimateWindow::OnEraseBkgnd(CDC* pDC) { try { // TODO: Add your message handler code here and/or call default if(m_pImg==NULL) return 1; // TODO: Add your message handler code here if(m_effect==1 || m_effect==2) { CRect rc; GetClientRect(rc); Graphics graph(m_pbmp); graph.Clear(Color(255,0,0,0)); Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ()); graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel); Graphics graph2(pDC->GetSafeHdc ()); graph2.DrawImage(m_pbmp,0,0); } return 1; } catch(...) { } } void MyAnimateWindow::OnOK() { // TODO: Add extra validation here } void MyAnimateWindow::OnCancel() { // TODO: Add extra cleanup here } BOOL MyAnimateWindow::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void MyAnimateWindow::OnPaint() { CPaintDC dc(this); // device context for painting if(m_pImg==NULL) return; // TODO: Add your message handler code here if(m_effect==0) { /* Graphics graph(m_pbmp); graph.Clear(Color(255,0,0,0)); Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ()); graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel); Graphics graph2(dc.GetSafeHdc ()); graph2.DrawImage(m_pbmp,0,0);*/ try { if(m_rcneedclear.IsRectEmpty ()) GetClientRect(m_rcneedclear); CDC *pDC=&dc; CRect rc,rc2; rc.IntersectRect(m_pRc, m_rcneedclear); rc2.left =m_rcneedclear.left ; rc2.top =rc.top ; rc2.right =rc.left ; rc2.bottom =rc.bottom ; pDC->FillSolidRect (rc2, 0); rc2.left =rc.right ; rc2.top =rc.top ; rc2.right =m_rcneedclear.right ; rc2.bottom =rc.bottom ; pDC->FillSolidRect (rc2, 0); rc2.left =rc.left ; rc2.top =m_rcneedclear.top ; rc2.right =rc.right ; rc2.bottom =rc.top ; pDC->FillSolidRect (rc2, 0); rc2.left =rc.left ; rc2.top =rc.bottom ; rc2.right =rc.right ; rc2.bottom =m_rcneedclear.bottom ; pDC->FillSolidRect (rc2, 0); m_rcneedclear=*m_pRc; Graphics graph(dc.GetSafeHdc ()); graph.Clear(Color(255,0,0,0)); Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ()); graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel); } catch(...) { } } // Do not call CDialog::OnPaint() for painting messages } void MyAnimateWindow::SetImage(Image *img) { m_pImg=img; } void MyAnimateWindow::MyExit() { AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE); } unsigned __stdcall DrawEffect1Thread(LPVOID lpParam) { try { MyAnimateWindow *pThis=(MyAnimateWindow*)lpParam; CDC *pDC=pThis->GetDC(); pThis->DrawEffect1(pDC); pThis->ReleaseDC(pDC); if(pThis->m_bTerminate==0) pThis->m_pParent->SetTimer(1, 1, NULL); pThis->m_bRunning=false; pThis->m_bTerminate=false; return 0; } catch(...) { } } unsigned __stdcall DrawEffect2Thread(LPVOID lpParam) { try { MyAnimateWindow *pThis=(MyAnimateWindow*)lpParam; CDC *pDC=pThis->GetDC(); pThis->ShowWindow(SW_SHOW); CRect rc; pThis->GetClientRect(rc); pDC->FillSolidRect (rc,0); if(pThis->m_time<2000) pThis->MagicFun16( pThis->m_pImg , 0 , 0 , pDC->GetSafeHdc() , pThis->m_pRc->left , pThis->m_pRc->top , pThis->m_pRc->Width (), pThis->m_pRc->Height () , 1, pThis->m_pRc->Width ()/12 ); else if(pThis->m_time<3000) pThis->MagicFun16( pThis->m_pImg , 0 , 0 , pDC->GetSafeHdc() , pThis->m_pRc->left , pThis->m_pRc->top , pThis->m_pRc->Width (), pThis->m_pRc->Height () , 1, pThis->m_pRc->Width ()/18 ); else pThis->MagicFun16( pThis->m_pImg , 0 , 0 , pDC->GetSafeHdc() , pThis->m_pRc->left , pThis->m_pRc->top , pThis->m_pRc->Width (), pThis->m_pRc->Height () , 1, pThis->m_pRc->Width ()/25 ); pThis->ReleaseDC(pDC); if(pThis->m_bTerminate2==0) pThis->m_pParent->SetTimer(1, pThis->m_time, NULL); pThis->m_bRunning2=false; pThis->m_bTerminate2=false; return 0; } catch(...) { } } unsigned __stdcall DrawEffect3Thread(LPVOID lpParam) { try { MyAnimateWindow *pThis=(MyAnimateWindow*)lpParam; CDC *pDC=pThis->GetDC(); pThis->ShowWindow(SW_SHOW); CRect rc; pThis->GetClientRect(rc); pDC->FillSolidRect (rc,0); if(pThis->m_time<2000) pThis->MagicFun20( pThis->m_pImg , 0 , 0 , pDC->GetSafeHdc() , pThis->m_pRc->left , pThis->m_pRc->top , pThis->m_pRc->Width (), pThis->m_pRc->Height () , 1, pThis->m_pRc->Width ()/12 ); else if(pThis->m_time<3000) pThis->MagicFun20( pThis->m_pImg , 0 , 0 , pDC->GetSafeHdc() , pThis->m_pRc->left , pThis->m_pRc->top , pThis->m_pRc->Width (), pThis->m_pRc->Height () , 1, pThis->m_pRc->Width ()/18 ); else pThis->MagicFun20( pThis->m_pImg , 0 , 0 , pDC->GetSafeHdc() , pThis->m_pRc->left , pThis->m_pRc->top , pThis->m_pRc->Width (), pThis->m_pRc->Height () , 1, pThis->m_pRc->Width ()/25 ); pThis->ReleaseDC(pDC); if(pThis->m_bTerminate3==0) pThis->m_pParent->SetTimer(1, pThis->m_time, NULL); pThis->m_bRunning3=false; pThis->m_bTerminate3=false; return 0; } catch(...) { } } void MyAnimateWindow::ShowAlpha() { try { m_rc=CRect(0,0,m_pImg->GetWidth(),m_pImg->GetHeight()); if(m_effect==1) { m_times=0; m_mode2++; if(m_mode2>7)m_mode2=0; switch(m_mode2) { case 0: m_mode=0; break; case 1: m_mode=4; break; case 2: m_mode=1; break; case 3: m_mode=5; break; case 4: m_mode=2; break; case 5: m_mode=6; break; case 6: m_mode=3; break; case 7: m_mode=7; break; } if(m_mode==0) { m_rc.left+=80; m_rc.bottom-=80; } else if(m_mode==1) { m_rc.right-=80; m_rc.bottom-=80; } else if(m_mode==2) { m_rc.left+=80; m_rc.top+=80; } else if(m_mode==3) { m_rc.right-=80; m_rc.top+=80; } // SetTimer(1, max(10,m_time/80), NULL); if(m_time<2000) AnimateWindow(GetSafeHwnd(), 200, AW_BLEND); else if(m_time<3000) AnimateWindow(GetSafeHwnd(), 400, AW_BLEND); else AnimateWindow(GetSafeHwnd(), 600, AW_BLEND); // Invalidate(); } else if(m_effect==2) { if(m_time<2000) AnimateWindow(GetSafeHwnd(), 200, AW_BLEND); else if(m_time<3000) AnimateWindow(GetSafeHwnd(), 400, AW_BLEND); else AnimateWindow(GetSafeHwnd(), 600, AW_BLEND); m_pParent->SetTimer(1, m_time, NULL); } else if(m_effect==3) { TerminateThread2(); } else if(m_effect==4) { TerminateThread3(); } else { ShowWindow(SW_SHOW); Invalidate(); m_pParent->SetTimer(1, m_time, NULL); } } catch(...) { } } BOOL MyAnimateWindow::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class return m_pParent->PreTranslateMessage(pMsg); // return CDialog::PreTranslateMessage(pMsg); } void MyAnimateWindow::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default /*if(nIDEvent==1) { m_times++; if(ChenkOver())return; if(m_mode==0) { m_rc.left--; m_rc.bottom++; // if(m_times%3==0) { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } else if(m_mode==1) { m_rc.right++; m_rc.bottom++; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } else if(m_mode==2) { m_rc.left--; m_rc.top--; { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==3) { m_rc.right++; m_rc.top--; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==4) { m_rc.left++; m_rc.bottom--; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==5) { m_rc.right--; m_rc.bottom--; { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==6) { m_rc.left++; m_rc.top++; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } else if(m_mode==7) { m_rc.right--; m_rc.top++; { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } Invalidate(); }*/ } BOOL MyAnimateWindow::ChenkOver() { if(m_times<80)return 0; m_pParent->SetTimer(1, 1, NULL); return 1; } void MyAnimateWindow::DrawEffect1(CDC *pDC) { try { GetClientRect(m_rcneedclear); // Graphics graph(m_pbmp); Graphics graph(pDC->GetSafeHdc ()); int step=5; if(m_time<2000) step=5; else if(m_time<3000) step=3; else if(m_time<4000) step=2; else step=1; for(int i=0; i<80/step; i++) { if(m_bTerminate)break; // graph.Clear(Color(255,0,0,0)); if(m_mode==0) { m_rc.left-=step; m_rc.bottom+=step; // if(m_times%3==0) { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } else if(m_mode==1) { m_rc.right+=step; m_rc.bottom+=step; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } else if(m_mode==2) { m_rc.left-=step; m_rc.top-=step; { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==3) { m_rc.right+=step; m_rc.top-=step; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==4) { m_rc.left+=step; m_rc.bottom-=step; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==5) { m_rc.right-=step; m_rc.bottom-=step; { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottomtop++; m_pRc->bottom++; } } } else if(m_mode==6) { m_rc.left+=step; m_rc.top+=step; { if(m_pRc->Width ()Height () && m_pRc->left) { m_pRc->left--; m_pRc->right--; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } else if(m_mode==7) { m_rc.right-=step; m_rc.top+=step; { if(m_pRc->Width ()Height () && m_pRc->rightleft++; m_pRc->right++; } else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top) { m_pRc->top--; m_pRc->bottom--; } } } CRect rc,rc2; rc.IntersectRect(m_pRc, m_rcneedclear); rc2.left =m_rcneedclear.left ; rc2.top =rc.top ; rc2.right =rc.left ; rc2.bottom =rc.bottom ; pDC->FillSolidRect (rc2, 0); rc2.left =rc.right ; rc2.top =rc.top ; rc2.right =m_rcneedclear.right ; rc2.bottom =rc.bottom ; pDC->FillSolidRect (rc2, 0); rc2.left =rc.left ; rc2.top =m_rcneedclear.top ; rc2.right =rc.right ; rc2.bottom =rc.top ; pDC->FillSolidRect (rc2, 0); rc2.left =rc.left ; rc2.top =rc.bottom ; rc2.right =rc.right ; rc2.bottom =m_rcneedclear.bottom ; pDC->FillSolidRect (rc2, 0); m_rcneedclear=*m_pRc; if(m_bTerminate)break; Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ()); graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel); // SleepEx( 10 ); SleepEx( max(10,m_time/160) ); // Sleep( 10 ); } } catch(...) { } } BOOL MyAnimateWindow::TerminateThread() { try { if ( m_bRunning ) { m_bTerminate=true; for( ; ; ) { if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 ) break; MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread); } if ( m_bRunning2 ) { m_bTerminate2=true; for( ; ; ) { if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 ) break; MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread2); } if ( m_bRunning3 ) { m_bTerminate3=true; for( ; ; ) { if ( ::WaitForSingleObject(m_hThread3, 0) == WAIT_OBJECT_0 ) break; MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread3); } return TRUE; } catch(...) { } } BOOL MyAnimateWindow::TerminateThread1() { try { if ( m_bRunning ) { m_bTerminate=true; for( ; ; ) { if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 ) break; MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread); } return TRUE; } catch(...) { } } BOOL MyAnimateWindow::TerminateThread2() { try { if ( m_bRunning2 ) { m_bTerminate2=true; for( ; ; ) { if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 ) break; MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread2); } return TRUE; } catch(...) { } } BOOL MyAnimateWindow::TerminateThread3() { try { if ( m_bRunning3 ) { m_bTerminate3=true; for( ; ; ) { if ( ::WaitForSingleObject(m_hThread3, 0) == WAIT_OBJECT_0 ) break; MSG msg; while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread3); } return TRUE; } catch(...) { } }