MyAnimateWindow.cpp 17 KB

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