ShowPic22.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640
  1. // ShowPic22.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShowPic22.h"
  6. #include "MyLock.h"
  7. #include "ShowEffect.h"
  8. #include "CutPhoto.h"
  9. #define PCL_R(p) (((RGBQUAD*)(p))->rgbRed)
  10. #define PCL_G(p) (((RGBQUAD*)(p))->rgbGreen)
  11. #define PCL_B(p) (((RGBQUAD*)(p))->rgbBlue)
  12. #define PCL_A(p) (((RGBQUAD*)(p))->rgbReserved)
  13. /////////////////////////////////////////////////////////////////////////////
  14. // PicBar m_PicBar;
  15. HANDLE Lock(char* name)
  16. {
  17. try
  18. {
  19. HANDLE mutex;
  20. // Try to open an exist mutex firstly.
  21. mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name);
  22. if(NULL == mutex) // If the mutex does not exist, create it with the certain name.
  23. {
  24. mutex = CreateMutex(NULL, TRUE, name);
  25. }
  26. else // If the mutex already exist, wait for other thread release it.
  27. {
  28. WaitForSingleObject(mutex, INFINITE);
  29. }
  30. return mutex;
  31. }
  32. catch(...)
  33. {
  34. }
  35. }
  36. bool Unlock(HANDLE mutex)
  37. {
  38. try
  39. {
  40. if(0 == ReleaseMutex(mutex)) // Failed to release mutex
  41. {
  42. return false;
  43. }
  44. else // Successed in release mutex
  45. {
  46. CloseHandle(mutex);
  47. mutex = NULL;
  48. return true;
  49. }
  50. }
  51. catch(...)
  52. {
  53. }
  54. }
  55. ShowPic22::ShowPic22(CWnd* pParent /*=NULL*/)
  56. : CDialog(ShowPic22::IDD, pParent)
  57. {
  58. //{{AFX_DATA_INIT(ShowPic22)
  59. // NOTE: the ClassWizard will add member initialization here IDC_STATIC2
  60. //}}AFX_DATA_INIT
  61. m_pImage=NULL;
  62. m_pImagesmall=NULL;
  63. m_pImagetemp=NULL;
  64. m_pbmp=NULL;
  65. m_pParent=NULL;
  66. m_bauto=0;
  67. m_fscale=1;
  68. m_bScroll=0;
  69. m_bTerminate=false;
  70. m_bRunning=false;
  71. m_hThread = NULL;
  72. m_bProcessing=0;
  73. m_bInit=0;
  74. m_bShowName=0;
  75. m_bShowEffect=0;
  76. m_pPathArray=NULL;
  77. m_pPathArrayBigsize=NULL;
  78. m_bChooseBig=0;
  79. }
  80. void ShowPic22::DoDataExchange(CDataExchange* pDX)
  81. {
  82. CDialog::DoDataExchange(pDX);
  83. //{{AFX_DATA_MAP(ShowPic22)
  84. DDX_Control(pDX, IDC_STATIC1, m_sta1);
  85. //}}AFX_DATA_MAP
  86. }
  87. BEGIN_MESSAGE_MAP(ShowPic22, CDialog)
  88. //{{AFX_MSG_MAP(ShowPic22)
  89. ON_WM_PAINT()
  90. ON_WM_DESTROY()
  91. ON_WM_LBUTTONDOWN()
  92. ON_WM_LBUTTONUP()
  93. ON_WM_MOUSEWHEEL()
  94. ON_WM_ERASEBKGND()
  95. ON_WM_RBUTTONDOWN()
  96. ON_WM_TIMER()
  97. ON_WM_CLOSE()
  98. ON_WM_MOUSEMOVE()
  99. ON_WM_CTLCOLOR()
  100. ON_MESSAGE(WM_USER+200, ShowInfo2)
  101. //}}AFX_MSG_MAP
  102. END_MESSAGE_MAP()
  103. /////////////////////////////////////////////////////////////////////////////
  104. // ShowPic22 message handlers
  105. BOOL ShowPic22::OnEraseBkgnd(CDC* pDC)
  106. {
  107. // TODO: Add your message handler code here and/or call default
  108. return 1;
  109. }
  110. unsigned __stdcall GenThumbImgThread(LPVOID lpParam)
  111. {
  112. try
  113. {
  114. ShowPic22 *pThis=(ShowPic22*)lpParam;
  115. int posbak=pThis->m_pos;
  116. int pos;
  117. BOOL bNext=1;
  118. BOOL bFirst=1;
  119. int count;
  120. while(1)
  121. {
  122. if(pThis->m_bTerminate)break;
  123. if( pThis->m_bauto || (pThis->m_bInit==0 && bFirst==0) )
  124. {
  125. ::Sleep (1000);
  126. continue;
  127. }
  128. if(bFirst)
  129. count=2;
  130. else
  131. count=5;
  132. bFirst=0;
  133. for(int i=0; i<count; i++)
  134. {
  135. if(pThis->m_bTerminate)break;
  136. if(pThis->m_bauto)break;
  137. if(posbak!=pThis->m_pos)
  138. {
  139. if(pThis->m_pos>posbak)
  140. bNext=1;
  141. else
  142. bNext=0;
  143. posbak=pThis->m_pos;i=0;continue;
  144. }
  145. if(bNext)
  146. {
  147. switch(i)
  148. {
  149. case 0:
  150. pos=posbak;
  151. break;
  152. case 1:
  153. pos=posbak+1;
  154. break;
  155. case 2:
  156. pos=posbak+2;
  157. break;
  158. case 3:
  159. pos=posbak-1;
  160. break;
  161. case 4:
  162. pos=posbak+3;
  163. break;
  164. }
  165. }
  166. else
  167. {
  168. switch(i)
  169. {
  170. case 0:
  171. pos=posbak;
  172. break;
  173. case 1:
  174. pos=posbak-1;
  175. break;
  176. case 2:
  177. pos=posbak-2;
  178. break;
  179. case 3:
  180. pos=posbak+1;
  181. break;
  182. case 4:
  183. pos=posbak-3;
  184. break;
  185. }
  186. }
  187. HANDLE handle=Lock("shgenimagethread");
  188. while(pos>=pThis->m_pPathArray->GetSize ())
  189. pos-=pThis->m_pPathArray->GetSize ();
  190. while(pos<0)
  191. pos+=pThis->m_pPathArray->GetSize ();
  192. BOOL bFind=0;
  193. for(int n=0; n<pThis->m_nPosArray.GetSize (); n++)
  194. {
  195. if(pos==pThis->m_nPosArray.ElementAt (n))
  196. {
  197. bFind=1;
  198. break;
  199. }
  200. }
  201. if(bFind)
  202. {
  203. Unlock(handle);
  204. continue;
  205. }
  206. CString path=pThis->m_pPathArray->ElementAt (pos);
  207. if( pThis->m_bChooseBig && pThis->m_pos==pos)
  208. {
  209. path=pThis->m_pPathArrayBigsize->ElementAt (pos);
  210. pThis->m_bChooseBig=0;
  211. }
  212. Image *img=NULL;
  213. Image *imgsmall=NULL;
  214. ::LoadImageFromBuf (&img, path);
  215. if(img==NULL)
  216. {
  217. Bitmap *pNULLBmp=new Bitmap(100, 100, PixelFormat24bppRGB );
  218. Graphics graph2(pNULLBmp);
  219. graph2.Clear(Color(255,0,0,0));
  220. Bitmap *pNULLBmp2=new Bitmap(100, 100, PixelFormat24bppRGB );
  221. Graphics graph3(pNULLBmp2);
  222. graph3.Clear(Color(255,0,0,0));
  223. pThis->m_pImageArray.Add (pNULLBmp);
  224. pThis->m_pImageSmallArray.Add (pNULLBmp2);
  225. pThis->m_nPosArray.Add (pos);
  226. Unlock(handle);
  227. continue;
  228. }
  229. if(img->GetWidth()==0)
  230. {
  231. Bitmap *pNULLBmp=new Bitmap(100, 100, PixelFormat24bppRGB );
  232. Graphics graph2(pNULLBmp);
  233. graph2.Clear(Color(255,0,0,0));
  234. Bitmap *pNULLBmp2=new Bitmap(100, 100, PixelFormat24bppRGB );
  235. Graphics graph3(pNULLBmp2);
  236. graph3.Clear(Color(255,0,0,0));
  237. pThis->m_pImageArray.Add (pNULLBmp);
  238. pThis->m_pImageSmallArray.Add (pNULLBmp2);
  239. pThis->m_nPosArray.Add (pos);
  240. Unlock(handle);
  241. continue;
  242. }
  243. CRect rc;
  244. pThis->InitRc(img, rc);
  245. imgsmall=img->GetThumbnailImage(rc.Width (), rc.Height (), NULL, NULL);
  246. Graphics graphic(imgsmall);//防止GetThumbnailImage影响质量
  247. graphic.DrawImage(img, 0,0,imgsmall->GetWidth(), imgsmall->GetHeight() );
  248. int orientation=GetOrientation(img);
  249. if(orientation==8)
  250. {
  251. imgsmall->RotateFlip( Rotate270FlipNone );
  252. img->RotateFlip( Rotate270FlipNone );
  253. }
  254. else if(orientation==6)
  255. {
  256. imgsmall->RotateFlip( Rotate90FlipNone );
  257. img->RotateFlip( Rotate90FlipNone );
  258. }
  259. pThis->m_pImageArray.Add (img);
  260. pThis->m_pImageSmallArray.Add (imgsmall);
  261. pThis->m_nPosArray.Add (pos);
  262. if(pThis->m_pImageArray.GetSize ()>10)
  263. {
  264. if(pThis->m_pImage!=pThis->m_pImageArray.ElementAt (0))
  265. {
  266. delete pThis->m_pImageArray.ElementAt (0);
  267. delete pThis->m_pImageSmallArray.ElementAt (0);
  268. pThis->m_pImageArray.RemoveAt(0);
  269. pThis->m_pImageSmallArray.RemoveAt(0);
  270. pThis->m_nPosArray.RemoveAt(0);
  271. }
  272. }
  273. Unlock(handle);
  274. }
  275. ::Sleep (200);
  276. }
  277. pThis->m_bRunning=false;
  278. pThis->m_bTerminate=false;
  279. _endthreadex( 0 );
  280. return 0;
  281. }
  282. catch(...)
  283. {
  284. }
  285. }
  286. BOOL ShowPic22::OnInitDialog()
  287. {
  288. CDialog::OnInitDialog();
  289. m_bShowName=1;
  290. try
  291. {
  292. g_nSendCode=0;
  293. RunPicThread();
  294. if(m_bShowName)
  295. {
  296. GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
  297. }
  298. // TODO: Add extra initialization here
  299. m_rcscreen=CRect(0, 0, g_screenwid, g_screenhei);
  300. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW);
  301. // m_pbmp=new Bitmap(g_screenwid, g_screenhei, PixelFormat24bppRGB );
  302. m_pbmp=new Bitmap(g_screenwid, g_screenhei, PixelFormat32bppARGB );
  303. // LoadImage();
  304. if(m_pParent)
  305. m_pParent->m_showpichwd=m_hWnd;
  306. m_dlg.Create (IDD_DLGAnimateWindow, this);
  307. m_dlg.m_pParent =this;
  308. m_dlg.m_pbmp =m_pbmp;
  309. m_dlg.m_pRc=&m_rc;
  310. m_dlg.MoveWindow (m_rcscreen);
  311. if(m_PicBar.GetSafeHwnd ()==NULL)
  312. {
  313. if(m_pParent==NULL)
  314. m_PicBar.m_bShowCut=0;
  315. else if(m_pParent->m_mode2) m_PicBar.m_bShowCut=0;
  316. m_PicBar.PreLoad();
  317. m_PicBar.SetLiaPath ("4.lia");
  318. m_PicBar.Create (IDD_DLGmydlg, this);
  319. }
  320. if(m_PreviewDlg.GetSafeHwnd ()==NULL)
  321. {
  322. m_PreviewDlg.Create (IDD_DIALOG30, this);
  323. CRect rc;
  324. rc.top =50;
  325. rc.bottom =g_screenhei-50;
  326. rc.right =g_screenwid-10;
  327. rc.left =rc.right -100;
  328. ///////////////////////////
  329. rc.left=g_screenwid-20;
  330. rc.right=rc.left+100;
  331. ///////////////////////////
  332. m_PreviewDlg.MoveWindow (rc);
  333. m_PreviewDlg.m_pPathArray=m_pPathArray;
  334. m_PreviewDlg.InitCtrl();
  335. }
  336. // m_PicBar.SetParent (this);
  337. if(m_PicBar.m_bInit)
  338. {
  339. m_PicBar.m_pParent =this;
  340. int hei;
  341. m_PicBar.GetWindowRect (m_picbarrc);
  342. hei=m_picbarrc.Height ();
  343. m_picbarrc.bottom =g_screenhei-10;
  344. m_picbarrc.top =m_picbarrc.bottom-hei;
  345. m_PicBar.MoveWindow (m_picbarrc);
  346. m_startpt2.x=m_startpt2.y=0;
  347. }
  348. m_sta1.SetFocus();
  349. // ::SetForegroundWindow (m_hWnd);
  350. LoadImage(); m_PreviewDlg.ShowWindow (SW_SHOW);
  351. }
  352. catch(...)
  353. {
  354. }
  355. return TRUE; // return TRUE unless you set the focus to a control
  356. // EXCEPTION: OCX Property Pages should return FALSE
  357. }
  358. inline void RGBtoHLS (int R, int G, int B, double* H, double* L, double* S)
  359. {
  360. const int n_cmax = max(B, max(R, G)),
  361. n_cmin = min(B, min(R, G));
  362. *L = (n_cmax + n_cmin) / 2.0 / 255.0 ;
  363. if (n_cmax == n_cmin)
  364. {
  365. *S = *H = 0.0 ;
  366. return ;
  367. }
  368. const double r = (double)R / 255.0,
  369. g = (double)G / 255.0,
  370. b = (double)B / 255.0,
  371. cmax = n_cmax / 255.0,
  372. cmin = n_cmin / 255.0,
  373. delta = cmax - cmin ;
  374. if (*L < 0.5)
  375. *S = delta / (cmax+cmin) ;
  376. else
  377. *S = delta / (2.0-cmax-cmin) ;
  378. if (R == n_cmax)
  379. *H = (g-b) / delta ;
  380. else if (G == n_cmax)
  381. *H = 2.0 + (b-r) / delta ;
  382. else
  383. *H = 4.0 + (r-g) / delta ;
  384. *H /= 6.0 ;
  385. if (*H < 0.0)
  386. *H += 1.0 ;
  387. }
  388. RGBQUAD __DoubleRGB_to_RGB (const double& r, const double& g, const double& b)
  389. {
  390. RGBQUAD rgb;
  391. rgb.rgbRed=max(0,min(255, (int)r*255));
  392. rgb.rgbGreen=max(0,min(255, (int)g*255));
  393. rgb.rgbBlue=max(0,min(255, (int)b*255));
  394. return rgb ;
  395. }
  396. inline double __HLS_Value (const double& m1, const double& m2, double h)
  397. {
  398. if (h > 6.0)
  399. h -= 6.0 ;
  400. else if (h < 0.0)
  401. h += 6.0 ;
  402. if (h < 1.0)
  403. return m1 + (m2 - m1) * h ;
  404. else if (h < 3.0)
  405. return m2 ;
  406. else if (h < 4.0)
  407. return m1 + (m2 - m1) * (4.0 - h) ;
  408. return m1 ;
  409. }
  410. inline RGBQUAD HLStoRGB (const double& H, const double& L, const double& S)
  411. {
  412. double m1, m2 ;
  413. if (L < 0.5)
  414. m2 = L * (1.0 + S) ;
  415. else
  416. m2 = L + S - L*S ;
  417. m1 = 2.0*L - m2 ;
  418. return __DoubleRGB_to_RGB (__HLS_Value (m1, m2, H*6.0 + 2.0),
  419. __HLS_Value (m1, m2, H*6.0),
  420. __HLS_Value (m1, m2, H*6.0 - 2.0)) ;
  421. }
  422. void Autocontrast(Bitmap *pBmpImage)
  423. {return;
  424. try
  425. {
  426. if(pBmpImage==NULL)return;
  427. BitmapData bitmapData;
  428. UINT* pixels;
  429. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  430. pBmpImage->LockBits(
  431. rc,
  432. ImageLockModeWrite,
  433. PixelFormat32bppARGB ,
  434. &bitmapData);
  435. // Write to the temporary buffer provided by LockBits. RGB
  436. pixels = (UINT*)bitmapData.Scan0;
  437. DWORD wids=bitmapData.Stride/4;
  438. Color color;
  439. BYTE R,G,B;
  440. double H, L, S ;
  441. int iPercent =128 * 110 / 100 ; // 转换成x/128
  442. int iPercentSat = 128 * 120 / 100 ; // 转换成x/128
  443. RGBQUAD rgb2;RGBTRIPLE rgb;
  444. for(INT row = 0; row < rc.Height; ++row)
  445. {
  446. for(INT col = 0; col < rc.Width; ++col)
  447. {
  448. color.SetValue(pixels[row * wids + col]);
  449. R=min(255, max(0, 128 + (color.GetR()-128) * iPercent / 128 ));
  450. G=min(255, max(0, 128 + (color.GetG()-128) * iPercent / 128 ));
  451. B=min(255, max(0, 128 + (color.GetB()-128) * iPercent / 128 ));
  452. rgb.rgbtRed =color.GetR();
  453. rgb.rgbtGreen =color.GetG();
  454. rgb.rgbtBlue =color.GetB();
  455. FCColor::RGBtoHLS (&rgb, &H, &L, &S) ;
  456. S = S * iPercentSat / 128 ;
  457. rgb2 = FCColor::HLStoRGB (H, L, S) ;
  458. pixels[row * wids + col]=Color::MakeARGB(255, rgb2.rgbRed, rgb2.rgbGreen, rgb2.rgbBlue );
  459. // pixels[row * wids + col]=Color::MakeARGB(255, R, G, B );
  460. }
  461. }
  462. pBmpImage->UnlockBits(&bitmapData);
  463. }
  464. catch(...)
  465. {
  466. }
  467. }
  468. void Autosaturation(Bitmap *pBmpImage)
  469. {
  470. #ifdef HIGH_VERSION
  471. try
  472. {
  473. if(pBmpImage==NULL)return;
  474. if(g_pMainWnd->m_pToneColorDlg2->m_saturation==100)return;
  475. BitmapData bitmapData;
  476. UINT* pixels;
  477. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  478. pBmpImage->LockBits(
  479. rc,
  480. ImageLockModeWrite,
  481. PixelFormat32bppARGB ,
  482. &bitmapData);
  483. // Write to the temporary buffer provided by LockBits. RGB
  484. pixels = (UINT*)bitmapData.Scan0;
  485. DWORD wids=bitmapData.Stride/4;
  486. Color color;
  487. double H, L, S ;
  488. RGBTRIPLE rgb;
  489. RGBQUAD rgb2;
  490. int iPercentSat = 128 * g_pMainWnd->m_pToneColorDlg2->m_saturation / 100 ; // 转换成x/128
  491. for(INT row = 0; row < rc.Height; ++row)
  492. {
  493. for(INT col = 0; col < rc.Width; ++col)
  494. {
  495. color.SetValue(pixels[row * wids + col]);
  496. rgb.rgbtRed =color.GetR();
  497. rgb.rgbtGreen =color.GetG();
  498. rgb.rgbtBlue =color.GetB();
  499. FCColor::RGBtoHLS (&rgb, &H, &L, &S) ;
  500. S = S * iPercentSat / 128 ;
  501. rgb2 = FCColor::HLStoRGB (H, L, S) ;
  502. pixels[row * wids + col]=Color::MakeARGB(color.GetA(), rgb2.rgbRed, rgb2.rgbGreen, rgb2.rgbBlue );
  503. }
  504. }
  505. pBmpImage->UnlockBits(&bitmapData);
  506. }
  507. catch(...)
  508. {
  509. }
  510. #endif
  511. }
  512. void ShowPic22::OnPaint()
  513. {
  514. CPaintDC dc(this); // device context for painting
  515. // TODO: Add your message handler code here
  516. try
  517. {
  518. CRect rc;
  519. GetClientRect(rc);
  520. if(m_pImage && m_bauto==0)
  521. {
  522. Graphics graph(m_pbmp);
  523. graph.Clear(Color(255,0,0,0));
  524. Image *img;
  525. if(m_pImagetemp && m_bScroll==0)
  526. img=m_pImagetemp;
  527. else
  528. img=m_pImagesmall;
  529. m_bScroll=0;
  530. int width,height;
  531. width=img->GetWidth();
  532. height=img->GetHeight();
  533. ///////////////
  534. Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () );
  535. // graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  536. graph.DrawImage(img, destinationRect, 0,0,width,height,UnitPixel);
  537. Graphics graph2(dc.GetSafeHdc ());
  538. Autocontrast(m_pbmp);
  539. graph2.DrawImage(m_pbmp,0,0);
  540. }
  541. else
  542. {
  543. // dc.FillSolidRect (rc, 0);
  544. }
  545. }
  546. catch(...)
  547. {
  548. }
  549. // Do not call CDialog::OnPaint() for painting messages
  550. }
  551. void ShowPic22::OnDestroy()
  552. {
  553. try
  554. {
  555. g_nSendCode=0;
  556. for(int n=0; n<m_nPosArray.GetSize (); n++)
  557. {
  558. m_pImage=m_pImageArray.ElementAt (n);
  559. m_pImagesmall=m_pImageSmallArray.ElementAt (n);
  560. delete m_pImage;
  561. delete m_pImagesmall;
  562. }
  563. if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
  564. if(m_pbmp) delete m_pbmp;m_pbmp=NULL;
  565. KillTimer(1);
  566. }
  567. catch(...)
  568. {
  569. }
  570. CDialog::OnDestroy();
  571. // m_pic.UnloadPicture ();
  572. // TODO: Add your message handler code here
  573. }
  574. void ShowPic22::LoadImage()
  575. {
  576. try
  577. {
  578. ::SetForegroundWindow (m_hWnd);
  579. KillTimer(5);
  580. if(m_pPathArray->GetSize ()==0)return;//2011-03-09
  581. m_pImage=m_pImagesmall=NULL;
  582. for(int n=0; n<m_nPosArray.GetSize (); n++)
  583. {
  584. if(m_pos==m_nPosArray.ElementAt (n))
  585. {
  586. m_pImage=m_pImageArray.ElementAt (n);
  587. m_pImagesmall=m_pImageSmallArray.ElementAt (n);
  588. break;
  589. }
  590. }
  591. if( m_pImage==NULL && ( m_bauto || m_bInit==0) )
  592. {
  593. HANDLE handle=Lock("shgenimagethread");
  594. CString path=m_pPathArray->ElementAt (m_pos);
  595. if( m_bChooseBig )
  596. {
  597. path=m_pPathArrayBigsize->ElementAt (m_pos);
  598. }
  599. ::LoadImageFromBuf (&m_pImage, path);
  600. if(m_pImage==NULL)
  601. {
  602. Bitmap *pNULLBmp=new Bitmap(100, 100, PixelFormat24bppRGB );
  603. Graphics graph2(pNULLBmp);
  604. graph2.Clear(Color(255,0,0,0));
  605. m_pImage=pNULLBmp;
  606. }
  607. if(m_pImage->GetWidth()==0)
  608. {
  609. m_bChooseBig=0;
  610. Unlock(handle);
  611. return;
  612. }
  613. InitRc();
  614. m_pImagesmall=m_pImage->GetThumbnailImage(m_rc.Width (), m_rc.Height (), NULL, NULL);
  615. Graphics graphic(m_pImagesmall);//防止GetThumbnailImage影响质量
  616. graphic.DrawImage(m_pImage, 0,0,m_pImagesmall->GetWidth(), m_pImagesmall->GetHeight() );
  617. int orientation=GetOrientation(m_pImage);
  618. if(orientation==8)
  619. { m_pImage->RotateFlip( Rotate270FlipNone );
  620. m_pImagesmall->RotateFlip( Rotate270FlipNone );
  621. }
  622. else if(orientation==6)
  623. {
  624. m_pImage->RotateFlip( Rotate90FlipNone );
  625. m_pImagesmall->RotateFlip( Rotate90FlipNone );
  626. }
  627. m_pImageArray.Add (m_pImage);
  628. m_pImageSmallArray.Add (m_pImagesmall);
  629. m_nPosArray.Add (m_pos);
  630. if(m_pImageArray.GetSize ()>10)
  631. {
  632. if(m_pImage!=m_pImageArray.ElementAt (0))
  633. {
  634. delete m_pImageArray.ElementAt (0);
  635. delete m_pImageSmallArray.ElementAt (0);
  636. m_pImageArray.RemoveAt(0);
  637. m_pImageSmallArray.RemoveAt(0);
  638. m_nPosArray.RemoveAt(0);
  639. }
  640. }
  641. m_bChooseBig=0;
  642. Unlock(handle);
  643. }
  644. else if(m_pImage==NULL)
  645. {
  646. SetTimer(5, 1, NULL);
  647. return ;
  648. }
  649. if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
  650. InitRc();
  651. if(m_bauto )
  652. {
  653. if(m_dlg.m_effect ==1 || m_dlg.m_effect ==2)
  654. {
  655. CDC *pDC=GetDC();
  656. HDC hdc=::GetDC(NULL);
  657. ::BitBlt (pDC->GetSafeHdc (), 0, 0, g_screenwid, g_screenhei , hdc, 0, 0, SRCCOPY);
  658. ReleaseDC(pDC);
  659. }
  660. m_dlg.m_time =m_PicBar.m_time*1000;
  661. m_dlg.SetImage (m_pImagesmall);
  662. if(m_dlg.m_effect ==1 || m_dlg.m_effect ==2)
  663. {
  664. m_dlg.ShowWindow (SW_HIDE);
  665. }
  666. m_dlg.ShowAlpha();
  667. }
  668. else
  669. {
  670. ShowInfo();
  671. Invalidate();
  672. }
  673. }
  674. catch(...)
  675. {
  676. }
  677. }
  678. void ShowPic22::OnLButtonDown(UINT nFlags, CPoint point)
  679. {
  680. // TODO: Add your message handler code here and/or call default
  681. SetCapture();
  682. m_startpt=m_startpt3=point;
  683. CDialog::OnLButtonDown(nFlags, point);
  684. }
  685. void ShowPic22::OnMouseMove(UINT nFlags, CPoint point)
  686. {
  687. // TODO: Add your message handler code here and/or call default
  688. if(GetCapture()!=this)return;
  689. if(m_rc.Width ()>m_rcscreen.Width ())
  690. {
  691. if(m_rc.left <m_rcscreen.left && point.x>m_startpt.x)
  692. {
  693. int dt=min(point.x-m_startpt.x, m_rcscreen.left-m_rc.left);
  694. m_rc.left +=dt;
  695. m_rc.right +=dt;
  696. }
  697. else if(m_rc.right >m_rcscreen.right && point.x<m_startpt.x)
  698. {
  699. int dt=min(m_startpt.x-point.x, m_rc.right-m_rcscreen.right);
  700. m_rc.left -=dt;
  701. m_rc.right -=dt;
  702. }m_startpt3=point;
  703. }
  704. if(m_rc.Height ()>m_rcscreen.Height ())
  705. {
  706. if(m_rc.top <m_rcscreen.top && point.y>m_startpt.y)
  707. {
  708. int dt=min(point.y-m_startpt.y, m_rcscreen.top-m_rc.top);
  709. m_rc.top +=dt;
  710. m_rc.bottom +=dt;
  711. }
  712. else if(m_rc.bottom >m_rcscreen.bottom && point.y<m_startpt.y)
  713. {
  714. int dt=min(m_startpt.y-point.y, m_rc.bottom-m_rcscreen.bottom);
  715. m_rc.top -=dt;
  716. m_rc.bottom -=dt;
  717. }m_startpt3=point;
  718. }
  719. m_startpt=point;
  720. Invalidate();
  721. CDialog::OnMouseMove(nFlags, point);
  722. }
  723. void ShowPic22::OnLButtonUp(UINT nFlags, CPoint point)
  724. {
  725. // TODO: Add your message handler code here and/or call default
  726. if(GetCapture()!=this)return;
  727. ReleaseCapture();
  728. if(point.x-m_startpt3.x>30)
  729. Next();
  730. else if(m_startpt3.x-point.x>30)
  731. Pre();
  732. CDialog::OnLButtonUp(nFlags, point);
  733. }
  734. BOOL ShowPic22::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  735. {
  736. // TODO: Add your message handler code here and/or call default
  737. if(m_pImage==NULL)return 1;
  738. if(m_bauto)return 1;if(m_bProcessing)return 1;
  739. m_bScroll=1;
  740. if(zDelta>0)
  741. {
  742. // if(m_fscale>4)return 1;
  743. m_fscale*=1.2;
  744. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  745. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  746. m_rc.left -=dtx;
  747. m_rc.right +=dtx;
  748. m_rc.top -=dty;
  749. m_rc.bottom +=dty;
  750. Invalidate();
  751. }
  752. else
  753. {
  754. if(m_fscale<=1)return 1;
  755. m_fscale/=1.2;
  756. if(m_fscale<1)m_fscale=1;
  757. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  758. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  759. m_rc.left -=dtx;
  760. m_rc.right +=dtx;
  761. m_rc.top -=dty;
  762. m_rc.bottom +=dty;
  763. if(m_rcbak.Height ()==m_rcscreen.Height ())
  764. {
  765. if(m_rc.top <m_rcscreen.top && m_rc.bottom < m_rcscreen.bottom )
  766. {
  767. dtx=m_rcscreen.bottom -m_rc.bottom;
  768. m_rc.top +=dtx;
  769. m_rc.bottom +=dtx;
  770. }
  771. else if(m_rc.top >m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom )
  772. {
  773. dtx=m_rc.top-m_rcscreen.top;
  774. m_rc.top -=dtx;
  775. m_rc.bottom -=dtx;
  776. }
  777. dtx=m_rc.Width ();
  778. m_rc.left =(m_rcscreen.Width ()-dtx)/2;
  779. m_rc.right =m_rc.left +dtx;
  780. }
  781. if(m_rcbak.Width ()==m_rcscreen.Width ())
  782. {
  783. if(m_rc.left <m_rcscreen.left && m_rc.right < m_rcscreen.right )
  784. {
  785. dtx=m_rcscreen.right -m_rc.right;
  786. m_rc.left +=dtx;
  787. m_rc.right +=dtx;
  788. }
  789. else if(m_rc.left >m_rcscreen.left && m_rc.right > m_rcscreen.right )
  790. {
  791. dtx=m_rc.left-m_rcscreen.left;
  792. m_rc.left -=dtx;
  793. m_rc.right -=dtx;
  794. }
  795. dtx=m_rc.Height ();
  796. m_rc.top =(m_rcscreen.Height ()-dtx)/2;
  797. m_rc.bottom =m_rc.top +dtx;
  798. }
  799. Invalidate();
  800. /* int dtx=(m_fscale-1)*m_rcbak.Width ()/2.0;
  801. int dty=(m_fscale-1)*m_rcbak.Height ()/2.0;
  802. m_rc=m_rcbak;
  803. m_rc.left -=dtx;
  804. m_rc.right +=dtx;
  805. m_rc.top -=dty;
  806. m_rc.bottom +=dty;
  807. Invalidate();*/
  808. }
  809. KillTimer(2);
  810. SetTimer(2, 100, NULL);
  811. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  812. }
  813. BOOL ShowPic22::PreTranslateMessage(MSG* pMsg)
  814. {
  815. // TODO: Add your specialized code here and/or call the base class
  816. if(pMsg->message==WM_MOUSEMOVE )
  817. { if(m_bShowEffect)return 1;
  818. if(m_PicBar.m_bInit && m_pImage)
  819. {
  820. CPoint point;
  821. ::GetCursorPos (&point);
  822. if( abs(m_startpt2.x -point.x )>5 || abs(m_startpt2.y -point.y )>5)
  823. {
  824. m_startpt2=point;
  825. m_PicBar.ShowWindow (SW_SHOW);
  826. SetTimer(3, 1500, NULL);
  827. }
  828. }
  829. }
  830. else if(pMsg->message==WM_KEYDOWN )
  831. { if(m_bShowEffect)return 1;
  832. switch (pMsg->wParam)
  833. {
  834. case VK_RETURN:
  835. return 1;
  836. case VK_ESCAPE:
  837. KillTimer(6);
  838. SetTimer(6, 100, NULL);
  839. return 1;
  840. case VK_F2:
  841. return 1;
  842. if(m_pParent==NULL)return 1;
  843. if(m_pParent->m_mode2)return 1;
  844. if(m_bShowEffect)return 1;
  845. if(m_bauto)
  846. {
  847. m_bauto=0;
  848. KillTimer(1);
  849. m_dlg.TerminateThread ();
  850. m_dlg.ShowWindow (SW_HIDE);
  851. }
  852. if(m_pImage)
  853. {
  854. m_bShowEffect=1;
  855. CutPhoto2();
  856. // ShowEffectDlg dlg;
  857. // dlg.DoModal();
  858. m_bShowEffect=0;
  859. }
  860. return 1;
  861. case VK_F3:
  862. AutoPic();
  863. break;
  864. case VK_UP:
  865. Rotate1();
  866. return 1;
  867. case VK_PRIOR:
  868. case VK_LEFT:
  869. Pre();
  870. return 1;
  871. case VK_DOWN:
  872. Rotate2();
  873. return 1;
  874. case VK_RIGHT:
  875. case VK_NEXT:
  876. Next();
  877. return 1;
  878. case VK_SHIFT:
  879. {
  880. if(m_bauto)return 1;if(m_bProcessing)return 1;
  881. if(m_pPathArrayBigsize && m_bChooseBig==0 )
  882. {
  883. HANDLE handle=Lock("shgenimagethread");
  884. for(int n=0; n<m_nPosArray.GetSize (); n++)
  885. {
  886. if(m_pos==m_nPosArray.ElementAt (n))
  887. {
  888. delete m_pImageArray.ElementAt (n);
  889. delete m_pImageSmallArray.ElementAt (n);
  890. m_pImageArray.RemoveAt(n);
  891. m_pImageSmallArray.RemoveAt(n);
  892. m_nPosArray.RemoveAt(n);
  893. break;
  894. }
  895. }
  896. Unlock(handle);
  897. m_bChooseBig=1;
  898. LoadImage();
  899. }
  900. }
  901. return 1;
  902. case VK_DELETE:
  903. if(m_bauto)return 1;
  904. if(m_pParent)
  905. {
  906. if(m_bProcessing)return 1;
  907. m_bProcessing=1;
  908. ::SetForegroundWindow (m_hWnd);
  909. if(m_pParent)
  910. {
  911. for(int i=0; i<m_pParent->m_List1.GetItemCount (); i++)
  912. {
  913. m_pParent->m_List1.SetItemState (i, 0, -1);
  914. }
  915. m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
  916. }
  917. // HANDLE handle=Lock("shgenimagethread");
  918. if(m_pParent->OnDel())
  919. {
  920. TerminateThread();
  921. ::SetForegroundWindow (m_hWnd);
  922. m_pImage=m_pImagesmall=NULL;
  923. for(int n=m_nPosArray.GetSize ()-1; n>=0; n--)
  924. {
  925. //if(m_pos==m_nPosArray.ElementAt (n))
  926. {
  927. delete m_pImageArray.ElementAt (n);
  928. delete m_pImageSmallArray.ElementAt (n);
  929. m_pImageArray.RemoveAt(n);
  930. m_pImageSmallArray.RemoveAt(n);
  931. m_nPosArray.RemoveAt(n);
  932. }
  933. }
  934. if(m_pPathArrayBigsize)
  935. {
  936. m_pPathArrayBigsize->RemoveAll();
  937. m_pPathArray->RemoveAll();
  938. CStringArray *pArray=m_pParent->GetCurArray();
  939. m_pPathArrayBigsize->Copy(*pArray);
  940. for(int i=0; i<m_pPathArrayBigsize->GetSize(); i++)
  941. {
  942. CString str=m_pPathArrayBigsize->ElementAt(i);
  943. CString spath=str.Left (str.ReverseFind ('\\')+1);
  944. spath+="m";
  945. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  946. if(::PathFileExists(spath))
  947. m_pPathArray->Add(spath);
  948. else
  949. m_pPathArray->Add(str);
  950. }
  951. }
  952. if(m_pos>=this->m_pPathArray->GetSize ())
  953. m_pos=0;
  954. // Unlock(handle);
  955. RunPicThread();
  956. LoadImage();
  957. m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
  958. }
  959. m_bProcessing=0;
  960. return 1;
  961. }
  962. }
  963. ::SetForegroundWindow (m_hWnd);
  964. }
  965. return CDialog::PreTranslateMessage(pMsg);
  966. }
  967. void ShowPic22::OnRButtonDown(UINT nFlags, CPoint point)
  968. {
  969. // TODO: Add your message handler code here and/or call default
  970. if(m_bauto)return;if(m_bProcessing)return;
  971. if(m_pParent)
  972. {
  973. for(int i=0; i<m_pParent->m_List1.GetItemCount (); i++)
  974. {
  975. m_pParent->m_List1.SetItemState (i, 0, -1);
  976. }
  977. m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
  978. m_pParent->OnRclickList1();
  979. }
  980. CDialog::OnRButtonDown(nFlags, point);
  981. }
  982. void ShowPic22::AutoPic()
  983. {
  984. try
  985. {
  986. if(m_bProcessing)return;
  987. m_dlg.m_effect=m_PicBar.m_nType;
  988. m_bauto=!m_bauto;
  989. m_PicBar.ChangeBtn();
  990. if(m_bauto)
  991. { m_PreviewDlg.ShowMin();
  992. if(m_pos>=this->m_pPathArray->GetSize ())
  993. m_pos=0;
  994. LoadImage();
  995. }
  996. else
  997. {
  998. KillTimer(1);
  999. m_dlg.TerminateThread ();
  1000. m_dlg.ShowWindow (SW_HIDE);
  1001. }
  1002. ::SetForegroundWindow (m_hWnd);
  1003. }
  1004. catch(...)
  1005. {
  1006. }
  1007. }
  1008. void ShowPic22::OnTimer(UINT nIDEvent)
  1009. {
  1010. // TODO: Add your message handler code here and/or call default
  1011. try
  1012. {if(m_bShowEffect)return;
  1013. ::SetForegroundWindow (m_hWnd);
  1014. if(nIDEvent==1)
  1015. {
  1016. KillTimer(1);
  1017. m_pos++;
  1018. if(m_pos>=this->m_pPathArray->GetSize ())
  1019. {
  1020. KillTimer(1);
  1021. m_dlg.TerminateThread ();
  1022. m_dlg.ShowWindow (SW_HIDE);
  1023. m_PicBar.ChangeBtn();
  1024. AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
  1025. m_bauto=0; m_bProcessing=0;
  1026. m_pos-=2;Next();
  1027. return;
  1028. }
  1029. LoadImage();
  1030. }
  1031. else if(nIDEvent==2)
  1032. {
  1033. KillTimer(2);
  1034. if(m_pImagetemp)
  1035. {
  1036. if(m_rc.Width ()>m_pImagetemp->GetWidth())
  1037. {
  1038. if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
  1039. m_pImagetemp=m_pImage->GetThumbnailImage(min(m_pImage->GetWidth(),m_rc.Width ()), min(m_pImage->GetHeight(),m_rc.Height ()), NULL, NULL);
  1040. Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
  1041. graphic.DrawImage(m_pImage, 0,0,m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight() );
  1042. }
  1043. }
  1044. else
  1045. {
  1046. m_pImagetemp=m_pImage->GetThumbnailImage(min(m_pImage->GetWidth(),m_rc.Width ()), min(m_pImage->GetHeight(),m_rc.Height ()), NULL, NULL);
  1047. Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
  1048. graphic.DrawImage(m_pImage, 0,0,m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight() );
  1049. }
  1050. Invalidate();
  1051. }
  1052. else if(nIDEvent==3)
  1053. {
  1054. KillTimer(3);
  1055. CPoint pt;
  1056. ::GetCursorPos (&pt);
  1057. if(m_picbarrc.PtInRect (pt))
  1058. {
  1059. SetTimer(3, 1500, NULL);
  1060. }
  1061. else
  1062. m_PicBar.ShowWindow (SW_HIDE);
  1063. ::SetForegroundWindow (m_hWnd);
  1064. }
  1065. else if(nIDEvent==4)
  1066. {
  1067. KillTimer(4);
  1068. m_PicBar.SetLiaPath ("4.lia");
  1069. m_PicBar.Create (IDD_DLGmydlg, this);
  1070. if(m_PicBar.m_bInit)
  1071. {
  1072. m_PicBar.m_pParent =this;
  1073. int hei;
  1074. m_PicBar.GetWindowRect (m_picbarrc);
  1075. hei=m_picbarrc.Height ();
  1076. m_picbarrc.bottom =g_screenhei-10;
  1077. m_picbarrc.top =m_picbarrc.bottom-hei;
  1078. m_PicBar.MoveWindow (m_picbarrc);
  1079. SetTimer(3, 1500, NULL);
  1080. m_startpt2.x=m_startpt2.y=0;
  1081. }
  1082. ::SetForegroundWindow (m_hWnd);
  1083. }
  1084. else if(nIDEvent==5)
  1085. {
  1086. KillTimer(5);
  1087. LoadImage();
  1088. }
  1089. else if(nIDEvent==6)
  1090. {
  1091. if(m_bProcessing)return;
  1092. m_bProcessing=1;
  1093. g_nSendCode=0;
  1094. TerminateThread();
  1095. m_dlg.TerminateThread();
  1096. CDialog::OnOK ();
  1097. m_bProcessing=0;
  1098. }
  1099. }
  1100. catch(...)
  1101. {
  1102. }
  1103. }
  1104. void ShowPic22::OnClose()
  1105. {
  1106. // TODO: Add your message handler code here and/or call default
  1107. if(m_pParent)
  1108. {
  1109. if(m_bProcessing)return;
  1110. m_bProcessing=1;
  1111. {
  1112. TerminateThread();
  1113. ::SetForegroundWindow (m_hWnd);
  1114. m_pImage=m_pImagesmall=NULL;
  1115. for(int n=m_nPosArray.GetSize ()-1; n>=0; n--)
  1116. {
  1117. delete m_pImageArray.ElementAt (n);
  1118. delete m_pImageSmallArray.ElementAt (n);
  1119. m_pImageArray.RemoveAt(n);
  1120. m_pImageSmallArray.RemoveAt(n);
  1121. m_nPosArray.RemoveAt(n);
  1122. }
  1123. if(m_pPathArrayBigsize)
  1124. {
  1125. m_pPathArrayBigsize->RemoveAll();
  1126. m_pPathArray->RemoveAll();
  1127. CStringArray *pArray=m_pParent->GetCurArray();
  1128. m_pPathArrayBigsize->Copy(*pArray);
  1129. for(int i=0; i<m_pPathArrayBigsize->GetSize(); i++)
  1130. {
  1131. CString str=m_pPathArrayBigsize->ElementAt(i);
  1132. CString spath=str.Left (str.ReverseFind ('\\')+1);
  1133. spath+="m";
  1134. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  1135. if(::PathFileExists(spath))
  1136. m_pPathArray->Add(spath);
  1137. else
  1138. m_pPathArray->Add(str);
  1139. }
  1140. }
  1141. if(m_pos>=this->m_pPathArray->GetSize ())
  1142. m_pos=0;
  1143. if(this->m_pPathArray->GetSize ()==0)
  1144. {
  1145. m_bProcessing=0;
  1146. KillTimer(6);
  1147. SetTimer(6, 100, NULL);
  1148. }
  1149. else
  1150. {
  1151. RunPicThread();
  1152. LoadImage();
  1153. }
  1154. }
  1155. m_bProcessing=0;
  1156. }
  1157. }
  1158. void ShowPic22::InitRc()
  1159. {
  1160. try
  1161. {
  1162. if(m_pImage==NULL)return;
  1163. CRect rc;
  1164. GetClientRect(rc);
  1165. m_rc=rc;
  1166. int width,height;
  1167. if(m_pImagesmall)
  1168. {
  1169. width=m_pImagesmall->GetWidth();
  1170. height=m_pImagesmall->GetHeight();
  1171. }
  1172. else
  1173. {
  1174. width=m_pImage->GetWidth();
  1175. height=m_pImage->GetHeight();
  1176. }
  1177. //////////
  1178. float fscale=(float)width/(float)height;
  1179. float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
  1180. int rcwid=m_rc.Width ();
  1181. int rchei=m_rc.Height ();
  1182. int dt=0;
  1183. if(rcscale<fscale)
  1184. {
  1185. dt=(rchei-rcwid/fscale)/2;
  1186. m_rc.top+=dt;
  1187. m_rc.bottom-=dt;
  1188. }
  1189. else
  1190. {
  1191. dt=(rcwid-rchei*fscale)/2;
  1192. m_rc.left +=dt;
  1193. m_rc.right-=dt;
  1194. }
  1195. m_rcbak=m_rc;
  1196. }
  1197. catch(...)
  1198. {
  1199. }
  1200. }
  1201. void ShowPic22::Rotate1()
  1202. {
  1203. if(m_bauto)return;if(m_bProcessing)return;
  1204. try
  1205. {
  1206. if(m_pImage)
  1207. {
  1208. m_pImage->RotateFlip( Rotate270FlipNone );
  1209. if(m_pImagesmall) m_pImagesmall->RotateFlip( Rotate270FlipNone );
  1210. if(m_pImagetemp) m_pImagetemp->RotateFlip( Rotate270FlipNone );
  1211. InitRc();
  1212. Invalidate();
  1213. }
  1214. }
  1215. catch(...)
  1216. {
  1217. }
  1218. }
  1219. void ShowPic22::Rotate2()
  1220. {
  1221. if(m_bauto)return;if(m_bProcessing)return;
  1222. try
  1223. {
  1224. if(m_pImage)
  1225. {
  1226. m_pImage->RotateFlip( Rotate90FlipNone );
  1227. if(m_pImagesmall) m_pImagesmall->RotateFlip( Rotate90FlipNone );
  1228. if(m_pImagetemp) m_pImagetemp->RotateFlip( Rotate90FlipNone );
  1229. InitRc();
  1230. Invalidate();
  1231. }
  1232. }
  1233. catch(...)
  1234. {
  1235. }
  1236. }
  1237. void ShowPic22::Pre()
  1238. {
  1239. if(m_bauto)return;if(m_bProcessing)return;
  1240. m_bInit=1;
  1241. try
  1242. {
  1243. {
  1244. m_pos--;
  1245. if(m_pos<0)
  1246. m_pos=this->m_pPathArray->GetSize ()-1;
  1247. m_bChooseBig=0;
  1248. LoadImage();m_PreviewDlg.ShowPic(m_pos);
  1249. }
  1250. }
  1251. catch(...)
  1252. {
  1253. }
  1254. }
  1255. void ShowPic22::Next()
  1256. {
  1257. if(m_bauto)return;if(m_bProcessing)return;
  1258. m_bInit=1;
  1259. try
  1260. {
  1261. {
  1262. m_pos++;
  1263. if(m_pos>=this->m_pPathArray->GetSize ())
  1264. {
  1265. m_pos=0; AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
  1266. }
  1267. m_bChooseBig=0;
  1268. LoadImage();
  1269. m_PreviewDlg.ShowPic(m_pos);
  1270. }
  1271. }
  1272. catch(...)
  1273. {
  1274. }
  1275. }
  1276. void ShowPic22::SetEffect(int effect)
  1277. {
  1278. ::SetForegroundWindow (m_hWnd);
  1279. m_dlg.m_effect=effect;
  1280. }
  1281. void ShowPic22::TerminateThread()
  1282. {
  1283. try
  1284. {
  1285. if ( m_bRunning )
  1286. {
  1287. m_bTerminate=true;
  1288. for( ; ; )
  1289. {
  1290. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  1291. break;
  1292. MSG msg;
  1293. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  1294. {
  1295. if (!AfxGetApp()->PumpMessage())
  1296. break;
  1297. }
  1298. }
  1299. ::CloseHandle(m_hThread);
  1300. }
  1301. }
  1302. catch(...)
  1303. {
  1304. }
  1305. }
  1306. void ShowPic22::InitRc(Image *img, CRect &rc)
  1307. {
  1308. try
  1309. {
  1310. if(img==NULL)return;
  1311. CRect rc2;
  1312. GetClientRect(rc2);
  1313. rc=rc2;
  1314. int width,height;
  1315. width=img->GetWidth();
  1316. height=img->GetHeight();
  1317. //////////
  1318. float fscale=(float)width/(float)height;
  1319. float rcscale=((float)rc.Width ())/((float)rc.Height ());
  1320. int rcwid=rc.Width ();
  1321. int rchei=rc.Height ();
  1322. int dt=0;
  1323. if(rcscale<fscale)
  1324. {
  1325. dt=(rchei-rcwid/fscale)/2;
  1326. rc.top+=dt;
  1327. rc.bottom-=dt;
  1328. }
  1329. else
  1330. {
  1331. dt=(rcwid-rchei*fscale)/2;
  1332. rc.left +=dt;
  1333. rc.right-=dt;
  1334. }
  1335. }
  1336. catch(...)
  1337. {
  1338. }
  1339. }
  1340. HBRUSH ShowPic22::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  1341. {
  1342. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  1343. // TODO: Change any attributes of the DC here
  1344. if(nCtlColor==CTLCOLOR_STATIC)
  1345. {
  1346. pDC->SetBkMode (TRANSPARENT);
  1347. pDC->SetTextColor (RGB(255,255,255));
  1348. return (HBRUSH)::GetStockObject(NULL_BRUSH);
  1349. }
  1350. // TODO: Return a different brush if the default is not desired
  1351. return hbr;
  1352. }
  1353. void ShowPic22::RunPicThread()
  1354. {
  1355. if(m_pPathArray->GetSize ()==0)return;//2011-03-09
  1356. TerminateThread();
  1357. m_hThread = (HANDLE)_beginthreadex(NULL,0, GenThumbImgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  1358. m_bRunning=true;
  1359. }
  1360. void ShowPic22::OnMouseWheel2(BOOL bZoomOut)
  1361. {
  1362. if(m_pImage==NULL)return ;
  1363. if(m_bauto)return ;if(m_bProcessing)return ;
  1364. m_bScroll=1;
  1365. if(bZoomOut)
  1366. {
  1367. // if(m_fscale>4)return 1;
  1368. m_fscale*=1.2;
  1369. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  1370. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  1371. m_rc.left -=dtx;
  1372. m_rc.right +=dtx;
  1373. m_rc.top -=dty;
  1374. m_rc.bottom +=dty;
  1375. Invalidate();
  1376. }
  1377. else
  1378. {
  1379. if(m_fscale<=1)return ;
  1380. m_fscale/=1.2;
  1381. if(m_fscale<1)m_fscale=1;
  1382. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  1383. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  1384. m_rc.left -=dtx;
  1385. m_rc.right +=dtx;
  1386. m_rc.top -=dty;
  1387. m_rc.bottom +=dty;
  1388. if(m_rcbak.Height ()==m_rcscreen.Height ())
  1389. {
  1390. if(m_rc.top <m_rcscreen.top && m_rc.bottom < m_rcscreen.bottom )
  1391. {
  1392. dtx=m_rcscreen.bottom -m_rc.bottom;
  1393. m_rc.top +=dtx;
  1394. m_rc.bottom +=dtx;
  1395. }
  1396. else if(m_rc.top >m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom )
  1397. {
  1398. dtx=m_rc.top-m_rcscreen.top;
  1399. m_rc.top -=dtx;
  1400. m_rc.bottom -=dtx;
  1401. }
  1402. dtx=m_rc.Width ();
  1403. m_rc.left =(m_rcscreen.Width ()-dtx)/2;
  1404. m_rc.right =m_rc.left +dtx;
  1405. }
  1406. if(m_rcbak.Width ()==m_rcscreen.Width ())
  1407. {
  1408. if(m_rc.left <m_rcscreen.left && m_rc.right < m_rcscreen.right )
  1409. {
  1410. dtx=m_rcscreen.right -m_rc.right;
  1411. m_rc.left +=dtx;
  1412. m_rc.right +=dtx;
  1413. }
  1414. else if(m_rc.left >m_rcscreen.left && m_rc.right > m_rcscreen.right )
  1415. {
  1416. dtx=m_rc.left-m_rcscreen.left;
  1417. m_rc.left -=dtx;
  1418. m_rc.right -=dtx;
  1419. }
  1420. dtx=m_rc.Height ();
  1421. m_rc.top =(m_rcscreen.Height ()-dtx)/2;
  1422. m_rc.bottom =m_rc.top +dtx;
  1423. }
  1424. Invalidate();
  1425. }
  1426. KillTimer(2);
  1427. SetTimer(2, 100, NULL);
  1428. }
  1429. long ShowPic22::ShowInfo2(WPARAM inWParam, LPARAM inLParam)
  1430. {
  1431. if(inWParam==1)
  1432. {
  1433. if(m_bauto)AutoPic();
  1434. return 1;
  1435. }
  1436. ShowInfo();
  1437. return 1;
  1438. }
  1439. void ShowPic22::ShowInfo()
  1440. {
  1441. Invalidate();
  1442. if(m_bShowName)
  1443. {
  1444. CString str= m_pPathArray->ElementAt (m_pos);
  1445. str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  1446. str=str.Left (str.GetLength ()-4);
  1447. str.TrimLeft("m");
  1448. str="编号:"+str+" ";
  1449. if(m_pParent)
  1450. str+=m_pParent->GetZSInfo(m_pos);
  1451. SetDlgItemText(IDC_STATIC2, str);
  1452. }
  1453. }
  1454. void ShowPic22::CutPhoto2()
  1455. {
  1456. if(m_pParent==NULL)return;
  1457. CutPhoto dlg;
  1458. CString path=m_pPathArray->ElementAt (m_pos);
  1459. if(m_pPathArrayBigsize)path=m_pPathArrayBigsize->ElementAt (m_pos);
  1460. path=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
  1461. path=path.Left (path.Find ("."));
  1462. dlg.m_path=path;
  1463. dlg.m_photowidth=m_pImage->GetWidth();
  1464. dlg.m_photoheight=m_pImage->GetHeight();
  1465. dlg.m_pImg=m_pImagesmall;
  1466. dlg.m_id=m_pParent->m_strOrderNumber;
  1467. dlg.DoModal();
  1468. }
  1469. void ShowPic22::CutPhoto3()
  1470. {
  1471. if(m_pParent==NULL)return;
  1472. if(m_pParent->m_mode2)return;
  1473. if(m_bShowEffect)return;
  1474. if(m_bauto)
  1475. {
  1476. m_bauto=0;
  1477. KillTimer(1);
  1478. m_dlg.TerminateThread ();
  1479. m_dlg.ShowWindow (SW_HIDE);
  1480. }
  1481. if(m_pImage)
  1482. {
  1483. m_bShowEffect=1;
  1484. CutPhoto2();
  1485. // ShowEffectDlg dlg;
  1486. // dlg.DoModal();
  1487. m_bShowEffect=0;
  1488. }
  1489. }