MyAnimateWindow.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. // MyAnimateWindow.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "MyAnimateWindow.h"
  6. #include <Winuser.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // MyAnimateWindow dialog
  14. bool SleepEx( DWORD dwMilliseconds )
  15. {
  16. if( dwMilliseconds == 0 ) return TRUE;
  17. DWORD t1 = GetTickCount();
  18. while(1)
  19. {
  20. DWORD t2 = GetTickCount();
  21. if( t2 < t1 || (t2 - t1) > dwMilliseconds )break;
  22. MSG msg;
  23. if( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )
  24. {
  25. GetMessage( &msg, NULL, 0, 0 );
  26. TranslateMessage(&msg);
  27. DispatchMessage(&msg);
  28. }
  29. else
  30. {
  31. Sleep(1);
  32. }
  33. }
  34. return TRUE;
  35. }
  36. //---------------------------------------------------
  37. //from leftbottom to righttop
  38. //-------------------------------------------------
  39. bool MyAnimateWindow::MagicFun20( Image *hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep)
  40. {
  41. try
  42. {
  43. int nSize = nStep;
  44. int Max = width>height?width:height;
  45. Graphics graph(hDestDC);
  46. while( nSize < Max )
  47. {
  48. if(m_bTerminate3)return 1;
  49. int nX = x+width-nSize;
  50. int nY = nSize;
  51. if( nX < 0 ) nX = 0;
  52. if( nY > height ) nY = height;
  53. // Rect desRect(xd , yd+height-nY , min(width,nSize) ,min(width,nSize)*height/width);
  54. Rect desRect(xd , yd+height-nY , min(width,nSize) ,min(width,nSize)*height/width);
  55. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  56. SleepEx( nDelay );
  57. nSize += nStep;
  58. }
  59. if(m_bTerminate3)return 1;
  60. Rect desRect(xd , yd , width , height);
  61. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  62. return TRUE;
  63. }
  64. catch(...)
  65. {
  66. }
  67. }
  68. bool MyAnimateWindow::MagicFun16( Image *hSrcDC , int x , int y , HDC hDestDC , int xd , int yd , int width , int height , int nDelay, int nStep )
  69. {
  70. try
  71. {
  72. Graphics graph(hDestDC);
  73. for( int i=0; i< width/nStep; i++ )
  74. {
  75. if(m_bTerminate2)return 1;
  76. Rect desRect(xd+width-(i+1)*nStep , yd , (i+1)*nStep , height);
  77. graph.DrawImage(hSrcDC, desRect, x , y , (i+1)*nStep, hSrcDC->GetHeight() ,UnitPixel);
  78. SleepEx( nDelay );
  79. }
  80. if(m_bTerminate2)return 1;
  81. Rect desRect(xd , yd , width , height);
  82. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  83. /* ·­Êé
  84. Graphics graph(hDestDC);
  85. for( int i=0; i< width/nStep; i++ )
  86. {
  87. Rect desRect(xd+width-(i+1)*nStep , yd , (i+1)*nStep , height);
  88. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  89. SleepEx( nDelay );
  90. }
  91. Rect desRect(xd , yd , width , height);
  92. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  93. */
  94. return TRUE;
  95. }
  96. catch(...)
  97. {
  98. }
  99. }
  100. MyAnimateWindow::MyAnimateWindow(CWnd* pParent /*=NULL*/)
  101. : CDialog(MyAnimateWindow::IDD, pParent)
  102. {
  103. //{{AFX_DATA_INIT(MyAnimateWindow)
  104. // NOTE: the ClassWizard will add member initialization here
  105. //}}AFX_DATA_INIT
  106. m_pImg=NULL;
  107. m_mode=-1;
  108. m_mode2=-1;
  109. m_time=3000;
  110. m_effect=1;
  111. m_bTerminate=false;
  112. m_bRunning=false;
  113. m_hThread = NULL;
  114. m_bTerminate2=false;
  115. m_bRunning2=false;
  116. m_hThread2 = NULL;
  117. m_bTerminate3=false;
  118. m_bRunning3=false;
  119. m_hThread3 = NULL;
  120. }
  121. void MyAnimateWindow::DoDataExchange(CDataExchange* pDX)
  122. {
  123. CDialog::DoDataExchange(pDX);
  124. //{{AFX_DATA_MAP(MyAnimateWindow)
  125. // NOTE: the ClassWizard will add DDX and DDV calls here
  126. //}}AFX_DATA_MAP
  127. }
  128. BEGIN_MESSAGE_MAP(MyAnimateWindow, CDialog)
  129. //{{AFX_MSG_MAP(MyAnimateWindow)
  130. ON_WM_ERASEBKGND()
  131. ON_WM_PAINT()
  132. ON_WM_TIMER()
  133. //}}AFX_MSG_MAP
  134. END_MESSAGE_MAP()
  135. /////////////////////////////////////////////////////////////////////////////
  136. // MyAnimateWindow message handlers
  137. BOOL MyAnimateWindow::OnEraseBkgnd(CDC* pDC)
  138. {
  139. try
  140. {
  141. // TODO: Add your message handler code here and/or call default
  142. if(m_pImg==NULL)
  143. return 1;
  144. // TODO: Add your message handler code here
  145. if(m_effect==1 || m_effect==2)
  146. {
  147. CRect rc;
  148. GetClientRect(rc);
  149. Graphics graph(m_pbmp);
  150. graph.Clear(Color(255,0,0,0));
  151. Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ());
  152. graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel);
  153. Graphics graph2(pDC->GetSafeHdc ());
  154. graph2.DrawImage(m_pbmp,0,0);
  155. }
  156. return 1;
  157. }
  158. catch(...)
  159. {
  160. }
  161. }
  162. void MyAnimateWindow::OnOK()
  163. {
  164. // TODO: Add extra validation here
  165. }
  166. void MyAnimateWindow::OnCancel()
  167. {
  168. // TODO: Add extra cleanup here
  169. }
  170. BOOL MyAnimateWindow::OnInitDialog()
  171. {
  172. CDialog::OnInitDialog();
  173. // TODO: Add extra initialization here
  174. return TRUE; // return TRUE unless you set the focus to a control
  175. // EXCEPTION: OCX Property Pages should return FALSE
  176. }
  177. void MyAnimateWindow::OnPaint()
  178. {
  179. CPaintDC dc(this); // device context for painting
  180. if(m_pImg==NULL)
  181. return;
  182. // TODO: Add your message handler code here
  183. if(m_effect==0)
  184. {
  185. /* Graphics graph(m_pbmp);
  186. graph.Clear(Color(255,0,0,0));
  187. Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ());
  188. graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel);
  189. Graphics graph2(dc.GetSafeHdc ());
  190. graph2.DrawImage(m_pbmp,0,0);*/
  191. try
  192. {
  193. if(m_rcneedclear.IsRectEmpty ())
  194. GetClientRect(m_rcneedclear);
  195. CDC *pDC=&dc;
  196. CRect rc,rc2;
  197. rc.IntersectRect(m_pRc, m_rcneedclear);
  198. rc2.left =m_rcneedclear.left ;
  199. rc2.top =rc.top ;
  200. rc2.right =rc.left ;
  201. rc2.bottom =rc.bottom ;
  202. pDC->FillSolidRect (rc2, 0);
  203. rc2.left =rc.right ;
  204. rc2.top =rc.top ;
  205. rc2.right =m_rcneedclear.right ;
  206. rc2.bottom =rc.bottom ;
  207. pDC->FillSolidRect (rc2, 0);
  208. rc2.left =rc.left ;
  209. rc2.top =m_rcneedclear.top ;
  210. rc2.right =rc.right ;
  211. rc2.bottom =rc.top ;
  212. pDC->FillSolidRect (rc2, 0);
  213. rc2.left =rc.left ;
  214. rc2.top =rc.bottom ;
  215. rc2.right =rc.right ;
  216. rc2.bottom =m_rcneedclear.bottom ;
  217. pDC->FillSolidRect (rc2, 0);
  218. m_rcneedclear=*m_pRc;
  219. Graphics graph(dc.GetSafeHdc ());
  220. graph.Clear(Color(255,0,0,0));
  221. Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ());
  222. graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel);
  223. }
  224. catch(...)
  225. {
  226. }
  227. }
  228. // Do not call CDialog::OnPaint() for painting messages
  229. }
  230. void MyAnimateWindow::SetImage(Image *img)
  231. {
  232. m_pImg=img;
  233. }
  234. void MyAnimateWindow::MyExit()
  235. {
  236. ::AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE);
  237. }
  238. unsigned __stdcall DrawEffect1Thread(LPVOID lpParam)
  239. {
  240. try
  241. {
  242. MyAnimateWindow *pThis=(MyAnimateWindow*)lpParam;
  243. CDC *pDC=pThis->GetDC();
  244. pThis->DrawEffect1(pDC);
  245. pThis->ReleaseDC(pDC);
  246. if(pThis->m_bTerminate==0)
  247. pThis->m_pParent->SetTimer(1, 1, NULL);
  248. pThis->m_bRunning=false;
  249. pThis->m_bTerminate=false;
  250. _endthreadex( 0 );
  251. return 0;
  252. }
  253. catch(...)
  254. {
  255. }
  256. }
  257. unsigned __stdcall DrawEffect2Thread(LPVOID lpParam)
  258. {
  259. try
  260. {
  261. MyAnimateWindow *pThis=(MyAnimateWindow*)lpParam;
  262. CDC *pDC=pThis->GetDC();
  263. pThis->ShowWindow(SW_SHOW);
  264. CRect rc;
  265. pThis->GetClientRect(rc);
  266. pDC->FillSolidRect (rc,0);
  267. if(pThis->m_time<2000)
  268. 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 );
  269. else if(pThis->m_time<3000)
  270. 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 );
  271. else
  272. 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 );
  273. pThis->ReleaseDC(pDC);
  274. if(pThis->m_bTerminate2==0)
  275. pThis->m_pParent->SetTimer(1, pThis->m_time, NULL);
  276. pThis->m_bRunning2=false;
  277. pThis->m_bTerminate2=false;
  278. _endthreadex( 0 );
  279. return 0;
  280. }
  281. catch(...)
  282. {
  283. }
  284. }
  285. unsigned __stdcall DrawEffect3Thread(LPVOID lpParam)
  286. {
  287. try
  288. {
  289. MyAnimateWindow *pThis=(MyAnimateWindow*)lpParam;
  290. CDC *pDC=pThis->GetDC();
  291. pThis->ShowWindow(SW_SHOW);
  292. CRect rc;
  293. pThis->GetClientRect(rc);
  294. pDC->FillSolidRect (rc,0);
  295. if(pThis->m_time<2000)
  296. 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 );
  297. else if(pThis->m_time<3000)
  298. 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 );
  299. else
  300. 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 );
  301. pThis->ReleaseDC(pDC);
  302. if(pThis->m_bTerminate3==0)
  303. pThis->m_pParent->SetTimer(1, pThis->m_time, NULL);
  304. pThis->m_bRunning3=false;
  305. pThis->m_bTerminate3=false;
  306. _endthreadex( 0 );
  307. return 0;
  308. }
  309. catch(...)
  310. {
  311. }
  312. }
  313. void MyAnimateWindow::ShowAlpha()
  314. {
  315. try
  316. {
  317. m_rc=CRect(0,0,m_pImg->GetWidth(),m_pImg->GetHeight());
  318. if(m_effect==1)
  319. {
  320. m_times=0;
  321. m_mode2++;
  322. if(m_mode2>7)m_mode2=0;
  323. switch(m_mode2)
  324. {
  325. case 0:
  326. m_mode=0;
  327. break;
  328. case 1:
  329. m_mode=4;
  330. break;
  331. case 2:
  332. m_mode=1;
  333. break;
  334. case 3:
  335. m_mode=5;
  336. break;
  337. case 4:
  338. m_mode=2;
  339. break;
  340. case 5:
  341. m_mode=6;
  342. break;
  343. case 6:
  344. m_mode=3;
  345. break;
  346. case 7:
  347. m_mode=7;
  348. break;
  349. }
  350. if(m_mode==0)
  351. {
  352. m_rc.left+=80;
  353. m_rc.bottom-=80;
  354. }
  355. else if(m_mode==1)
  356. {
  357. m_rc.right-=80;
  358. m_rc.bottom-=80;
  359. }
  360. else if(m_mode==2)
  361. {
  362. m_rc.left+=80;
  363. m_rc.top+=80;
  364. }
  365. else if(m_mode==3)
  366. {
  367. m_rc.right-=80;
  368. m_rc.top+=80;
  369. }
  370. // SetTimer(1, max(10,m_time/80), NULL);
  371. if(m_time<2000)
  372. ::AnimateWindow(GetSafeHwnd(), 200, AW_BLEND);
  373. else if(m_time<3000)
  374. ::AnimateWindow(GetSafeHwnd(), 400, AW_BLEND);
  375. else
  376. ::AnimateWindow(GetSafeHwnd(), 600, AW_BLEND);
  377. // Invalidate();
  378. TerminateThread1();
  379. m_hThread = (HANDLE)_beginthreadex(NULL,0, DrawEffect1Thread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  380. m_bRunning=true;
  381. }
  382. else if(m_effect==2)
  383. {
  384. if(m_time<2000)
  385. ::AnimateWindow(GetSafeHwnd(), 200, AW_BLEND);
  386. else if(m_time<3000)
  387. ::AnimateWindow(GetSafeHwnd(), 400, AW_BLEND);
  388. else
  389. ::AnimateWindow(GetSafeHwnd(), 600, AW_BLEND);
  390. m_pParent->SetTimer(1, m_time, NULL);
  391. }
  392. else if(m_effect==3)
  393. {
  394. TerminateThread2();
  395. m_hThread2 = (HANDLE)_beginthreadex(NULL,0, DrawEffect2Thread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
  396. m_bRunning2=true;
  397. }
  398. else if(m_effect==4)
  399. {
  400. TerminateThread3();
  401. m_hThread3 = (HANDLE)_beginthreadex(NULL,0, DrawEffect3Thread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
  402. m_bRunning3=true;
  403. }
  404. else
  405. {
  406. ShowWindow(SW_SHOW);
  407. Invalidate();
  408. m_pParent->SetTimer(1, m_time, NULL);
  409. }
  410. }
  411. catch(...)
  412. {
  413. }
  414. }
  415. BOOL MyAnimateWindow::PreTranslateMessage(MSG* pMsg)
  416. {
  417. // TODO: Add your specialized code here and/or call the base class
  418. return m_pParent->PreTranslateMessage(pMsg);
  419. // return CDialog::PreTranslateMessage(pMsg);
  420. }
  421. void MyAnimateWindow::OnTimer(UINT nIDEvent)
  422. {
  423. // TODO: Add your message handler code here and/or call default
  424. /*if(nIDEvent==1)
  425. {
  426. m_times++;
  427. if(ChenkOver())return;
  428. if(m_mode==0)
  429. {
  430. m_rc.left--;
  431. m_rc.bottom++;
  432. // if(m_times%3==0)
  433. {
  434. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  435. {
  436. m_pRc->left++;
  437. m_pRc->right++;
  438. }
  439. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  440. {
  441. m_pRc->top--;
  442. m_pRc->bottom--;
  443. }
  444. }
  445. }
  446. else if(m_mode==1)
  447. {
  448. m_rc.right++;
  449. m_rc.bottom++;
  450. {
  451. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  452. {
  453. m_pRc->left--;
  454. m_pRc->right--;
  455. }
  456. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  457. {
  458. m_pRc->top--;
  459. m_pRc->bottom--;
  460. }
  461. }
  462. }
  463. else if(m_mode==2)
  464. {
  465. m_rc.left--;
  466. m_rc.top--;
  467. {
  468. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  469. {
  470. m_pRc->left++;
  471. m_pRc->right++;
  472. }
  473. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  474. {
  475. m_pRc->top++;
  476. m_pRc->bottom++;
  477. }
  478. }
  479. }
  480. else if(m_mode==3)
  481. {
  482. m_rc.right++;
  483. m_rc.top--;
  484. {
  485. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  486. {
  487. m_pRc->left--;
  488. m_pRc->right--;
  489. }
  490. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  491. {
  492. m_pRc->top++;
  493. m_pRc->bottom++;
  494. }
  495. }
  496. }
  497. else if(m_mode==4)
  498. {
  499. m_rc.left++;
  500. m_rc.bottom--;
  501. {
  502. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  503. {
  504. m_pRc->left--;
  505. m_pRc->right--;
  506. }
  507. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  508. {
  509. m_pRc->top++;
  510. m_pRc->bottom++;
  511. }
  512. }
  513. }
  514. else if(m_mode==5)
  515. {
  516. m_rc.right--;
  517. m_rc.bottom--;
  518. {
  519. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  520. {
  521. m_pRc->left++;
  522. m_pRc->right++;
  523. }
  524. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  525. {
  526. m_pRc->top++;
  527. m_pRc->bottom++;
  528. }
  529. }
  530. }
  531. else if(m_mode==6)
  532. {
  533. m_rc.left++;
  534. m_rc.top++;
  535. {
  536. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  537. {
  538. m_pRc->left--;
  539. m_pRc->right--;
  540. }
  541. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  542. {
  543. m_pRc->top--;
  544. m_pRc->bottom--;
  545. }
  546. }
  547. }
  548. else if(m_mode==7)
  549. {
  550. m_rc.right--;
  551. m_rc.top++;
  552. {
  553. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  554. {
  555. m_pRc->left++;
  556. m_pRc->right++;
  557. }
  558. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  559. {
  560. m_pRc->top--;
  561. m_pRc->bottom--;
  562. }
  563. }
  564. }
  565. Invalidate();
  566. }*/
  567. }
  568. BOOL MyAnimateWindow::ChenkOver()
  569. {
  570. if(m_times<80)return 0;
  571. m_pParent->SetTimer(1, 1, NULL);
  572. return 1;
  573. }
  574. void MyAnimateWindow::DrawEffect1(CDC *pDC)
  575. {
  576. try
  577. {
  578. GetClientRect(m_rcneedclear);
  579. // Graphics graph(m_pbmp);
  580. Graphics graph(pDC->GetSafeHdc ());
  581. int step=5;
  582. if(m_time<2000)
  583. step=5;
  584. else if(m_time<3000)
  585. step=3;
  586. else if(m_time<4000)
  587. step=2;
  588. else
  589. step=1;
  590. for(int i=0; i<80/step; i++)
  591. {
  592. if(m_bTerminate)break;
  593. // graph.Clear(Color(255,0,0,0));
  594. if(m_mode==0)
  595. {
  596. m_rc.left-=step;
  597. m_rc.bottom+=step;
  598. // if(m_times%3==0)
  599. {
  600. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  601. {
  602. m_pRc->left++;
  603. m_pRc->right++;
  604. }
  605. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  606. {
  607. m_pRc->top--;
  608. m_pRc->bottom--;
  609. }
  610. }
  611. }
  612. else if(m_mode==1)
  613. {
  614. m_rc.right+=step;
  615. m_rc.bottom+=step;
  616. {
  617. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  618. {
  619. m_pRc->left--;
  620. m_pRc->right--;
  621. }
  622. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  623. {
  624. m_pRc->top--;
  625. m_pRc->bottom--;
  626. }
  627. }
  628. }
  629. else if(m_mode==2)
  630. {
  631. m_rc.left-=step;
  632. m_rc.top-=step;
  633. {
  634. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  635. {
  636. m_pRc->left++;
  637. m_pRc->right++;
  638. }
  639. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  640. {
  641. m_pRc->top++;
  642. m_pRc->bottom++;
  643. }
  644. }
  645. }
  646. else if(m_mode==3)
  647. {
  648. m_rc.right+=step;
  649. m_rc.top-=step;
  650. {
  651. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  652. {
  653. m_pRc->left--;
  654. m_pRc->right--;
  655. }
  656. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  657. {
  658. m_pRc->top++;
  659. m_pRc->bottom++;
  660. }
  661. }
  662. }
  663. else if(m_mode==4)
  664. {
  665. m_rc.left+=step;
  666. m_rc.bottom-=step;
  667. {
  668. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  669. {
  670. m_pRc->left--;
  671. m_pRc->right--;
  672. }
  673. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  674. {
  675. m_pRc->top++;
  676. m_pRc->bottom++;
  677. }
  678. }
  679. }
  680. else if(m_mode==5)
  681. {
  682. m_rc.right-=step;
  683. m_rc.bottom-=step;
  684. {
  685. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  686. {
  687. m_pRc->left++;
  688. m_pRc->right++;
  689. }
  690. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->bottom<g_screenhei)
  691. {
  692. m_pRc->top++;
  693. m_pRc->bottom++;
  694. }
  695. }
  696. }
  697. else if(m_mode==6)
  698. {
  699. m_rc.left+=step;
  700. m_rc.top+=step;
  701. {
  702. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->left)
  703. {
  704. m_pRc->left--;
  705. m_pRc->right--;
  706. }
  707. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  708. {
  709. m_pRc->top--;
  710. m_pRc->bottom--;
  711. }
  712. }
  713. }
  714. else if(m_mode==7)
  715. {
  716. m_rc.right-=step;
  717. m_rc.top+=step;
  718. {
  719. if(m_pRc->Width ()<m_pRc->Height () && m_pRc->right<g_screenwid)
  720. {
  721. m_pRc->left++;
  722. m_pRc->right++;
  723. }
  724. else if(m_pRc->Width ()>m_pRc->Height () && m_pRc->top)
  725. {
  726. m_pRc->top--;
  727. m_pRc->bottom--;
  728. }
  729. }
  730. }
  731. CRect rc,rc2;
  732. rc.IntersectRect(m_pRc, m_rcneedclear);
  733. rc2.left =m_rcneedclear.left ;
  734. rc2.top =rc.top ;
  735. rc2.right =rc.left ;
  736. rc2.bottom =rc.bottom ;
  737. pDC->FillSolidRect (rc2, 0);
  738. rc2.left =rc.right ;
  739. rc2.top =rc.top ;
  740. rc2.right =m_rcneedclear.right ;
  741. rc2.bottom =rc.bottom ;
  742. pDC->FillSolidRect (rc2, 0);
  743. rc2.left =rc.left ;
  744. rc2.top =m_rcneedclear.top ;
  745. rc2.right =rc.right ;
  746. rc2.bottom =rc.top ;
  747. pDC->FillSolidRect (rc2, 0);
  748. rc2.left =rc.left ;
  749. rc2.top =rc.bottom ;
  750. rc2.right =rc.right ;
  751. rc2.bottom =m_rcneedclear.bottom ;
  752. pDC->FillSolidRect (rc2, 0);
  753. m_rcneedclear=*m_pRc;
  754. if(m_bTerminate)break;
  755. Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ());
  756. graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel);
  757. // SleepEx( 10 );
  758. SleepEx( max(10,m_time/160) );
  759. // Sleep( 10 );
  760. }
  761. }
  762. catch(...)
  763. {
  764. }
  765. }
  766. BOOL MyAnimateWindow::TerminateThread()
  767. {
  768. try
  769. {
  770. if ( m_bRunning )
  771. {
  772. m_bTerminate=true;
  773. for( ; ; )
  774. {
  775. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  776. break;
  777. MSG msg;
  778. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  779. {
  780. if (!AfxGetApp()->PumpMessage())
  781. break;
  782. }
  783. }
  784. ::CloseHandle(m_hThread);
  785. }
  786. if ( m_bRunning2 )
  787. {
  788. m_bTerminate2=true;
  789. for( ; ; )
  790. {
  791. if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
  792. break;
  793. MSG msg;
  794. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  795. {
  796. if (!AfxGetApp()->PumpMessage())
  797. break;
  798. }
  799. }
  800. ::CloseHandle(m_hThread2);
  801. }
  802. if ( m_bRunning3 )
  803. {
  804. m_bTerminate3=true;
  805. for( ; ; )
  806. {
  807. if ( ::WaitForSingleObject(m_hThread3, 0) == WAIT_OBJECT_0 )
  808. break;
  809. MSG msg;
  810. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  811. {
  812. if (!AfxGetApp()->PumpMessage())
  813. break;
  814. }
  815. }
  816. ::CloseHandle(m_hThread3);
  817. }
  818. return TRUE;
  819. }
  820. catch(...)
  821. {
  822. }
  823. }
  824. BOOL MyAnimateWindow::TerminateThread1()
  825. {
  826. try
  827. {
  828. if ( m_bRunning )
  829. {
  830. m_bTerminate=true;
  831. for( ; ; )
  832. {
  833. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  834. break;
  835. MSG msg;
  836. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  837. {
  838. if (!AfxGetApp()->PumpMessage())
  839. break;
  840. }
  841. }
  842. ::CloseHandle(m_hThread);
  843. }
  844. return TRUE;
  845. }
  846. catch(...)
  847. {
  848. }
  849. }
  850. BOOL MyAnimateWindow::TerminateThread2()
  851. {
  852. try
  853. {
  854. if ( m_bRunning2 )
  855. {
  856. m_bTerminate2=true;
  857. for( ; ; )
  858. {
  859. if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
  860. break;
  861. MSG msg;
  862. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  863. {
  864. if (!AfxGetApp()->PumpMessage())
  865. break;
  866. }
  867. }
  868. ::CloseHandle(m_hThread2);
  869. }
  870. return TRUE;
  871. }
  872. catch(...)
  873. {
  874. }
  875. }
  876. BOOL MyAnimateWindow::TerminateThread3()
  877. {
  878. try
  879. {
  880. if ( m_bRunning3 )
  881. {
  882. m_bTerminate3=true;
  883. for( ; ; )
  884. {
  885. if ( ::WaitForSingleObject(m_hThread3, 0) == WAIT_OBJECT_0 )
  886. break;
  887. MSG msg;
  888. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  889. {
  890. if (!AfxGetApp()->PumpMessage())
  891. break;
  892. }
  893. }
  894. ::CloseHandle(m_hThread3);
  895. }
  896. return TRUE;
  897. }
  898. catch(...)
  899. {
  900. }
  901. }