ShowPic22.cpp 37 KB

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