ShowPic22.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. // ShowPic22.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "LYFZIPManage.h"
  5. #include "ShowPic22.h"
  6. #include "MyLock.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. // ShowPic22 dialog
  9. HANDLE Lock(char* name)
  10. {
  11. try
  12. {
  13. HANDLE mutex;
  14. // Try to open an exist mutex firstly.
  15. mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name);
  16. if(NULL == mutex) // If the mutex does not exist, create it with the certain name.
  17. {
  18. mutex = CreateMutex(NULL, TRUE, name);
  19. }
  20. else // If the mutex already exist, wait for other thread release it.
  21. {
  22. WaitForSingleObject(mutex, INFINITE);
  23. }
  24. return mutex;
  25. }
  26. catch(...)
  27. {
  28. }
  29. }
  30. bool Unlock(HANDLE mutex)
  31. {
  32. try
  33. {
  34. if(0 == ReleaseMutex(mutex)) // Failed to release mutex
  35. {
  36. return false;
  37. }
  38. else // Successed in release mutex
  39. {
  40. CloseHandle(mutex);
  41. mutex = NULL;
  42. return true;
  43. }
  44. }
  45. catch(...)
  46. {
  47. }
  48. }
  49. ShowPic22::ShowPic22(CWnd* pParent /*=NULL*/)
  50. : CDialog(ShowPic22::IDD, pParent)
  51. {
  52. //{{AFX_DATA_INIT(ShowPic22)
  53. // NOTE: the ClassWizard will add member initialization here
  54. //}}AFX_DATA_INIT
  55. m_pImage=NULL;
  56. m_pImagesmall=NULL;
  57. m_pImagetemp=NULL;
  58. m_pbmp=NULL;
  59. m_pParent=NULL;
  60. m_bauto=0;
  61. m_fscale=1;
  62. m_bScroll=0;
  63. m_bTerminate=false;
  64. m_bRunning=false;
  65. m_hThread = NULL;
  66. m_bProcessing=0;
  67. m_bInit=0;
  68. }
  69. void ShowPic22::DoDataExchange(CDataExchange* pDX)
  70. {
  71. CDialog::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(ShowPic22)
  73. DDX_Control(pDX, IDC_STATIC1, m_sta1);
  74. //}}AFX_DATA_MAP
  75. }
  76. BEGIN_MESSAGE_MAP(ShowPic22, CDialog)
  77. //{{AFX_MSG_MAP(ShowPic22)
  78. ON_WM_PAINT()
  79. ON_WM_DESTROY()
  80. ON_WM_LBUTTONDOWN()
  81. ON_WM_LBUTTONUP()
  82. ON_WM_MOUSEWHEEL()
  83. ON_WM_ERASEBKGND()
  84. ON_WM_RBUTTONDOWN()
  85. ON_WM_TIMER()
  86. ON_WM_CLOSE()
  87. ON_WM_MOUSEMOVE()
  88. //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90. /////////////////////////////////////////////////////////////////////////////
  91. // ShowPic22 message handlers
  92. extern void LoadImageFromFile(Image **img, CString path);
  93. BOOL ShowPic22::OnEraseBkgnd(CDC* pDC)
  94. {
  95. // TODO: Add your message handler code here and/or call default
  96. return 1;
  97. }
  98. unsigned __stdcall GenThumbImgThread(LPVOID lpParam)
  99. {
  100. try
  101. {
  102. ShowPic22 *pThis=(ShowPic22*)lpParam;
  103. int posbak=pThis->m_pos;
  104. int pos;
  105. BOOL bNext=1;
  106. BOOL bFirst=1;
  107. int count;
  108. while(1)
  109. {
  110. if(pThis->m_bTerminate)break;
  111. if( pThis->m_bauto || (pThis->m_bInit==0 && bFirst==0) )
  112. {
  113. ::Sleep (1000);
  114. continue;
  115. }
  116. if(bFirst)
  117. count=2;
  118. else
  119. count=5;
  120. bFirst=0;
  121. for(int i=0; i<count; i++)
  122. {
  123. if(pThis->m_bTerminate)break;
  124. if(pThis->m_bauto)break;
  125. if(posbak!=pThis->m_pos)
  126. {
  127. if(pThis->m_pos>posbak)
  128. bNext=1;
  129. else
  130. bNext=0;
  131. posbak=pThis->m_pos;i=0;continue;
  132. }
  133. if(bNext)
  134. {
  135. switch(i)
  136. {
  137. case 0:
  138. pos=posbak;
  139. break;
  140. case 1:
  141. pos=posbak+1;
  142. break;
  143. case 2:
  144. pos=posbak+2;
  145. break;
  146. case 3:
  147. pos=posbak-1;
  148. break;
  149. case 4:
  150. pos=posbak+3;
  151. break;
  152. }
  153. }
  154. else
  155. {
  156. switch(i)
  157. {
  158. case 0:
  159. pos=posbak;
  160. break;
  161. case 1:
  162. pos=posbak-1;
  163. break;
  164. case 2:
  165. pos=posbak-2;
  166. break;
  167. case 3:
  168. pos=posbak+1;
  169. break;
  170. case 4:
  171. pos=posbak-3;
  172. break;
  173. }
  174. }
  175. HANDLE handle=Lock("shgenimagethread");
  176. while(pos>=pThis->m_pPathArray->GetSize ())
  177. pos-=pThis->m_pPathArray->GetSize ();
  178. while(pos<0)
  179. pos+=pThis->m_pPathArray->GetSize ();
  180. BOOL bFind=0;
  181. for(int n=0; n<pThis->m_nPosArray.GetSize (); n++)
  182. {
  183. if(pos==pThis->m_nPosArray.ElementAt (n))
  184. {
  185. bFind=1;
  186. break;
  187. }
  188. }
  189. if(bFind)
  190. {
  191. Unlock(handle);
  192. continue;
  193. }
  194. CString path=pThis->m_pPathArray->ElementAt (pos);
  195. Image *img=NULL;
  196. Image *imgsmall=NULL;
  197. ::LoadImageFromBuf (&img, path);
  198. if(img==NULL)
  199. {
  200. Unlock(handle);
  201. continue;
  202. }
  203. if(img->GetWidth()==0)
  204. {
  205. Unlock(handle);
  206. continue;
  207. }
  208. int orientation=GetOrientation(img);
  209. if(orientation==8)
  210. img->RotateFlip( Rotate270FlipNone );
  211. else if(orientation==6)
  212. img->RotateFlip( Rotate90FlipNone );
  213. CRect rc;
  214. pThis->InitRc(img, rc);
  215. imgsmall=img->GetThumbnailImage(rc.Width (), rc.Height (), NULL, NULL);
  216. Graphics graphic(imgsmall);//防止GetThumbnailImage影响质量
  217. graphic.DrawImage(img, 0,0,imgsmall->GetWidth(), imgsmall->GetHeight() );
  218. pThis->m_pImageArray.Add (img);
  219. pThis->m_pImageSmallArray.Add (imgsmall);
  220. pThis->m_nPosArray.Add (pos);
  221. if(pThis->m_pImageArray.GetSize ()>10)
  222. {
  223. if(pThis->m_pImage!=pThis->m_pImageArray.ElementAt (0))
  224. {
  225. delete pThis->m_pImageArray.ElementAt (0);
  226. delete pThis->m_pImageSmallArray.ElementAt (0);
  227. pThis->m_pImageArray.RemoveAt(0);
  228. pThis->m_pImageSmallArray.RemoveAt(0);
  229. pThis->m_nPosArray.RemoveAt(0);
  230. }
  231. }
  232. Unlock(handle);
  233. }
  234. ::Sleep (1000);
  235. }
  236. pThis->m_bRunning=false;
  237. return 0;
  238. }
  239. catch(...)
  240. {
  241. }
  242. }
  243. BOOL ShowPic22::OnInitDialog()
  244. {
  245. CDialog::OnInitDialog();
  246. try
  247. {
  248. g_nSendCode=0;
  249. TerminateThread();
  250. g_bInSkin=1;
  251. // TODO: Add extra initialization here
  252. m_rcscreen=CRect(0, 0, g_dm.dmPelsWidth, g_dm.dmPelsHeight);
  253. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_dm.dmPelsWidth,g_dm.dmPelsHeight,SWP_SHOWWINDOW);
  254. m_pbmp=new Bitmap(g_dm.dmPelsWidth, g_dm.dmPelsHeight, PixelFormat24bppRGB );
  255. // LoadImage();
  256. if(m_pParent)
  257. m_pParent->m_showpichwd=m_hWnd;
  258. m_dlg.Create (IDD_DLGAnimateWindow, this);
  259. m_dlg.m_pParent =this;
  260. m_dlg.m_pbmp =m_pbmp;
  261. m_dlg.m_pRc=&m_rc;
  262. m_dlg.MoveWindow (m_rcscreen);
  263. m_PicBar.SetLiaPath ("4.lia");
  264. m_PicBar.Create (IDD_DLGmydlg, this);
  265. if(m_PicBar.m_bInit)
  266. {
  267. m_PicBar.m_pParent =this;
  268. int hei;
  269. m_PicBar.GetWindowRect (m_picbarrc);
  270. hei=m_picbarrc.Height ();
  271. m_picbarrc.bottom =g_dm.dmPelsHeight-10;
  272. m_picbarrc.top =m_picbarrc.bottom-hei;
  273. m_PicBar.MoveWindow (m_picbarrc);
  274. m_startpt2.x=m_startpt2.y=0;
  275. }
  276. // SetTimer(4, 500, NULL);
  277. m_sta1.SetFocus();
  278. // ::SetForegroundWindow (m_hWnd);
  279. LoadImage();
  280. }
  281. catch(...)
  282. {
  283. }
  284. return TRUE; // return TRUE unless you set the focus to a control
  285. // EXCEPTION: OCX Property Pages should return FALSE
  286. }
  287. void ShowPic22::OnPaint()
  288. {
  289. CPaintDC dc(this); // device context for painting
  290. // TODO: Add your message handler code here
  291. try
  292. {
  293. CRect rc;
  294. GetClientRect(rc);
  295. if(m_pImage && m_bauto==0)
  296. {
  297. Graphics graph(m_pbmp);
  298. graph.Clear(Color(255,0,0,0));
  299. Image *img;
  300. if(m_pImagetemp && m_bScroll==0)
  301. img=m_pImagetemp;
  302. else
  303. img=m_pImagesmall;
  304. m_bScroll=0;
  305. int width,height;
  306. width=img->GetWidth();
  307. height=img->GetHeight();
  308. ///////////////
  309. Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () );
  310. graph.DrawImage(img, destinationRect, 0,0,width,height,UnitPixel);
  311. Graphics graph2(dc.GetSafeHdc ());
  312. graph2.DrawImage(m_pbmp,0,0);
  313. }
  314. else
  315. {
  316. // dc.FillSolidRect (rc, 0);
  317. }
  318. }
  319. catch(...)
  320. {
  321. }
  322. // Do not call CDialog::OnPaint() for painting messages
  323. }
  324. void ShowPic22::OnDestroy()
  325. {
  326. CDialog::OnDestroy();
  327. try
  328. {
  329. g_nSendCode=0;
  330. for(int n=0; n<m_nPosArray.GetSize (); n++)
  331. {
  332. m_pImage=m_pImageArray.ElementAt (n);
  333. m_pImagesmall=m_pImageSmallArray.ElementAt (n);
  334. delete m_pImage;
  335. delete m_pImagesmall;
  336. }
  337. if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
  338. if(m_pbmp) delete m_pbmp;m_pbmp=NULL;
  339. KillTimer(1);
  340. }
  341. catch(...)
  342. {
  343. }
  344. // m_pic.UnloadPicture ();
  345. // TODO: Add your message handler code here
  346. }
  347. void ShowPic22::LoadImage()
  348. {
  349. try
  350. {
  351. ::SetForegroundWindow (m_hWnd);
  352. KillTimer(5);
  353. m_pImage=m_pImagesmall=NULL;
  354. for(int n=0; n<m_nPosArray.GetSize (); n++)
  355. {
  356. if(m_pos==m_nPosArray.ElementAt (n))
  357. {
  358. m_pImage=m_pImageArray.ElementAt (n);
  359. m_pImagesmall=m_pImageSmallArray.ElementAt (n);
  360. break;
  361. }
  362. }
  363. if( m_pImage==NULL && ( m_bauto || m_bInit==0) )
  364. {
  365. HANDLE handle=Lock("shgenimagethread");
  366. CString path=m_pPathArray->ElementAt (m_pos);
  367. ::LoadImageFromBuf (&m_pImage, path);
  368. if(m_pImage==NULL)
  369. {
  370. Unlock(handle);
  371. return;
  372. }
  373. if(m_pImage->GetWidth()==0)
  374. {
  375. Unlock(handle);
  376. return;
  377. }
  378. int orientation=GetOrientation(m_pImage);
  379. if(orientation==8)
  380. m_pImage->RotateFlip( Rotate270FlipNone );
  381. else if(orientation==6)
  382. m_pImage->RotateFlip( Rotate90FlipNone );
  383. InitRc();
  384. m_pImagesmall=m_pImage->GetThumbnailImage(m_rc.Width (), m_rc.Height (), NULL, NULL);
  385. Graphics graphic(m_pImagesmall);//防止GetThumbnailImage影响质量
  386. graphic.DrawImage(m_pImage, 0,0,m_pImagesmall->GetWidth(), m_pImagesmall->GetHeight() );
  387. m_pImageArray.Add (m_pImage);
  388. m_pImageSmallArray.Add (m_pImagesmall);
  389. m_nPosArray.Add (m_pos);
  390. if(m_pImageArray.GetSize ()>10)
  391. {
  392. if(m_pImage!=m_pImageArray.ElementAt (0))
  393. {
  394. delete m_pImageArray.ElementAt (0);
  395. delete m_pImageSmallArray.ElementAt (0);
  396. m_pImageArray.RemoveAt(0);
  397. m_pImageSmallArray.RemoveAt(0);
  398. m_nPosArray.RemoveAt(0);
  399. }
  400. }
  401. Unlock(handle);
  402. }
  403. else if(m_pImage==NULL)
  404. {
  405. SetTimer(5, 1, NULL);
  406. return ;
  407. }
  408. // if(m_pImage) delete m_pImage;m_pImage=NULL;
  409. // if(m_pImagesmall) delete m_pImagesmall;m_pImagesmall=NULL;
  410. if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
  411. /* CString path=m_pPathArray->ElementAt (m_pos);
  412. ::LoadImageFromBuf (&m_pImage, path);
  413. if(m_pImage==NULL)return;
  414. if(m_pImage->GetWidth()==0)return;
  415. int orientation=GetOrientation(m_pImage);
  416. if(orientation==8)
  417. m_pImage->RotateFlip( Rotate270FlipNone );
  418. else if(orientation==6)
  419. m_pImage->RotateFlip( Rotate90FlipNone );*/
  420. InitRc();
  421. // m_pImagesmall=m_pImage->GetThumbnailImage(m_rc.Width (), m_rc.Height (), NULL, NULL);
  422. // Graphics graphic(m_pImagesmall);//防止GetThumbnailImage影响质量
  423. // graphic.DrawImage(m_pImage, 0,0,m_pImagesmall->GetWidth(), m_pImagesmall->GetHeight() );
  424. if(m_bauto )
  425. {
  426. if(m_dlg.m_effect ==1 || m_dlg.m_effect ==2)
  427. {
  428. CDC *pDC=GetDC();
  429. HDC hdc=::GetDC(NULL);
  430. ::BitBlt (pDC->GetSafeHdc (), 0, 0, g_dm.dmPelsWidth, g_dm.dmPelsHeight , hdc, 0, 0, SRCCOPY);
  431. ReleaseDC(pDC);
  432. }
  433. m_dlg.m_time =m_PicBar.m_time*1000;
  434. m_dlg.SetImage (m_pImagesmall);
  435. if(m_dlg.m_effect ==1 || m_dlg.m_effect ==2)
  436. {
  437. m_dlg.ShowWindow (SW_HIDE);
  438. }
  439. m_dlg.ShowAlpha();
  440. }
  441. else
  442. Invalidate();
  443. }
  444. catch(...)
  445. {
  446. }
  447. }
  448. void ShowPic22::OnLButtonDown(UINT nFlags, CPoint point)
  449. {
  450. // TODO: Add your message handler code here and/or call default
  451. SetCapture();
  452. m_startpt=point;
  453. CDialog::OnLButtonDown(nFlags, point);
  454. }
  455. void ShowPic22::OnMouseMove(UINT nFlags, CPoint point)
  456. {
  457. // TODO: Add your message handler code here and/or call default
  458. if(GetCapture()!=this)return;
  459. if(m_rc.Width ()>m_rcscreen.Width ())
  460. {
  461. if(m_rc.left <m_rcscreen.left && point.x>m_startpt.x)
  462. {
  463. int dt=min(point.x-m_startpt.x, m_rcscreen.left-m_rc.left);
  464. m_rc.left +=dt;
  465. m_rc.right +=dt;
  466. }
  467. else if(m_rc.right >m_rcscreen.right && point.x<m_startpt.x)
  468. {
  469. int dt=min(m_startpt.x-point.x, m_rc.right-m_rcscreen.right);
  470. m_rc.left -=dt;
  471. m_rc.right -=dt;
  472. }
  473. }
  474. if(m_rc.Height ()>m_rcscreen.Height ())
  475. {
  476. if(m_rc.top <m_rcscreen.top && point.y>m_startpt.y)
  477. {
  478. int dt=min(point.y-m_startpt.y, m_rcscreen.top-m_rc.top);
  479. m_rc.top +=dt;
  480. m_rc.bottom +=dt;
  481. }
  482. else if(m_rc.bottom >m_rcscreen.bottom && point.y<m_startpt.y)
  483. {
  484. int dt=min(m_startpt.y-point.y, m_rc.bottom-m_rcscreen.bottom);
  485. m_rc.top -=dt;
  486. m_rc.bottom -=dt;
  487. }
  488. }
  489. m_startpt=point;
  490. Invalidate();
  491. CDialog::OnMouseMove(nFlags, point);
  492. }
  493. void ShowPic22::OnLButtonUp(UINT nFlags, CPoint point)
  494. {
  495. // TODO: Add your message handler code here and/or call default
  496. if(GetCapture()!=this)return;
  497. ReleaseCapture();
  498. CDialog::OnLButtonUp(nFlags, point);
  499. }
  500. BOOL ShowPic22::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  501. {
  502. // TODO: Add your message handler code here and/or call default
  503. if(m_pImage==NULL)return 1;
  504. if(m_bauto)return 1;if(m_bProcessing)return 1;
  505. m_bScroll=1;
  506. if(zDelta>0)
  507. {
  508. // if(m_fscale>4)return 1;
  509. m_fscale*=1.2;
  510. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  511. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  512. m_rc.left -=dtx;
  513. m_rc.right +=dtx;
  514. m_rc.top -=dty;
  515. m_rc.bottom +=dty;
  516. Invalidate();
  517. }
  518. else
  519. {
  520. if(m_fscale<=1)return 1;
  521. m_fscale/=1.2;
  522. if(m_fscale<1)m_fscale=1;
  523. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  524. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  525. m_rc.left -=dtx;
  526. m_rc.right +=dtx;
  527. m_rc.top -=dty;
  528. m_rc.bottom +=dty;
  529. if(m_rcbak.Height ()==m_rcscreen.Height ())
  530. {
  531. if(m_rc.top <m_rcscreen.top && m_rc.bottom < m_rcscreen.bottom )
  532. {
  533. dtx=m_rcscreen.bottom -m_rc.bottom;
  534. m_rc.top +=dtx;
  535. m_rc.bottom +=dtx;
  536. }
  537. else if(m_rc.top >m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom )
  538. {
  539. dtx=m_rc.top-m_rcscreen.top;
  540. m_rc.top -=dtx;
  541. m_rc.bottom -=dtx;
  542. }
  543. dtx=m_rc.Width ();
  544. m_rc.left =(m_rcscreen.Width ()-dtx)/2;
  545. m_rc.right =m_rc.left +dtx;
  546. }
  547. if(m_rcbak.Width ()==m_rcscreen.Width ())
  548. {
  549. if(m_rc.left <m_rcscreen.left && m_rc.right < m_rcscreen.right )
  550. {
  551. dtx=m_rcscreen.right -m_rc.right;
  552. m_rc.left +=dtx;
  553. m_rc.right +=dtx;
  554. }
  555. else if(m_rc.left >m_rcscreen.left && m_rc.right > m_rcscreen.right )
  556. {
  557. dtx=m_rc.left-m_rcscreen.left;
  558. m_rc.left -=dtx;
  559. m_rc.right -=dtx;
  560. }
  561. dtx=m_rc.Height ();
  562. m_rc.top =(m_rcscreen.Height ()-dtx)/2;
  563. m_rc.bottom =m_rc.top +dtx;
  564. }
  565. Invalidate();
  566. /* int dtx=(m_fscale-1)*m_rcbak.Width ()/2.0;
  567. int dty=(m_fscale-1)*m_rcbak.Height ()/2.0;
  568. m_rc=m_rcbak;
  569. m_rc.left -=dtx;
  570. m_rc.right +=dtx;
  571. m_rc.top -=dty;
  572. m_rc.bottom +=dty;
  573. Invalidate();*/
  574. }
  575. KillTimer(2);
  576. SetTimer(2, 100, NULL);
  577. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  578. }
  579. BOOL ShowPic22::PreTranslateMessage(MSG* pMsg)
  580. {
  581. // TODO: Add your specialized code here and/or call the base class
  582. if(pMsg->message==WM_MOUSEMOVE )
  583. {
  584. if(m_PicBar.m_bInit && m_pImage)
  585. {
  586. CPoint point;
  587. ::GetCursorPos (&point);
  588. if( abs(m_startpt2.x -point.x )>5 || abs(m_startpt2.y -point.y )>5)
  589. {
  590. m_startpt2=point;
  591. m_PicBar.ShowWindow (SW_SHOW);
  592. SetTimer(3, 1500, NULL);
  593. }
  594. }
  595. }
  596. else if(pMsg->message==WM_KEYDOWN )
  597. {
  598. switch (pMsg->wParam)
  599. {
  600. case VK_RETURN:
  601. return 1;
  602. case VK_ESCAPE:
  603. KillTimer(6);
  604. SetTimer(6, 100, NULL);
  605. return 1;
  606. case VK_F3:
  607. AutoPic();
  608. break;
  609. case VK_UP:
  610. Rotate1();
  611. return 1;
  612. case VK_LEFT:
  613. Pre();
  614. return 1;
  615. case VK_DOWN:
  616. Rotate2();
  617. return 1;
  618. case VK_RIGHT:
  619. Next();
  620. return 1;
  621. case VK_DELETE:
  622. if(m_bauto)return 1;
  623. if(m_pParent)
  624. {
  625. if(m_bProcessing)return 1;
  626. m_bProcessing=1;
  627. ::SetForegroundWindow (m_hWnd);
  628. if(m_pParent)
  629. {
  630. for(int i=0; i<m_pParent->m_List1.GetItemCount (); i++)
  631. {
  632. m_pParent->m_List1.SetItemState (i, 0, -1);
  633. }
  634. m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
  635. }
  636. if(m_pParent->OnDel())
  637. {
  638. ::SetForegroundWindow (m_hWnd);
  639. // TerminateThread();
  640. HANDLE handle=Lock("shgenimagethread");
  641. m_pImage=m_pImagesmall=NULL;
  642. for(int n=0; n<m_nPosArray.GetSize (); n++)
  643. {
  644. if(m_pos==m_nPosArray.ElementAt (n))
  645. {
  646. delete m_pImageArray.ElementAt (n);
  647. delete m_pImageSmallArray.ElementAt (n);
  648. m_pImageArray.RemoveAt(n);
  649. m_pImageSmallArray.RemoveAt(n);
  650. m_nPosArray.RemoveAt(n);
  651. }
  652. }
  653. if(m_pos>=this->m_pPathArray->GetSize ())
  654. m_pos=0;
  655. Unlock(handle);
  656. LoadImage();
  657. m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
  658. }
  659. m_bProcessing=0;
  660. return 1;
  661. }
  662. }
  663. ::SetForegroundWindow (m_hWnd);
  664. }
  665. return CDialog::PreTranslateMessage(pMsg);
  666. }
  667. void ShowPic22::OnRButtonDown(UINT nFlags, CPoint point)
  668. {
  669. // TODO: Add your message handler code here and/or call default
  670. if(m_bauto)return;if(m_bProcessing)return;
  671. if(m_pParent)
  672. {
  673. for(int i=0; i<m_pParent->m_List1.GetItemCount (); i++)
  674. {
  675. m_pParent->m_List1.SetItemState (i, 0, -1);
  676. }
  677. m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
  678. m_pParent->OnRclickList1();
  679. }
  680. CDialog::OnRButtonDown(nFlags, point);
  681. }
  682. void ShowPic22::AutoPic()
  683. {
  684. try
  685. {
  686. if(m_bProcessing)return;
  687. m_dlg.m_effect=m_PicBar.m_nType;
  688. m_bauto=!m_bauto;
  689. m_PicBar.ChangeBtn();
  690. if(m_bauto)
  691. {
  692. m_pos=0;
  693. LoadImage();
  694. }
  695. else
  696. {
  697. KillTimer(1);
  698. m_dlg.TerminateThread ();
  699. m_dlg.ShowWindow (SW_HIDE);
  700. }
  701. ::SetForegroundWindow (m_hWnd);
  702. }
  703. catch(...)
  704. {
  705. }
  706. }
  707. void ShowPic22::OnTimer(UINT nIDEvent)
  708. {
  709. // TODO: Add your message handler code here and/or call default
  710. try
  711. {
  712. ::SetForegroundWindow (m_hWnd);
  713. if(nIDEvent==1)
  714. {
  715. KillTimer(1);
  716. m_pos++;
  717. if(m_pos>=this->m_pPathArray->GetSize ())
  718. {
  719. KillTimer(1);
  720. m_bauto=0;
  721. m_dlg.TerminateThread ();
  722. m_dlg.ShowWindow (SW_HIDE);
  723. m_PicBar.ChangeBtn();
  724. AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
  725. return;
  726. }
  727. LoadImage();
  728. }
  729. else if(nIDEvent==2)
  730. {
  731. KillTimer(2);
  732. if(m_pImagetemp)
  733. {
  734. if(m_rc.Width ()>m_pImagetemp->GetWidth())
  735. {
  736. if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
  737. m_pImagetemp=m_pImage->GetThumbnailImage(min(m_pImage->GetWidth(),m_rc.Width ()), min(m_pImage->GetHeight(),m_rc.Height ()), NULL, NULL);
  738. Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
  739. graphic.DrawImage(m_pImage, 0,0,m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight() );
  740. }
  741. }
  742. else
  743. {
  744. m_pImagetemp=m_pImage->GetThumbnailImage(min(m_pImage->GetWidth(),m_rc.Width ()), min(m_pImage->GetHeight(),m_rc.Height ()), NULL, NULL);
  745. Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
  746. graphic.DrawImage(m_pImage, 0,0,m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight() );
  747. }
  748. Invalidate();
  749. }
  750. else if(nIDEvent==3)
  751. {
  752. KillTimer(3);
  753. CPoint pt;
  754. ::GetCursorPos (&pt);
  755. if(m_picbarrc.PtInRect (pt))
  756. {
  757. SetTimer(3, 1500, NULL);
  758. }
  759. else
  760. m_PicBar.ShowWindow (SW_HIDE);
  761. ::SetForegroundWindow (m_hWnd);
  762. }
  763. else if(nIDEvent==4)
  764. {
  765. KillTimer(4);
  766. m_PicBar.SetLiaPath ("4.lia");
  767. m_PicBar.Create (IDD_DLGmydlg, this);
  768. if(m_PicBar.m_bInit)
  769. {
  770. m_PicBar.m_pParent =this;
  771. int hei;
  772. m_PicBar.GetWindowRect (m_picbarrc);
  773. hei=m_picbarrc.Height ();
  774. m_picbarrc.bottom =g_dm.dmPelsHeight-10;
  775. m_picbarrc.top =m_picbarrc.bottom-hei;
  776. m_PicBar.MoveWindow (m_picbarrc);
  777. SetTimer(3, 1500, NULL);
  778. m_startpt2.x=m_startpt2.y=0;
  779. }
  780. ::SetForegroundWindow (m_hWnd);
  781. }
  782. else if(nIDEvent==5)
  783. {
  784. KillTimer(5);
  785. LoadImage();
  786. }
  787. else if(nIDEvent==6)
  788. {
  789. if(m_bProcessing)return;
  790. m_bProcessing=1;
  791. g_nSendCode=0;
  792. TerminateThread();
  793. m_dlg.TerminateThread();
  794. g_bInSkin=0;
  795. CDialog::OnOK ();
  796. m_bProcessing=0;
  797. }
  798. }
  799. catch(...)
  800. {
  801. }
  802. }
  803. void ShowPic22::OnClose()
  804. {
  805. // TODO: Add your message handler code here and/or call default
  806. /* TerminateThread();
  807. for(int n=0; n<m_nPosArray.GetSize (); n++)
  808. {
  809. m_pImage=m_pImageArray.ElementAt (n);
  810. m_pImagesmall=m_pImageSmallArray.ElementAt (n);
  811. delete m_pImage;
  812. delete m_pImagesmall;
  813. }
  814. m_pImageArray.RemoveAll ();
  815. m_pImageSmallArray.RemoveAll ();
  816. m_nPosArray.RemoveAll ();*/
  817. try
  818. {
  819. m_pImage=m_pImagesmall=NULL;
  820. HANDLE handle=Lock("shgenimagethread");
  821. m_pImage=m_pImagesmall=NULL;
  822. for(int n=0; n<m_nPosArray.GetSize (); n++)
  823. {
  824. if(m_pos==m_nPosArray.ElementAt (n))
  825. {
  826. delete m_pImageArray.ElementAt (n);
  827. delete m_pImageSmallArray.ElementAt (n);
  828. m_pImageArray.RemoveAt(n);
  829. m_pImageSmallArray.RemoveAt(n);
  830. m_nPosArray.RemoveAt(n);
  831. }
  832. }
  833. if(m_pos>=this->m_pPathArray->GetSize ())
  834. m_pos=0;
  835. Unlock(handle);
  836. LoadImage();
  837. }
  838. catch(...)
  839. {
  840. }
  841. }
  842. void ShowPic22::InitRc()
  843. {
  844. try
  845. {
  846. if(m_pImage==NULL)return;
  847. CRect rc;
  848. GetClientRect(rc);
  849. m_rc=rc;
  850. int width,height;
  851. width=m_pImage->GetWidth();
  852. height=m_pImage->GetHeight();
  853. //////////
  854. float fscale=(float)width/(float)height;
  855. float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
  856. int rcwid=m_rc.Width ();
  857. int rchei=m_rc.Height ();
  858. int dt=0;
  859. if(rcscale<fscale)
  860. {
  861. dt=(rchei-rcwid/fscale)/2;
  862. m_rc.top+=dt;
  863. m_rc.bottom-=dt;
  864. }
  865. else
  866. {
  867. dt=(rcwid-rchei*fscale)/2;
  868. m_rc.left +=dt;
  869. m_rc.right-=dt;
  870. }
  871. m_rcbak=m_rc;
  872. }
  873. catch(...)
  874. {
  875. }
  876. }
  877. void ShowPic22::Rotate1()
  878. {
  879. if(m_bauto)return;if(m_bProcessing)return;
  880. try
  881. {
  882. if(m_pImage)
  883. {
  884. m_pImage->RotateFlip( Rotate270FlipNone );
  885. if(m_pImagesmall) m_pImagesmall->RotateFlip( Rotate270FlipNone );
  886. if(m_pImagetemp) m_pImagetemp->RotateFlip( Rotate270FlipNone );
  887. InitRc();
  888. Invalidate();
  889. }
  890. }
  891. catch(...)
  892. {
  893. }
  894. }
  895. void ShowPic22::Rotate2()
  896. {
  897. if(m_bauto)return;if(m_bProcessing)return;
  898. try
  899. {
  900. if(m_pImage)
  901. {
  902. m_pImage->RotateFlip( Rotate90FlipNone );
  903. if(m_pImagesmall) m_pImagesmall->RotateFlip( Rotate90FlipNone );
  904. if(m_pImagetemp) m_pImagetemp->RotateFlip( Rotate90FlipNone );
  905. InitRc();
  906. Invalidate();
  907. }
  908. }
  909. catch(...)
  910. {
  911. }
  912. }
  913. void ShowPic22::Pre()
  914. {
  915. if(m_bauto)return;if(m_bProcessing)return;
  916. m_bInit=1;
  917. try
  918. {
  919. {
  920. m_pos--;
  921. if(m_pos<0)
  922. m_pos=this->m_pPathArray->GetSize ()-1;
  923. LoadImage();
  924. }
  925. }
  926. catch(...)
  927. {
  928. }
  929. }
  930. void ShowPic22::Next()
  931. {
  932. if(m_bauto)return;if(m_bProcessing)return;
  933. m_bInit=1;
  934. try
  935. {
  936. {
  937. m_pos++;
  938. if(m_pos>=this->m_pPathArray->GetSize ())
  939. m_pos=0;
  940. LoadImage();
  941. }
  942. }
  943. catch(...)
  944. {
  945. }
  946. }
  947. void ShowPic22::SetEffect(int effect)
  948. {
  949. ::SetForegroundWindow (m_hWnd);
  950. m_dlg.m_effect=effect;
  951. // if(effect==0)
  952. // SetTimer(1, 3000, NULL);
  953. }
  954. void ShowPic22::TerminateThread()
  955. {
  956. try
  957. {
  958. if ( m_bRunning )
  959. {
  960. m_bTerminate=true;
  961. for( ; ; )
  962. {
  963. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  964. break;
  965. MSG msg;
  966. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  967. {
  968. if (!AfxGetApp()->PumpMessage())
  969. break;
  970. }
  971. }
  972. ::CloseHandle(m_hThread);
  973. }
  974. }
  975. catch(...)
  976. {
  977. }
  978. }
  979. void ShowPic22::InitRc(Image *img, CRect &rc)
  980. {
  981. try
  982. {
  983. if(img==NULL)return;
  984. CRect rc2;
  985. GetClientRect(rc2);
  986. rc=rc2;
  987. int width,height;
  988. width=img->GetWidth();
  989. height=img->GetHeight();
  990. //////////
  991. float fscale=(float)width/(float)height;
  992. float rcscale=((float)rc.Width ())/((float)rc.Height ());
  993. int rcwid=rc.Width ();
  994. int rchei=rc.Height ();
  995. int dt=0;
  996. if(rcscale<fscale)
  997. {
  998. dt=(rchei-rcwid/fscale)/2;
  999. rc.top+=dt;
  1000. rc.bottom-=dt;
  1001. }
  1002. else
  1003. {
  1004. dt=(rcwid-rchei*fscale)/2;
  1005. rc.left +=dt;
  1006. rc.right-=dt;
  1007. }
  1008. }
  1009. catch(...)
  1010. {
  1011. }
  1012. }