MyAnimateWindow.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. return true;
  68. }
  69. bool MyAnimateWindow::MagicFun16(Image *hSrcDC, int x, int y, HDC hDestDC, int xd, int yd, int width, int height, int nDelay, int nStep)
  70. {
  71. try
  72. {
  73. Graphics graph(hDestDC);
  74. for (int i = 0; i < width / nStep; i++)
  75. {
  76. if (m_bTerminate2)return 1;
  77. Rect desRect(xd + width - (i + 1)*nStep, yd, (i + 1)*nStep, height);
  78. graph.DrawImage(hSrcDC, desRect, x, y, (i + 1)*nStep, hSrcDC->GetHeight(), UnitPixel);
  79. SleepEx(nDelay);
  80. }
  81. if (m_bTerminate2)return 1;
  82. Rect desRect(xd, yd, width, height);
  83. graph.DrawImage(hSrcDC, desRect, x, y, hSrcDC->GetWidth(), hSrcDC->GetHeight(), UnitPixel);
  84. /* ·­Êé
  85. Graphics graph(hDestDC);
  86. for( int i=0; i< width/nStep; i++ )
  87. {
  88. Rect desRect(xd+width-(i+1)*nStep , yd , (i+1)*nStep , height);
  89. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  90. SleepEx( nDelay );
  91. }
  92. Rect desRect(xd , yd , width , height);
  93. graph.DrawImage(hSrcDC, desRect, x , y , hSrcDC->GetWidth(), hSrcDC->GetHeight() ,UnitPixel);
  94. */
  95. return TRUE;
  96. }
  97. catch (...)
  98. {
  99. }
  100. return true;
  101. }
  102. MyAnimateWindow::MyAnimateWindow(CWnd* pParent /*=NULL*/): CDialog(MyAnimateWindow::IDD, pParent)
  103. {
  104. m_pImg = NULL;
  105. m_mode = -1;
  106. m_mode2 = -1;
  107. m_time = 3000;
  108. m_effect = 1;
  109. m_bTerminate = false;
  110. m_bRunning = false;
  111. m_hThread = NULL;
  112. m_bTerminate2 = false;
  113. m_bRunning2 = false;
  114. m_hThread2 = NULL;
  115. m_bTerminate3 = false;
  116. m_bRunning3 = false;
  117. m_hThread3 = NULL;
  118. }
  119. void MyAnimateWindow::DoDataExchange(CDataExchange* pDX)
  120. {
  121. CDialog::DoDataExchange(pDX);
  122. }
  123. BEGIN_MESSAGE_MAP(MyAnimateWindow, CDialog)
  124. ON_WM_ERASEBKGND()
  125. ON_WM_PAINT()
  126. ON_WM_TIMER()
  127. END_MESSAGE_MAP()
  128. BOOL MyAnimateWindow::OnEraseBkgnd(CDC* pDC)
  129. {
  130. try
  131. {
  132. if (m_pImg == NULL)
  133. return 1;
  134. if (m_effect == 1 || m_effect == 2)
  135. {
  136. CRect rc;
  137. GetClientRect(rc);
  138. Graphics graph(m_pbmp);
  139. graph.Clear(Color(255, 0, 0, 0));
  140. Rect desRect(m_pRc->left, m_pRc->top, m_pRc->Width(), m_pRc->Height());
  141. graph.DrawImage(m_pImg, desRect, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), UnitPixel);
  142. Graphics graph2(pDC->GetSafeHdc());
  143. graph2.DrawImage(m_pbmp, 0, 0);
  144. }
  145. return 1;
  146. }
  147. catch (...)
  148. {
  149. }
  150. return true;
  151. }
  152. void MyAnimateWindow::OnOK()
  153. {
  154. }
  155. void MyAnimateWindow::OnCancel()
  156. {
  157. }
  158. BOOL MyAnimateWindow::OnInitDialog()
  159. {
  160. CDialog::OnInitDialog();
  161. return TRUE;
  162. }
  163. void MyAnimateWindow::OnPaint()
  164. {
  165. CPaintDC dc(this); // device context for painting
  166. if (m_pImg == NULL)
  167. return;
  168. if (m_effect == 0)
  169. {
  170. /* Graphics graph(m_pbmp);
  171. graph.Clear(Color(255,0,0,0));
  172. Rect desRect(m_pRc->left , m_pRc->top , m_pRc->Width (), m_pRc->Height ());
  173. graph.DrawImage(m_pImg, desRect, m_rc.left , m_rc.top , m_rc.Width() , m_rc.Height() ,UnitPixel);
  174. Graphics graph2(dc.GetSafeHdc ());
  175. graph2.DrawImage(m_pbmp,0,0);*/
  176. try
  177. {
  178. if (m_rcneedclear.IsRectEmpty())
  179. GetClientRect(m_rcneedclear);
  180. CDC *pDC = &dc;
  181. CRect rc, rc2;
  182. rc.IntersectRect(m_pRc, m_rcneedclear);
  183. rc2.left = m_rcneedclear.left;
  184. rc2.top = rc.top;
  185. rc2.right = rc.left;
  186. rc2.bottom = rc.bottom;
  187. pDC->FillSolidRect(rc2, 0);
  188. rc2.left = rc.right;
  189. rc2.top = rc.top;
  190. rc2.right = m_rcneedclear.right;
  191. rc2.bottom = rc.bottom;
  192. pDC->FillSolidRect(rc2, 0);
  193. rc2.left = rc.left;
  194. rc2.top = m_rcneedclear.top;
  195. rc2.right = rc.right;
  196. rc2.bottom = rc.top;
  197. pDC->FillSolidRect(rc2, 0);
  198. rc2.left = rc.left;
  199. rc2.top = rc.bottom;
  200. rc2.right = rc.right;
  201. rc2.bottom = m_rcneedclear.bottom;
  202. pDC->FillSolidRect(rc2, 0);
  203. m_rcneedclear = *m_pRc;
  204. Graphics graph(dc.GetSafeHdc());
  205. graph.Clear(Color(255, 0, 0, 0));
  206. Rect desRect(m_pRc->left, m_pRc->top, m_pRc->Width(), m_pRc->Height());
  207. graph.DrawImage(m_pImg, desRect, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), UnitPixel);
  208. }
  209. catch (...)
  210. {
  211. }
  212. }
  213. }
  214. void MyAnimateWindow::SetImage(Image *img)
  215. {
  216. m_pImg = img;
  217. }
  218. void MyAnimateWindow::MyExit()
  219. {
  220. ::AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE);
  221. }
  222. unsigned __stdcall DrawEffect1Thread(LPVOID lpParam)
  223. {
  224. try
  225. {
  226. MyAnimateWindow *pThis = (MyAnimateWindow*)lpParam;
  227. CDC *pDC = pThis->GetDC();
  228. pThis->DrawEffect1(pDC);
  229. pThis->ReleaseDC(pDC);
  230. if (pThis->m_bTerminate == 0)
  231. pThis->m_pParent->SetTimer(1, 1, NULL);
  232. pThis->m_bRunning = false;
  233. pThis->m_bTerminate = false;
  234. _endthreadex(0);
  235. return 0;
  236. }
  237. catch (...)
  238. {
  239. }
  240. return true;
  241. }
  242. unsigned __stdcall DrawEffect2Thread(LPVOID lpParam)
  243. {
  244. try
  245. {
  246. MyAnimateWindow *pThis = (MyAnimateWindow*)lpParam;
  247. CDC *pDC = pThis->GetDC();
  248. pThis->ShowWindow(SW_SHOW);
  249. CRect rc;
  250. pThis->GetClientRect(rc);
  251. pDC->FillSolidRect(rc, 0);
  252. if (pThis->m_time < 2000)
  253. 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);
  254. else if (pThis->m_time < 3000)
  255. 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);
  256. else
  257. 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);
  258. pThis->ReleaseDC(pDC);
  259. if (pThis->m_bTerminate2 == 0)
  260. pThis->m_pParent->SetTimer(1, pThis->m_time, NULL);
  261. pThis->m_bRunning2 = false;
  262. pThis->m_bTerminate2 = false;
  263. _endthreadex(0);
  264. return 0;
  265. }
  266. catch (...)
  267. {
  268. }
  269. return true;
  270. }
  271. unsigned __stdcall DrawEffect3Thread(LPVOID lpParam)
  272. {
  273. try
  274. {
  275. MyAnimateWindow *pThis = (MyAnimateWindow*)lpParam;
  276. CDC *pDC = pThis->GetDC();
  277. pThis->ShowWindow(SW_SHOW);
  278. CRect rc;
  279. pThis->GetClientRect(rc);
  280. pDC->FillSolidRect(rc, 0);
  281. if (pThis->m_time < 2000)
  282. 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);
  283. else if (pThis->m_time < 3000)
  284. 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);
  285. else
  286. 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);
  287. pThis->ReleaseDC(pDC);
  288. if (pThis->m_bTerminate3 == 0)
  289. pThis->m_pParent->SetTimer(1, pThis->m_time, NULL);
  290. pThis->m_bRunning3 = false;
  291. pThis->m_bTerminate3 = false;
  292. _endthreadex(0);
  293. return 0;
  294. }
  295. catch (...)
  296. {
  297. }
  298. return true;
  299. }
  300. void MyAnimateWindow::ShowAlpha()
  301. {
  302. try
  303. {
  304. m_rc = CRect(0, 0, m_pImg->GetWidth(), m_pImg->GetHeight());
  305. if (m_effect == 1)
  306. {
  307. m_times = 0;
  308. m_mode2++;
  309. if (m_mode2 > 7)
  310. m_mode2 = 0;
  311. switch (m_mode2)
  312. {
  313. case 0:
  314. m_mode = 0;
  315. break;
  316. case 1:
  317. m_mode = 4;
  318. break;
  319. case 2:
  320. m_mode = 1;
  321. break;
  322. case 3:
  323. m_mode = 5;
  324. break;
  325. case 4:
  326. m_mode = 2;
  327. break;
  328. case 5:
  329. m_mode = 6;
  330. break;
  331. case 6:
  332. m_mode = 3;
  333. break;
  334. case 7:
  335. m_mode = 7;
  336. break;
  337. }
  338. if (m_mode == 0)
  339. {
  340. m_rc.left += 80;
  341. m_rc.bottom -= 80;
  342. }
  343. else if (m_mode == 1)
  344. {
  345. m_rc.right -= 80;
  346. m_rc.bottom -= 80;
  347. }
  348. else if (m_mode == 2)
  349. {
  350. m_rc.left += 80;
  351. m_rc.top += 80;
  352. }
  353. else if (m_mode == 3)
  354. {
  355. m_rc.right -= 80;
  356. m_rc.top += 80;
  357. }
  358. // SetTimer(1, max(10,m_time/80), NULL);
  359. if (m_time < 2000)
  360. ::AnimateWindow(GetSafeHwnd(), 200, AW_BLEND);
  361. else if (m_time < 3000)
  362. ::AnimateWindow(GetSafeHwnd(), 400, AW_BLEND);
  363. else
  364. ::AnimateWindow(GetSafeHwnd(), 600, AW_BLEND);
  365. // Invalidate();
  366. TerminateThread1();
  367. m_hThread = (HANDLE)_beginthreadex(NULL, 0, DrawEffect1Thread, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  368. m_bRunning = true;
  369. }
  370. else if (m_effect == 2)
  371. {
  372. if (m_time < 2000)
  373. ::AnimateWindow(GetSafeHwnd(), 200, AW_BLEND);
  374. else if (m_time < 3000)
  375. ::AnimateWindow(GetSafeHwnd(), 400, AW_BLEND);
  376. else
  377. ::AnimateWindow(GetSafeHwnd(), 600, AW_BLEND);
  378. m_pParent->SetTimer(1, m_time, NULL);
  379. }
  380. else if (m_effect == 3)
  381. {
  382. TerminateThread2();
  383. m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, DrawEffect2Thread, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID2);
  384. m_bRunning2 = true;
  385. }
  386. else if (m_effect == 4)
  387. {
  388. TerminateThread3();
  389. m_hThread3 = (HANDLE)_beginthreadex(NULL, 0, DrawEffect3Thread, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID2);
  390. m_bRunning3 = true;
  391. }
  392. else
  393. {
  394. ShowWindow(SW_SHOW);
  395. Invalidate();
  396. m_pParent->SetTimer(1, m_time, NULL);
  397. }
  398. }
  399. catch (...)
  400. {
  401. }
  402. }
  403. BOOL MyAnimateWindow::PreTranslateMessage(MSG* pMsg)
  404. {
  405. return m_pParent->PreTranslateMessage(pMsg);
  406. }
  407. void MyAnimateWindow::OnTimer(UINT nIDEvent)
  408. {
  409. }
  410. BOOL MyAnimateWindow::ChenkOver()
  411. {
  412. if (m_times < 80)return 0;
  413. m_pParent->SetTimer(1, 1, NULL);
  414. return 1;
  415. }
  416. void MyAnimateWindow::DrawEffect1(CDC *pDC)
  417. {
  418. try
  419. {
  420. GetClientRect(m_rcneedclear);
  421. // Graphics graph(m_pbmp);
  422. Graphics graph(pDC->GetSafeHdc());
  423. int step = 5;
  424. if (m_time < 2000)
  425. step = 5;
  426. else if (m_time < 3000)
  427. step = 3;
  428. else if (m_time < 4000)
  429. step = 2;
  430. else
  431. step = 1;
  432. for (int i = 0; i < 80 / step; i++)
  433. {
  434. if (m_bTerminate)break;
  435. // graph.Clear(Color(255,0,0,0));
  436. if (m_mode == 0)
  437. {
  438. m_rc.left -= step;
  439. m_rc.bottom += step;
  440. // if(m_times%3==0)
  441. {
  442. if (m_pRc->Width() < m_pRc->Height() && m_pRc->right<g_screenwid)
  443. {
  444. m_pRc->left++;
  445. m_pRc->right++;
  446. }
  447. else if (m_pRc->Width()>m_pRc->Height() && m_pRc->top)
  448. {
  449. m_pRc->top--;
  450. m_pRc->bottom--;
  451. }
  452. }
  453. }
  454. else if (m_mode == 1)
  455. {
  456. m_rc.right += step;
  457. m_rc.bottom += step;
  458. {
  459. if (m_pRc->Width() < m_pRc->Height() && m_pRc->left)
  460. {
  461. m_pRc->left--;
  462. m_pRc->right--;
  463. }
  464. else if (m_pRc->Width() > m_pRc->Height() && m_pRc->top)
  465. {
  466. m_pRc->top--;
  467. m_pRc->bottom--;
  468. }
  469. }
  470. }
  471. else if (m_mode == 2)
  472. {
  473. m_rc.left -= step;
  474. m_rc.top -= step;
  475. {
  476. if (m_pRc->Width() < m_pRc->Height() && m_pRc->right<g_screenwid)
  477. {
  478. m_pRc->left++;
  479. m_pRc->right++;
  480. }
  481. else if (m_pRc->Width()>m_pRc->Height() && m_pRc->bottom < g_screenhei)
  482. {
  483. m_pRc->top++;
  484. m_pRc->bottom++;
  485. }
  486. }
  487. }
  488. else if (m_mode == 3)
  489. {
  490. m_rc.right += step;
  491. m_rc.top -= step;
  492. {
  493. if (m_pRc->Width() < m_pRc->Height() && m_pRc->left)
  494. {
  495. m_pRc->left--;
  496. m_pRc->right--;
  497. }
  498. else if (m_pRc->Width() > m_pRc->Height() && m_pRc->bottom < g_screenhei)
  499. {
  500. m_pRc->top++;
  501. m_pRc->bottom++;
  502. }
  503. }
  504. }
  505. else if (m_mode == 4)
  506. {
  507. m_rc.left += step;
  508. m_rc.bottom -= step;
  509. {
  510. if (m_pRc->Width() < m_pRc->Height() && m_pRc->left)
  511. {
  512. m_pRc->left--;
  513. m_pRc->right--;
  514. }
  515. else if (m_pRc->Width() > m_pRc->Height() && m_pRc->bottom < g_screenhei)
  516. {
  517. m_pRc->top++;
  518. m_pRc->bottom++;
  519. }
  520. }
  521. }
  522. else if (m_mode == 5)
  523. {
  524. m_rc.right -= step;
  525. m_rc.bottom -= step;
  526. {
  527. if (m_pRc->Width() < m_pRc->Height() && m_pRc->right<g_screenwid)
  528. {
  529. m_pRc->left++;
  530. m_pRc->right++;
  531. }
  532. else if (m_pRc->Width()>m_pRc->Height() && m_pRc->bottom < g_screenhei)
  533. {
  534. m_pRc->top++;
  535. m_pRc->bottom++;
  536. }
  537. }
  538. }
  539. else if (m_mode == 6)
  540. {
  541. m_rc.left += step;
  542. m_rc.top += step;
  543. {
  544. if (m_pRc->Width() < m_pRc->Height() && m_pRc->left)
  545. {
  546. m_pRc->left--;
  547. m_pRc->right--;
  548. }
  549. else if (m_pRc->Width() > m_pRc->Height() && m_pRc->top)
  550. {
  551. m_pRc->top--;
  552. m_pRc->bottom--;
  553. }
  554. }
  555. }
  556. else if (m_mode == 7)
  557. {
  558. m_rc.right -= step;
  559. m_rc.top += step;
  560. {
  561. if (m_pRc->Width() < m_pRc->Height() && m_pRc->right<g_screenwid)
  562. {
  563. m_pRc->left++;
  564. m_pRc->right++;
  565. }
  566. else if (m_pRc->Width()>m_pRc->Height() && m_pRc->top)
  567. {
  568. m_pRc->top--;
  569. m_pRc->bottom--;
  570. }
  571. }
  572. }
  573. CRect rc, rc2;
  574. rc.IntersectRect(m_pRc, m_rcneedclear);
  575. rc2.left = m_rcneedclear.left;
  576. rc2.top = rc.top;
  577. rc2.right = rc.left;
  578. rc2.bottom = rc.bottom;
  579. pDC->FillSolidRect(rc2, 0);
  580. rc2.left = rc.right;
  581. rc2.top = rc.top;
  582. rc2.right = m_rcneedclear.right;
  583. rc2.bottom = rc.bottom;
  584. pDC->FillSolidRect(rc2, 0);
  585. rc2.left = rc.left;
  586. rc2.top = m_rcneedclear.top;
  587. rc2.right = rc.right;
  588. rc2.bottom = rc.top;
  589. pDC->FillSolidRect(rc2, 0);
  590. rc2.left = rc.left;
  591. rc2.top = rc.bottom;
  592. rc2.right = rc.right;
  593. rc2.bottom = m_rcneedclear.bottom;
  594. pDC->FillSolidRect(rc2, 0);
  595. m_rcneedclear = *m_pRc;
  596. if (m_bTerminate)break;
  597. Rect desRect(m_pRc->left, m_pRc->top, m_pRc->Width(), m_pRc->Height());
  598. graph.DrawImage(m_pImg, desRect, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), UnitPixel);
  599. SleepEx(max(10, m_time / 160));
  600. }
  601. }
  602. catch (...)
  603. {
  604. }
  605. }
  606. BOOL MyAnimateWindow::TerminateThread()
  607. {
  608. try
  609. {
  610. if (m_bRunning)
  611. {
  612. m_bTerminate = true;
  613. for (;;)
  614. {
  615. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  616. break;
  617. MSG msg;
  618. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  619. {
  620. if (!AfxGetApp()->PumpMessage())
  621. break;
  622. }
  623. }
  624. ::CloseHandle(m_hThread);
  625. }
  626. if (m_bRunning2)
  627. {
  628. m_bTerminate2 = true;
  629. for (;;)
  630. {
  631. if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0)
  632. break;
  633. MSG msg;
  634. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  635. {
  636. if (!AfxGetApp()->PumpMessage())
  637. break;
  638. }
  639. }
  640. ::CloseHandle(m_hThread2);
  641. }
  642. if (m_bRunning3)
  643. {
  644. m_bTerminate3 = true;
  645. for (;;)
  646. {
  647. if (::WaitForSingleObject(m_hThread3, 0) == WAIT_OBJECT_0)
  648. break;
  649. MSG msg;
  650. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  651. {
  652. if (!AfxGetApp()->PumpMessage())
  653. break;
  654. }
  655. }
  656. ::CloseHandle(m_hThread3);
  657. }
  658. return TRUE;
  659. }
  660. catch (...)
  661. {
  662. }
  663. return true;
  664. }
  665. BOOL MyAnimateWindow::TerminateThread1()
  666. {
  667. try
  668. {
  669. if (m_bRunning)
  670. {
  671. m_bTerminate = true;
  672. for (;;)
  673. {
  674. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  675. break;
  676. MSG msg;
  677. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  678. {
  679. if (!AfxGetApp()->PumpMessage())
  680. break;
  681. }
  682. }
  683. ::CloseHandle(m_hThread);
  684. }
  685. return TRUE;
  686. }
  687. catch (...)
  688. {
  689. }
  690. return true;
  691. }
  692. BOOL MyAnimateWindow::TerminateThread2()
  693. {
  694. try
  695. {
  696. if (m_bRunning2)
  697. {
  698. m_bTerminate2 = true;
  699. for (;;)
  700. {
  701. if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0)
  702. break;
  703. MSG msg;
  704. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  705. {
  706. if (!AfxGetApp()->PumpMessage())
  707. break;
  708. }
  709. }
  710. ::CloseHandle(m_hThread2);
  711. }
  712. return TRUE;
  713. }
  714. catch (...)
  715. {
  716. }
  717. return true;
  718. }
  719. BOOL MyAnimateWindow::TerminateThread3()
  720. {
  721. try
  722. {
  723. if (m_bRunning3)
  724. {
  725. m_bTerminate3 = true;
  726. for (;;)
  727. {
  728. if (::WaitForSingleObject(m_hThread3, 0) == WAIT_OBJECT_0)
  729. break;
  730. MSG msg;
  731. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  732. {
  733. if (!AfxGetApp()->PumpMessage())
  734. break;
  735. }
  736. }
  737. ::CloseHandle(m_hThread3);
  738. }
  739. return TRUE;
  740. }
  741. catch (...)
  742. {
  743. }
  744. return true;
  745. }