ShowCut.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. // ShowCut.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShowCut.h"
  6. #include "JPEG.h"
  7. #include "MyLock.h"
  8. #include "ShowPhoto.h"
  9. #define THUMBNAIL_WIDTH 100
  10. #define THUMBNAIL_HEIGHT 90
  11. ShowCut::ShowCut(CWnd* pParent /*=NULL*/): CDialog(ShowCut::IDD, pParent)
  12. {
  13. m_bTerminate = false;
  14. m_bRunning = false;
  15. m_hThread = NULL;
  16. m_mode = 0;
  17. }
  18. void ShowCut::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialog::DoDataExchange(pDX);
  21. DDX_Control(pDX, IDC_LIST1, m_List1);
  22. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  23. }
  24. BEGIN_MESSAGE_MAP(ShowCut, CDialog)
  25. ON_WM_DESTROY()
  26. ON_BN_CLICKED(IDC_BUTdelall, OnBUTdelall)
  27. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  28. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
  29. END_MESSAGE_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // ShowCut message handlers
  32. BOOL ShowCut::OnInitDialog()
  33. {
  34. CDialog::OnInitDialog();
  35. CRect rc2;
  36. GetWindowRect(rc2);
  37. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  38. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  39. GetClientRect(rc2);
  40. if (m_mode == 0)
  41. rc2.top += 35 * g_fscaley;
  42. else
  43. {
  44. GetDlgItem(IDC_BUTdelall)->ShowWindow(0);
  45. GetDlgItem(IDC_BUTdel)->ShowWindow(0);
  46. GetDlgItem(IDOK)->ShowWindow(0);
  47. }
  48. m_List1.MoveWindow(rc2);
  49. int right = rc2.right;
  50. GetDlgItem(IDOK)->GetWindowRect(rc2);
  51. ScreenToClient(rc2);
  52. int hei = rc2.Height();
  53. int dtx = right - rc2.right - 5;
  54. rc2.top = 5;
  55. rc2.bottom = rc2.top + hei;
  56. rc2.left += dtx;
  57. rc2.right += dtx;
  58. GetDlgItem(IDOK)->MoveWindow(rc2);
  59. GetDlgItem(IDC_BUTdel)->GetWindowRect(rc2);
  60. ScreenToClient(rc2);
  61. rc2.top = 5;
  62. rc2.bottom = rc2.top + hei;
  63. rc2.left += dtx;
  64. rc2.right += dtx;
  65. GetDlgItem(IDC_BUTdel)->MoveWindow(rc2);
  66. GetDlgItem(IDC_BUTdelall)->GetWindowRect(rc2);
  67. ScreenToClient(rc2);
  68. rc2.top = 5;
  69. rc2.bottom = rc2.top + hei;
  70. rc2.left += dtx;
  71. rc2.right += dtx;
  72. GetDlgItem(IDC_BUTdelall)->MoveWindow(rc2);
  73. if (GetSize() == 0)
  74. {
  75. CDialog::OnCancel();
  76. return 0;
  77. }
  78. if (g_bAllBranch)
  79. {
  80. CString branchpath = GetBranchPhotoPath(m_branch);
  81. m_path = g_path1 + branchpath + "\\";
  82. }
  83. else
  84. m_path = g_path1 + "\\";
  85. m_path += m_strOrderNum;
  86. m_path += "\\";
  87. m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  88. m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
  89. LoadPhotos();
  90. return TRUE;
  91. }
  92. unsigned __stdcall LoadThumbNail15(LPVOID lpParam)
  93. {
  94. try
  95. {
  96. ShowCut *pDlg = (ShowCut*)lpParam;
  97. CListCtrl *ListCtrl = &pDlg->m_List1;
  98. CImageList* pImgList = &pDlg->m_ImageListThumb;
  99. // reset our image list
  100. for (int i = 0; i < pImgList->GetImageCount(); i++)
  101. pImgList->Remove(i);
  102. // remove all items from list view
  103. ListCtrl->DeleteAllItems();
  104. pImgList->SetImageCount(pDlg->m_vFileName.size());
  105. TCHAR path[MAX_PATH];
  106. vector<CString>::iterator iter;
  107. // Set redraw to FALSE to avoid flickering during adding new items
  108. ListCtrl->SetRedraw(FALSE);
  109. int nIndex = 0;
  110. CString str, spath;
  111. for (iter = pDlg->m_vFileName.begin(); iter != pDlg->m_vFileName.end() && pDlg->m_bTerminate != true; iter++, nIndex++)
  112. {
  113. ListCtrl->InsertItem(nIndex, pDlg->m_titlearray.ElementAt(nIndex), nIndex);
  114. }
  115. ListCtrl->SetRedraw(TRUE);
  116. ListCtrl->Invalidate();
  117. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  118. int XDest, YDest, nDestWidth, nDestHeight;
  119. nIndex = 0;
  120. SolidBrush whitebrush(Color(255, 255, 255, 255));
  121. for (iter = pDlg->m_vFileName.begin(); iter != pDlg->m_vFileName.end() && pDlg->m_bTerminate != true; iter++, nIndex++)
  122. {
  123. // Load Image File
  124. Image *image = NULL;
  125. Bitmap *pBmp = NULL;
  126. str = *iter;
  127. spath = str.Left(str.ReverseFind('\\') + 1);
  128. spath += "s";
  129. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  130. if (PathFileExists(spath))
  131. ::LoadImageFromBuf(&image, spath);
  132. else
  133. ::LoadImageFromBuf(&image, str);
  134. int orientation = GetOrientation(image);
  135. if (orientation == 8)
  136. image->RotateFlip(Rotate270FlipNone);
  137. else if (orientation == 6)
  138. image->RotateFlip(Rotate90FlipNone);
  139. if (image->GetWidth() == 0)
  140. continue;
  141. // Calculate Rect to fit to canvas
  142. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  143. if (fImgRatio > fRatio)
  144. {
  145. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  146. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  147. YDest = 0;
  148. nDestHeight = THUMBNAIL_HEIGHT;
  149. }
  150. else
  151. {
  152. XDest = 0;
  153. nDestWidth = THUMBNAIL_WIDTH;
  154. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  155. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  156. }
  157. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  158. Graphics graph2(pBmp);
  159. graph2.Clear(Color(255, 192, 192, 192));
  160. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  161. Graphics graph(pBmp);
  162. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  163. // Draw Image
  164. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  165. float scale = (float)nDestWidth / (float)image->GetWidth();
  166. int pos = pDlg->FindArray2(pDlg->m_titlearray.ElementAt(nIndex));
  167. if (pos != -1)
  168. {
  169. int nIndex = pos;
  170. CRect rc = pDlg->m_rcarray.ElementAt(nIndex);
  171. int wid = pDlg->m_widtharray.ElementAt(nIndex).left;
  172. int hei = pDlg->m_widtharray.ElementAt(nIndex).top;
  173. scale *= (float)image->GetWidth() / (float)wid;
  174. rc.left *= scale;
  175. rc.right *= scale;
  176. rc.top *= scale;
  177. rc.bottom *= scale;
  178. rc.left += XDest;
  179. rc.right += XDest;
  180. rc.top += YDest;
  181. rc.bottom += YDest;
  182. Pen blackPen(Color(255, 255, 0, 0), 1);
  183. graph.DrawRectangle(&blackPen, rc.left, rc.top, rc.Width(), rc.Height());
  184. }
  185. delete image;
  186. // Attach to Bitmap and Replace image in CImageList
  187. CBitmap bitmap;
  188. HBITMAP hbmp;
  189. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  190. bitmap.Attach(hbmp);
  191. pImgList->Replace(nIndex, &bitmap, NULL);
  192. delete pBmp;
  193. // Redraw only a current item for removing flickering and fast speed.
  194. ListCtrl->RedrawItems(nIndex, nIndex);
  195. // Release used DC and Object
  196. }
  197. ListCtrl->Invalidate();
  198. pDlg->m_bRunning = false;
  199. pDlg->m_bTerminate = false;
  200. _endthreadex(0);
  201. return 0;
  202. }
  203. catch (...)
  204. {
  205. }
  206. return true;
  207. }
  208. void ShowCut::LoadThumbImages()
  209. {
  210. TerminateThread();
  211. m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail15, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  212. m_bRunning = true;
  213. }
  214. BOOL ShowCut::TerminateThread()
  215. {
  216. if (!m_bRunning)
  217. return TRUE;
  218. m_bTerminate = true;
  219. for (;;)
  220. {
  221. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  222. break;
  223. MSG msg;
  224. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  225. {
  226. if (!AfxGetApp()->PumpMessage())
  227. break;
  228. }
  229. }
  230. ::CloseHandle(m_hThread);
  231. return TRUE;
  232. }
  233. void ShowCut::OnDestroy()
  234. {
  235. TerminateThread();
  236. CDialog::OnDestroy();
  237. }
  238. void ShowCut::LoadPhotos()
  239. {
  240. if (m_bRunning)
  241. return;
  242. #ifdef USE_KERNEL_DLL
  243. DWORD dwMemSize = 0;
  244. CStringArray AryLoadExtImgpath;
  245. CStringArray AryWithExtImgpath;
  246. CStringArray AryOrderDirectory;
  247. CString strBranchId = g_branchname.IsEmpty() ? g_domain : GetDomainFromBranch(g_branchname);
  248. INT i = 0;
  249. INT nSize = 0;
  250. INT nIndex = 0;
  251. CString str;
  252. CString strfilename;
  253. CStringArray AryImgNums;
  254. CStringArray AryCropName;
  255. AryImgNums.Copy(m_noarray);
  256. AryCropName.Copy(m_namearray);
  257. if ( GetOrderImgpathEx(EImgtype, strBranchId, m_strOrderNum, TRUE, _T("*.jpg|*.jpeg"), _T(""), AryLoadExtImgpath, AryWithExtImgpath, AryOrderDirectory))
  258. {// 先查找初修片;
  259. m_patharray1.RemoveAll();
  260. nSize = AryLoadExtImgpath.GetSize();
  261. for (i = 0; i < nSize; i++ )
  262. {
  263. // 过滤小图和中图;
  264. str = AryLoadExtImgpath.ElementAt(i);
  265. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  266. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  267. str.MakeLower();
  268. strfilename = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  269. if (strfilename.Find(_T(".")) != -1)
  270. {
  271. strfilename = strfilename.Left(strfilename.Find(_T(".")));
  272. do
  273. {
  274. nIndex = FindArray(&AryImgNums, strfilename);
  275. if ( nIndex != -1 )
  276. {// 是要显示的裁剪相片;
  277. m_patharray1.Add(str);
  278. m_titlearray.Add(strfilename + _T("\r\n") + AryCropName.ElementAt(nIndex));
  279. AryCropName.RemoveAt(nIndex);
  280. AryImgNums.RemoveAt(nIndex);
  281. }
  282. } while ( FindArray(&AryImgNums, strfilename) != -1 );
  283. }
  284. }
  285. }
  286. // 查找完初修片后,再次查找原片;
  287. AryLoadExtImgpath.RemoveAll();
  288. AryWithExtImgpath.RemoveAll();
  289. AryOrderDirectory.RemoveAll();
  290. if ( GetOrderImgpathEx(OImgtype, strBranchId, m_strOrderNum, TRUE, _T("*.jpg|*.jpeg"), _T(""), AryLoadExtImgpath, AryWithExtImgpath, AryOrderDirectory))
  291. {// 查找原片;
  292. nSize = AryLoadExtImgpath.GetSize();
  293. for (i = 0; i < nSize; i++ )
  294. {
  295. str = AryLoadExtImgpath.ElementAt(i);
  296. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  297. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  298. str.MakeLower();
  299. strfilename = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  300. if (strfilename.Find(_T(".")) != -1)
  301. {
  302. strfilename = strfilename.Left(strfilename.Find(_T(".")));
  303. do
  304. {
  305. nIndex = FindArray(&AryImgNums, strfilename);
  306. if ( nIndex != -1 )
  307. {// 是要显示的裁剪相片;
  308. m_patharray1.Add(str);
  309. m_titlearray.Add(strfilename + _T("\r\n") + AryCropName.ElementAt(nIndex));
  310. AryCropName.RemoveAt(nIndex);
  311. AryImgNums.RemoveAt(nIndex);
  312. }
  313. } while ( FindArray(&AryImgNums, strfilename) != -1 );
  314. }
  315. }
  316. }
  317. CStringArray *pArray = &m_patharray1;
  318. m_vFileName.clear();
  319. for ( i = 0; i < pArray->GetSize(); i++)
  320. {
  321. CString filePath = pArray->ElementAt(i);
  322. filePath.MakeLower();
  323. m_vFileName.push_back(filePath);
  324. }
  325. if (m_vFileName.size())
  326. LoadThumbImages();
  327. #else
  328. m_patharray1.RemoveAll();
  329. m_path.MakeLower();
  330. CStringArray dirarray;
  331. CString str, path2, no;
  332. if (1)
  333. {
  334. using namespace helper_coffs;
  335. ffsco o;
  336. o.dirs(1);
  337. o.find(LPCSTR(m_path), LPCSTR("*.*"));
  338. ffsco::typeT coo;
  339. ffsco::typeT::iterator it;
  340. coo = o.co_dir();
  341. for (it = coo.begin();coo.end() != it;it++)
  342. {
  343. str = (*it).c_str();
  344. str.MakeLower();
  345. if (str == m_path)continue;
  346. if (FindArray(&dirarray, str) == -1)
  347. {
  348. dirarray.Add(str);
  349. }
  350. }
  351. }
  352. if (1)
  353. {
  354. for (int i = 0; i < dirarray.GetSize(); i++)
  355. {
  356. using namespace helper_coffs;
  357. ffsco o;
  358. o.dirs(1);
  359. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  360. ffsco::typeT coo;
  361. ffsco::typeT::iterator it;
  362. coo = o.co_file();
  363. for (it = coo.begin();coo.end() != it;it++)
  364. {
  365. str = (*it).c_str();
  366. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  367. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  368. str.MakeLower();
  369. path2 = str;
  370. path2.Replace("客户原片", "修好的片");
  371. int pos1 = path2.Find(m_strOrderNum);
  372. pos1 += m_strOrderNum.GetLength();
  373. int pos2 = path2.ReverseFind('\\');
  374. path2 = path2.Left(pos1) + path2.Right(path2.GetLength() - pos2);
  375. no = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  376. no = no.Left(no.Find("."));
  377. CStringArray noarray, namearray;
  378. noarray.Copy(m_noarray);
  379. namearray.Copy(m_namearray);
  380. int pos = ::FindArray(&noarray, no);
  381. while (pos != -1)
  382. {
  383. if (::PathFileExists(path2))
  384. {
  385. m_patharray1.Add(path2);
  386. }
  387. else
  388. {
  389. m_patharray1.Add(str);
  390. }
  391. m_titlearray.Add(no + "\r\n" + namearray.ElementAt(pos));
  392. noarray.RemoveAt(pos); namearray.RemoveAt(pos);
  393. pos = ::FindArray(&noarray, no);
  394. }
  395. }
  396. }
  397. }
  398. if (m_patharray1.GetSize() == 0 && m_mode)
  399. {
  400. if (m_mode == 2)
  401. AfxMessageBox("无照片裁剪!");
  402. CDialog::OnCancel();
  403. return;
  404. }
  405. CStringArray *pArray = &m_patharray1;
  406. m_vFileName.clear();
  407. for (int i = 0; i < pArray->GetSize(); i++)
  408. {
  409. CString filePath = pArray->ElementAt(i);
  410. filePath.MakeLower();
  411. m_vFileName.push_back(filePath);
  412. }
  413. LoadThumbImages();
  414. #endif
  415. }
  416. void ShowCut::OnBUTdelall()
  417. {
  418. if (AfxMessageBox("清除裁剪后将无法恢复, 确认清除吗?", MB_YESNO | MB_ICONSTOP) != IDYES)
  419. return;
  420. CString sql;
  421. sql.Format("update dindan set size='' where id='%s'", m_strOrderNum);
  422. g_sendhead.bsql = 1;
  423. if (m_branch != "" && g_bAllBranch)
  424. {
  425. g_branchip = GetIP(m_branch);
  426. g_pMainWnd->OnDisconnect();
  427. g_branchname = m_branch;
  428. g_bBranchModify = 1;
  429. g_pMainWnd->ProcessChatMessageRequest2(sql);
  430. g_pMainWnd->OnDisconnect();
  431. g_bBranchModify = 0;
  432. g_branchip = g_branchname = "";
  433. }
  434. else
  435. g_pMainWnd->ProcessChatMessageRequest2(sql);
  436. if (g_bSendOK == 0)return;
  437. AfxMessageBox("保存成功!");
  438. GetSize();
  439. LoadPhotos();
  440. }
  441. void ShowCut::OnBUTdel()
  442. {
  443. POSITION pos;
  444. pos = m_List1.GetFirstSelectedItemPosition();
  445. if (pos == NULL)
  446. {
  447. AfxMessageBox("请先选中您要清除裁剪的照片!", MB_ICONINFORMATION);
  448. return;
  449. }
  450. if (AfxMessageBox("清除裁剪后将无法恢复, 确认清除吗?", MB_YESNO | MB_ICONSTOP) != IDYES)return;
  451. int iItem = m_List1.GetNextSelectedItem(pos);
  452. CString title = m_List1.GetItemText(iItem, 0);
  453. CString no = title.Left(title.Find("\r"));
  454. CString name = title.Right(title.GetLength() - title.ReverseFind('\n') - 1);
  455. {
  456. CString header = no + ":" + name + ",";
  457. int pos = m_size.Find(header);
  458. if (pos != -1)
  459. {
  460. CString left, right;
  461. left = m_size.Left(pos);
  462. m_size = m_size.Right(m_size.GetLength() - pos - header.GetLength());
  463. pos = m_size.Find(";");
  464. right = m_size.Right(m_size.GetLength() - pos - 1);
  465. m_size = left + right;
  466. }
  467. }
  468. CString sql;
  469. sql.Format("update dindan set size='%s' where id='%s'", m_size, m_strOrderNum);
  470. g_sendhead.bsql = 1;
  471. if (m_branch != "" && g_bAllBranch)
  472. {
  473. g_branchip = GetIP(m_branch);
  474. g_pMainWnd->OnDisconnect();
  475. g_branchname = m_branch;
  476. g_bBranchModify = 1;
  477. g_pMainWnd->ProcessChatMessageRequest2(sql);
  478. g_pMainWnd->OnDisconnect();
  479. g_bBranchModify = 0;
  480. g_branchip = g_branchname = "";
  481. }
  482. else
  483. g_pMainWnd->ProcessChatMessageRequest2(sql);
  484. if (g_bSendOK == 0)return;
  485. AfxMessageBox("保存成功!");
  486. GetSize();
  487. LoadPhotos();
  488. }
  489. void ShowCut::AddSize(CString size)
  490. {
  491. int pos = size.Find(":");
  492. if (pos != -1)
  493. {
  494. CString str;
  495. CRect rc;
  496. str = size.Left(pos);
  497. // 添加相片名称;
  498. m_noarray.Add(str);
  499. str = size.Right(size.GetLength() - pos - 1);
  500. pos = str.Find(",");
  501. // 添加裁剪方案名;
  502. m_namearray.Add(str.Left(pos));
  503. str.Delete(0, pos + 1);
  504. pos = str.Find(",");
  505. rc.left = atoi(str.Left(pos)); str.Delete(0, pos + 1);
  506. pos = str.Find(",");
  507. rc.top = atoi(str.Left(pos)); str.Delete(0, pos + 1);
  508. m_widtharray.Add(rc);
  509. pos = str.Find(",");
  510. rc.left = atoi(str.Left(pos)); str.Delete(0, pos + 1);
  511. pos = str.Find(",");
  512. rc.top = atoi(str.Left(pos)); str.Delete(0, pos + 1);
  513. pos = str.Find(",");
  514. rc.right = atoi(str.Left(pos)); str.Delete(0, pos + 1);
  515. rc.bottom = atoi(str);
  516. // 添加裁剪坐标;
  517. m_rcarray.Add(rc);
  518. }
  519. }
  520. BOOL ShowCut::GetSize() // 获取裁剪的相片坐标;
  521. {
  522. g_sendhead.bsql = 0;
  523. g_sendhead.code[0] = 11;
  524. g_sendhead.tabcount = 1;
  525. CString filter = "id='" + m_strOrderNum + "';";
  526. if (m_branch != "")
  527. {
  528. g_branchip = GetIP(m_branch);
  529. g_pMainWnd->OnDisconnect();
  530. g_branchname = m_branch;
  531. g_bBranchModify = 1;
  532. g_pMainWnd->ProcessChatMessageRequest2(filter);
  533. g_pMainWnd->OnDisconnect();
  534. g_bBranchModify = 0;
  535. g_branchip = g_branchname = "";
  536. }
  537. else
  538. g_pMainWnd->ProcessChatMessageRequest2(filter);
  539. if (g_bSendOK == 0)
  540. {
  541. return 0;
  542. }
  543. CArray<CStringArray, CStringArray>m_List1array;
  544. DataToArray(&m_List1array);
  545. CenterWindow();
  546. m_noarray.RemoveAll();
  547. m_widtharray.RemoveAll();
  548. m_rcarray.RemoveAll();
  549. if (m_List1array.GetSize())
  550. {
  551. m_size = m_List1array.ElementAt(0).ElementAt(60);//
  552. int pos = m_size.Find(";");
  553. while (pos != -1)
  554. {
  555. // 添加裁剪的相片;
  556. AddSize(m_size.Left(pos));
  557. m_size = m_size.Right(m_size.GetLength() - pos - 1);
  558. pos = m_size.Find(";");
  559. }
  560. m_size = m_List1array.ElementAt(0).ElementAt(60);
  561. return 1;
  562. }
  563. return 0;
  564. }
  565. int ShowCut::FindArray2(CString title)
  566. {
  567. CString no = title.Left(title.Find("\r"));
  568. CString name = title.Right(title.GetLength() - title.ReverseFind('\n') - 1);
  569. for (int i = 0; i < m_noarray.GetSize(); i++)
  570. {
  571. if (no == m_noarray.ElementAt(i) && name == m_namearray.ElementAt(i))
  572. return i;
  573. }
  574. return -1;
  575. }
  576. void ShowCut::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) // 双击裁剪小图查看大图效果;
  577. {
  578. POSITION pos;
  579. pos = m_List1.GetFirstSelectedItemPosition();
  580. if (pos == NULL)
  581. {
  582. return;
  583. }
  584. int iItem = m_List1.GetNextSelectedItem(pos);
  585. Image *image = NULL;
  586. if (m_patharray1.GetSize() <= iItem)return;
  587. CString str = m_patharray1.ElementAt(iItem);
  588. ::LoadImageFromBuf(&image, str);
  589. int orientation = GetOrientation(image);
  590. if (orientation == 8)
  591. image->RotateFlip(Rotate270FlipNone);
  592. else if (orientation == 6)
  593. image->RotateFlip(Rotate90FlipNone);
  594. if (image->GetWidth() == 0)
  595. return;
  596. Graphics graph(image);
  597. // Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  598. // Draw Image
  599. // graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
  600. float scale = 1.0;//(float)nDestWidth/(float)image->GetWidth();
  601. int pos2 = FindArray2(m_titlearray.ElementAt(iItem));
  602. if (pos2 != -1)
  603. {
  604. int nIndex = pos2;
  605. CRect rc = m_rcarray.ElementAt(nIndex);
  606. int wid = m_widtharray.ElementAt(nIndex).left;
  607. int hei = m_widtharray.ElementAt(nIndex).top;
  608. scale *= (float)image->GetWidth() / (float)wid;
  609. rc.left *= scale;
  610. rc.right *= scale;
  611. rc.top *= scale;
  612. rc.bottom *= scale;
  613. /* rc.left +=XDest ;
  614. rc.right +=XDest;
  615. rc.top +=YDest ;
  616. rc.bottom +=YDest ;*/
  617. Pen blackPen(Color(255, 255, 0, 0), 1);
  618. graph.DrawRectangle(&blackPen, rc.left, rc.top, rc.Width(), rc.Height());
  619. ShowPhoto dlg;
  620. dlg.m_pImg = image;
  621. dlg.DoModal();
  622. }
  623. delete image;
  624. *pResult = 0;
  625. }