ReplaceDesignNo.cpp 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. // ReplaceDesignNo.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ReplaceDesignNo.h"
  6. #include "ShowPic22.h"
  7. #include "JPEG.h"
  8. #include "SetDesignNo.h"
  9. #define THUMBNAIL_WIDTH 80
  10. #define THUMBNAIL_HEIGHT 70
  11. /////////////////////////////////////////////////////////////////////////////
  12. // ReplaceDesignNo dialog IDC_BU Tdelall
  13. ReplaceDesignNo::ReplaceDesignNo(CWnd* pParent /*=NULL*/)
  14. : CDialog(ReplaceDesignNo::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(ReplaceDesignNo)
  17. m_replace = _T("");
  18. //}}AFX_DATA_INIT
  19. m_bTerminate = false;
  20. m_bRunning = false;
  21. m_hThread = NULL;
  22. m_bTerminate2 = false;
  23. m_bRunning2 = false;
  24. m_hThread2 = NULL;
  25. m_image = NULL;
  26. }
  27. void ReplaceDesignNo::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(ReplaceDesignNo)
  31. DDX_Control(pDX, IDC_LIST5, m_List5);
  32. DDX_Control(pDX, IDC_LIST4, m_List4);
  33. DDX_Control(pDX, IDC_LIST1, m_List1);
  34. DDX_Text(pDX, IDC_EDIT1, m_replacesingle);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(ReplaceDesignNo, CDialog)
  38. //{{AFX_MSG_MAP(ReplaceDesignNo)
  39. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
  40. ON_WM_DESTROY()
  41. ON_NOTIFY(NM_DBLCLK, IDC_LIST4, OnDblclkList4)
  42. ON_WM_CTLCOLOR()
  43. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  44. ON_NOTIFY(NM_CLICK, IDC_LIST4, OnClickList4)
  45. ON_WM_PAINT()
  46. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  47. ON_WM_LBUTTONUP()
  48. ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST4, OnBegindragList4)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // ReplaceDesignNo message handlers
  53. extern BOOL CALLBACK EnumChildProc2(HWND hwnd, LPARAM lParam);
  54. BOOL ReplaceDesignNo::OnInitDialog()
  55. {
  56. CDialog::OnInitDialog();
  57. CRect rc2, rc;
  58. GetWindowRect(rc2);
  59. rc = CRect(0, 0, g_screenwid, g_screenhei);
  60. ::SetWindowPos(m_hWnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
  61. g_WidthScale2 = (float)rc.Width() / (float)rc2.Width(); // new/Old
  62. g_HeightScale2 = (float)rc.Height() / (float)rc2.Height();
  63. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc2, 0);
  64. GetDlgItem(IDC_STATIC1)->GetWindowRect(rc2);
  65. rc2.right -= rc2.left;
  66. rc2.bottom -= rc2.top;
  67. rc2.left = rc2.top = 0;
  68. GetDlgItem(IDC_STATIC1)->MoveWindow(rc2);
  69. GetDlgItem(IDC_STATIC2)->MoveWindow(rc2);
  70. // GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  71. // ScreenToClient(rc);
  72. // rc.top =rc2.bottom ;
  73. /// GetDlgItem(IDC_STATIC3)->MoveWindow(rc);
  74. CString str;
  75. str = "\r\n 功能简介:客人选设计过程中,按照客人要求将原设计版上的照片替换成客人喜欢的照片\r\n 1. 点选左侧要替换的一张设计版,此设计版所用照片将出现在右侧,如果没有设置,可点'重设照片'按钮设置照片.\r\n 2. 在右下方全部客人原片区选中客人喜欢的目标照片拖放至上方需要替换的照片上\r\n 3. 重复前两步全部替换完成后点击保存";
  76. GetDlgItem(IDC_STATIC1)->SetWindowText(str);
  77. m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  78. m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
  79. m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  80. m_List4.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL);
  81. m_ImageListThumb3.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  82. m_List5.SetImageList(&m_ImageListThumb3, LVSIL_NORMAL);
  83. CString filter = "id='" + m_id + "'";
  84. g_sendhead.code[0] = 11;
  85. g_sendhead.tabcount = 1;
  86. g_sendhead.bsql = 0;
  87. g_pMainWnd->ProcessChatMessageRequest2(filter);
  88. if (g_bSendOK == 0)
  89. {
  90. CDialog::OnCancel();
  91. return 0;
  92. }
  93. DataToArray(&g_List1array);
  94. if (g_List1array.GetSize())
  95. {
  96. m_designno = g_List1array.ElementAt(0).ElementAt(58);
  97. m_replace = g_List1array.ElementAt(0).ElementAt(59);
  98. }
  99. LoadPhotos();
  100. return TRUE; // return TRUE unless you set the focus to a control
  101. // EXCEPTION: OCX Property Pages should return FALSE
  102. }
  103. unsigned __stdcall LoadThumbNail13(LPVOID lpParam)
  104. {
  105. try
  106. {
  107. ReplaceDesignNo *pDlg = (ReplaceDesignNo*)lpParam;
  108. CListCtrl *ListCtrl = &pDlg->m_List1;
  109. CImageList* pImgList = &pDlg->m_ImageListThumb;
  110. // reset our image list
  111. for (int i = 0; i < pImgList->GetImageCount(); i++)
  112. pImgList->Remove(i);
  113. // remove all items from list view
  114. ListCtrl->DeleteAllItems();
  115. pImgList->SetImageCount(pDlg->m_vFileName.size());
  116. TCHAR path[MAX_PATH];
  117. vector<CString>::iterator iter;
  118. // Set redraw to FALSE to avoid flickering during adding new items
  119. ListCtrl->SetRedraw(FALSE);
  120. int nIndex = 0;
  121. CString str, spath;
  122. for (iter = pDlg->m_vFileName.begin(); iter != pDlg->m_vFileName.end() && pDlg->m_bTerminate != true; iter++, nIndex++)
  123. {
  124. str = *iter;
  125. spath.Empty();
  126. if (str.Left(str.ReverseFind('\\') + 1) != pDlg->m_path2)
  127. {
  128. spath = str.Left(str.ReverseFind('\\') + 1);
  129. spath = spath.Right(spath.GetLength() - pDlg->m_path2.GetLength());
  130. }
  131. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  132. str = spath + str.Left(str.GetLength() - 4);
  133. ListCtrl->InsertItem(nIndex, str, nIndex);
  134. }
  135. ListCtrl->SetRedraw(TRUE);
  136. ListCtrl->Invalidate();
  137. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  138. int XDest, YDest, nDestWidth, nDestHeight;
  139. nIndex = 0;
  140. SolidBrush whitebrush(Color(255, 255, 255, 255));
  141. for (iter = pDlg->m_vFileName.begin(); iter != pDlg->m_vFileName.end() && pDlg->m_bTerminate != true; iter++, nIndex++)
  142. {
  143. // Load Image File
  144. Image *image = NULL;
  145. Bitmap *pBmp = NULL;
  146. str = *iter;
  147. spath = str.Left(str.ReverseFind('\\') + 1);
  148. spath += "s";
  149. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  150. if (PathFileExists(spath))
  151. ::LoadImageFromBuf(&image, spath);
  152. else
  153. ::LoadImageFromBuf(&image, str);
  154. int orientation = GetOrientation(image);
  155. if (orientation == 8)
  156. image->RotateFlip(Rotate270FlipNone);
  157. else if (orientation == 6)
  158. image->RotateFlip(Rotate90FlipNone);
  159. if (image->GetWidth() == 0)
  160. continue;
  161. // Calculate Rect to fit to canvas
  162. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  163. if (fImgRatio > fRatio)
  164. {
  165. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  166. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  167. YDest = 0;
  168. nDestHeight = THUMBNAIL_HEIGHT;
  169. }
  170. else
  171. {
  172. XDest = 0;
  173. nDestWidth = THUMBNAIL_WIDTH;
  174. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  175. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  176. }
  177. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  178. Graphics graph2(pBmp);
  179. graph2.Clear(Color(255, 192, 192, 192));
  180. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  181. Graphics graph(pBmp);
  182. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  183. // Draw Image
  184. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  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. }
  207. unsigned __stdcall LoadThumbNail14(LPVOID lpParam)
  208. {
  209. try
  210. {
  211. ReplaceDesignNo *pDlg = (ReplaceDesignNo*)lpParam;
  212. CImageList* pImgList = &pDlg->m_ImageListThumb2;
  213. CListCtrl *ListCtrl = &pDlg->m_List4;
  214. // reset our image list
  215. for (int i = 0; i < pImgList->GetImageCount(); i++)
  216. pImgList->Remove(i);
  217. // remove all items from list view
  218. ListCtrl->DeleteAllItems();
  219. pImgList->SetImageCount(pDlg->m_vFileName2.size());
  220. TCHAR path[MAX_PATH];
  221. vector<CString>::iterator iter;
  222. // Set redraw to FALSE to avoid flickering during adding new items
  223. ListCtrl->SetRedraw(FALSE);
  224. int nIndex = 0;
  225. CString str, spath;
  226. for (iter = pDlg->m_vFileName2.begin(); iter != pDlg->m_vFileName2.end() && pDlg->m_bTerminate2 != true; iter++, nIndex++)
  227. {
  228. str = *iter;
  229. spath.Empty();
  230. if (str.Left(str.ReverseFind('\\') + 1) != pDlg->m_path)
  231. {
  232. spath = str.Left(str.ReverseFind('\\') + 1);
  233. spath = spath.Right(spath.GetLength() - pDlg->m_path.GetLength());
  234. }
  235. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  236. str = spath + str.Left(str.GetLength() - 4);
  237. ListCtrl->InsertItem(nIndex, str, nIndex);
  238. }
  239. ListCtrl->SetRedraw(TRUE);
  240. ListCtrl->Invalidate();
  241. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  242. int XDest, YDest, nDestWidth, nDestHeight;
  243. nIndex = 0;
  244. SolidBrush whitebrush(Color(255, 255, 255, 255));
  245. for (iter = pDlg->m_vFileName2.begin(); iter != pDlg->m_vFileName2.end() && pDlg->m_bTerminate2 != true; iter++, nIndex++)
  246. {
  247. // Load Image File
  248. Image *image = NULL;
  249. Bitmap *pBmp = NULL;
  250. str = *iter;
  251. spath = str.Left(str.ReverseFind('\\') + 1);
  252. spath += "s";
  253. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  254. if (PathFileExists(spath))
  255. ::LoadImageFromBuf(&image, spath);
  256. else
  257. ::LoadImageFromBuf(&image, str);
  258. int orientation = GetOrientation(image);
  259. if (orientation == 8)
  260. image->RotateFlip(Rotate270FlipNone);
  261. else if (orientation == 6)
  262. image->RotateFlip(Rotate90FlipNone);
  263. if (image->GetWidth() == 0)
  264. continue;
  265. // Calculate Rect to fit to canvas
  266. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  267. if (fImgRatio > fRatio)
  268. {
  269. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  270. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  271. YDest = 0;
  272. nDestHeight = THUMBNAIL_HEIGHT;
  273. }
  274. else
  275. {
  276. XDest = 0;
  277. nDestWidth = THUMBNAIL_WIDTH;
  278. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  279. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  280. }
  281. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  282. Graphics graph2(pBmp);
  283. graph2.Clear(Color(255, 192, 192, 192));
  284. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  285. Graphics graph(pBmp);
  286. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  287. // Draw Image
  288. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  289. delete image;
  290. // Attach to Bitmap and Replace image in CImageList
  291. CBitmap bitmap;
  292. HBITMAP hbmp;
  293. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  294. bitmap.Attach(hbmp);
  295. pImgList->Replace(nIndex, &bitmap, NULL);
  296. delete pBmp;
  297. // Redraw only a current item for removing flickering and fast speed.
  298. ListCtrl->RedrawItems(nIndex, nIndex);
  299. // Release used DC and Object
  300. }
  301. ListCtrl->Invalidate();
  302. pDlg->m_bRunning2 = false;
  303. pDlg->m_bTerminate2 = false;
  304. _endthreadex(0);
  305. return 0;
  306. }
  307. catch (...)
  308. {
  309. }
  310. }
  311. void ReplaceDesignNo::LoadThumbImages()
  312. {
  313. TerminateThread();
  314. m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail13, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  315. m_bRunning = true;
  316. }
  317. BOOL ReplaceDesignNo::TerminateThread()
  318. {
  319. if (!m_bRunning)
  320. return TRUE;
  321. m_bTerminate = true;
  322. for (;;)
  323. {
  324. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  325. break;
  326. MSG msg;
  327. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  328. {
  329. if (!AfxGetApp()->PumpMessage())
  330. break;
  331. }
  332. }
  333. ::CloseHandle(m_hThread);
  334. return TRUE;
  335. }
  336. void ReplaceDesignNo::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
  337. {
  338. // TODO: Add your control notification handler code here
  339. POSITION pos;
  340. pos = m_List1.GetFirstSelectedItemPosition();
  341. if (pos == NULL)
  342. {
  343. return;
  344. }
  345. int iItem = m_List1.GetNextSelectedItem(pos);
  346. ShowPic22 dlg;
  347. dlg.m_pos = iItem;
  348. dlg.m_pPathArray = &m_patharray1;
  349. dlg.DoModal();
  350. *pResult = 0;
  351. }
  352. void ReplaceDesignNo::OnDestroy()
  353. {
  354. if (m_image)delete m_image; m_image = NULL;
  355. TerminateThread(); TerminateThread2(); CDialog::OnDestroy();
  356. // TODO: Add your message handler code here
  357. }
  358. void ReplaceDesignNo::LoadPhotos()
  359. {
  360. m_path2 = g_path3 + "\\";
  361. m_path2 += m_id;
  362. m_path2 += "\\";
  363. m_patharray1.RemoveAll();
  364. m_path2.MakeLower();
  365. CStringArray dirarray;
  366. CString str;
  367. if (1)
  368. {
  369. using namespace helper_coffs;
  370. ffsco o;
  371. o.dirs(1);
  372. o.find(LPCSTR(m_path2), LPCSTR("*.*"));
  373. ffsco::typeT coo;
  374. ffsco::typeT::iterator it;
  375. coo = o.co_dir();
  376. for (it = coo.begin();
  377. coo.end() != it;
  378. it++)
  379. {
  380. str = (*it).c_str();
  381. if (FindArray(&dirarray, str) == -1)
  382. {
  383. dirarray.Add(str);
  384. }
  385. }
  386. }
  387. if (1)
  388. {
  389. for (int i = 0; i < dirarray.GetSize(); i++)
  390. {
  391. using namespace helper_coffs;
  392. ffsco o;
  393. o.dirs(0);
  394. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  395. ffsco::typeT coo;
  396. ffsco::typeT::iterator it;
  397. coo = o.co_file();
  398. for (it = coo.begin();
  399. coo.end() != it;
  400. it++)
  401. {
  402. str = (*it).c_str();
  403. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  404. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  405. str.MakeLower();
  406. m_patharray1.Add(str);
  407. }
  408. }
  409. }
  410. CStringArray *pArray = &m_patharray1;
  411. m_vFileName.clear();
  412. for (int i = 0; i < pArray->GetSize(); i++)
  413. {
  414. CString filePath = pArray->ElementAt(i);
  415. filePath.MakeLower();
  416. m_vFileName.push_back(filePath);
  417. }
  418. LoadThumbImages();
  419. /////////////
  420. m_path = g_path1 + "\\";
  421. m_path += m_id;
  422. m_path += "\\";
  423. m_patharray2.RemoveAll();
  424. m_path.MakeLower();
  425. dirarray.RemoveAll();
  426. if (1)
  427. {
  428. using namespace helper_coffs;
  429. ffsco o;
  430. o.dirs(1);
  431. o.find(LPCSTR(m_path), LPCSTR("*.*"));
  432. ffsco::typeT coo;
  433. ffsco::typeT::iterator it;
  434. coo = o.co_dir();
  435. for (it = coo.begin();
  436. coo.end() != it;
  437. it++)
  438. {
  439. str = (*it).c_str();
  440. if (FindArray(&dirarray, str) == -1)
  441. {
  442. dirarray.Add(str);
  443. }
  444. }
  445. }
  446. if (1)
  447. {
  448. for (int i = 0; i < dirarray.GetSize(); i++)
  449. {
  450. using namespace helper_coffs;
  451. ffsco o;
  452. o.dirs(0);
  453. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  454. ffsco::typeT coo;
  455. ffsco::typeT::iterator it;
  456. coo = o.co_file();
  457. for (it = coo.begin();
  458. coo.end() != it;
  459. it++)
  460. {
  461. str = (*it).c_str();
  462. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  463. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  464. str.MakeLower();
  465. m_patharray2.Add(str);
  466. }
  467. }
  468. }
  469. if (m_bRunning2)return;
  470. pArray = &m_patharray2;
  471. m_vFileName2.clear();
  472. for (i = 0; i < pArray->GetSize(); i++)
  473. {
  474. CString filePath = pArray->ElementAt(i);
  475. filePath.MakeLower();
  476. m_vFileName2.push_back(filePath);
  477. }
  478. TerminateThread2();
  479. m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail14, (LPVOID)this, 0, &m_dwThreadID2);
  480. m_bRunning2 = true;
  481. }
  482. BOOL ReplaceDesignNo::TerminateThread2()
  483. {
  484. if (!m_bRunning2)
  485. return TRUE;
  486. m_bTerminate2 = true;
  487. for (;;)
  488. {
  489. if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0)
  490. break;
  491. MSG msg;
  492. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  493. {
  494. if (!AfxGetApp()->PumpMessage())
  495. break;
  496. }
  497. }
  498. ::CloseHandle(m_hThread2);
  499. return TRUE;
  500. }
  501. void ReplaceDesignNo::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
  502. {
  503. // TODO: Add your control notification handler code here
  504. POSITION pos;
  505. pos = m_List4.GetFirstSelectedItemPosition();
  506. if (pos == NULL)
  507. {
  508. return;
  509. }
  510. int iItem = m_List4.GetNextSelectedItem(pos);
  511. ShowPic22 dlg;
  512. dlg.m_pos = iItem;
  513. dlg.m_pPathArray = &m_patharray2;
  514. dlg.DoModal();
  515. *pResult = 0;
  516. }
  517. HBRUSH ReplaceDesignNo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  518. {
  519. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  520. // TODO: Change any attributes of the DC here
  521. if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_STATIC1)
  522. {
  523. pDC->SetBkMode(TRANSPARENT); //设置字体背景为透明
  524. return (HBRUSH)::GetStockObject(WHITE_BRUSH); // 设置背景色
  525. }
  526. // TODO: Return a different brush if the default is not desired
  527. // TODO: Return a different brush if the default is not desired
  528. return hbr;
  529. }
  530. void ReplaceDesignNo::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  531. {
  532. // TODO: Add your control notification handler code here
  533. POSITION ppos;
  534. ppos = m_List1.GetFirstSelectedItemPosition();
  535. if (ppos == NULL)
  536. {
  537. return;
  538. }
  539. int iItem = m_List1.GetNextSelectedItem(ppos);
  540. CString title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  541. CString str, spath;
  542. if (m_image)delete m_image; m_image = NULL;
  543. str = m_patharray1.ElementAt(iItem);
  544. spath = str.Left(str.ReverseFind('\\') + 1);
  545. spath += "s";
  546. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  547. if (PathFileExists(spath))
  548. ::LoadImageFromBuf(&m_image, spath);
  549. else
  550. ::LoadImageFromBuf(&m_image, str);
  551. CRect rc;
  552. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  553. ScreenToClient(rc);
  554. InvalidateRect(rc);
  555. CString sel;
  556. int pos = m_designno.Find(title);
  557. if (pos != -1)
  558. {
  559. sel = m_designno.Right(m_designno.GetLength() - pos);
  560. sel = sel.Right(sel.GetLength() - title.GetLength());
  561. pos = sel.Find("$");
  562. if (pos != -1)
  563. sel = sel.Left(pos);
  564. sel.TrimLeft(",");
  565. sel.TrimRight(",");
  566. sel = "," + sel + ",";
  567. }
  568. CStringArray list5array;
  569. for (int i = 0; i < m_List4.GetItemCount(); i++)
  570. {
  571. title = "," + m_List4.GetItemText(i, 0) + ",";
  572. if (sel.Find(title) != -1)
  573. list5array.Add(m_patharray2.ElementAt(i));
  574. }
  575. try
  576. {
  577. ReplaceDesignNo *pDlg = (ReplaceDesignNo*)this;
  578. CListCtrl *ListCtrl = &pDlg->m_List5;
  579. CImageList* pImgList = &pDlg->m_ImageListThumb3;
  580. // reset our image list
  581. for (int i = 0; i < pImgList->GetImageCount(); i++)
  582. pImgList->Remove(i);
  583. // remove all items from list view
  584. ListCtrl->DeleteAllItems();
  585. pImgList->SetImageCount(list5array.GetSize());
  586. TCHAR path[MAX_PATH];
  587. // Set redraw to FALSE to avoid flickering during adding new items
  588. ListCtrl->SetRedraw(FALSE);
  589. int nIndex = 0;
  590. CString str, spath;
  591. for (i = 0; i < list5array.GetSize(); i++)
  592. {
  593. str = list5array.ElementAt(i);
  594. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  595. str = str.Left(str.GetLength() - 4);
  596. ListCtrl->InsertItem(nIndex, str, nIndex);
  597. }
  598. ListCtrl->SetRedraw(TRUE);
  599. ListCtrl->Invalidate();
  600. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  601. int XDest, YDest, nDestWidth, nDestHeight;
  602. nIndex = 0;
  603. SolidBrush whitebrush(Color(255, 255, 255, 255));
  604. for (i = 0; i < list5array.GetSize(); i++)
  605. {
  606. // Load Image File
  607. Image *image = NULL;
  608. Bitmap *pBmp = NULL;
  609. str = list5array.ElementAt(i);
  610. spath = str.Left(str.ReverseFind('\\') + 1);
  611. spath += "s";
  612. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  613. if (PathFileExists(spath))
  614. ::LoadImageFromBuf(&image, spath);
  615. else
  616. ::LoadImageFromBuf(&image, str);
  617. int orientation = GetOrientation(image);
  618. if (orientation == 8)
  619. image->RotateFlip(Rotate270FlipNone);
  620. else if (orientation == 6)
  621. image->RotateFlip(Rotate90FlipNone);
  622. if (image->GetWidth() == 0)
  623. continue;
  624. // Calculate Rect to fit to canvas
  625. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  626. if (fImgRatio > fRatio)
  627. {
  628. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  629. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  630. YDest = 0;
  631. nDestHeight = THUMBNAIL_HEIGHT;
  632. }
  633. else
  634. {
  635. XDest = 0;
  636. nDestWidth = THUMBNAIL_WIDTH;
  637. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  638. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  639. }
  640. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  641. Graphics graph2(pBmp);
  642. graph2.Clear(Color(255, 192, 192, 192));
  643. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  644. Graphics graph(pBmp);
  645. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  646. // Draw Image
  647. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  648. delete image;
  649. // Attach to Bitmap and Replace image in CImageList
  650. CBitmap bitmap;
  651. HBITMAP hbmp;
  652. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  653. bitmap.Attach(hbmp);
  654. pImgList->Replace(i, &bitmap, NULL);
  655. delete pBmp;
  656. // Redraw only a current item for removing flickering and fast speed.
  657. ListCtrl->RedrawItems(i, i);
  658. // Release used DC and Object
  659. }
  660. ListCtrl->Invalidate();
  661. }
  662. catch (...)
  663. {
  664. }
  665. {
  666. title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  667. int pos = m_replace.Find(title);
  668. if (pos != -1)
  669. {
  670. m_replacesingle = m_replace.Right(m_replace.GetLength() - pos);
  671. m_replacesingle.Delete(0, 1);
  672. pos = m_replacesingle.Find("$");
  673. if (pos != -1)
  674. m_replacesingle = m_replacesingle.Left(pos);
  675. m_replacesingle = "$" + m_replacesingle;
  676. }
  677. else
  678. m_replacesingle.Empty();
  679. UpdateData(false);
  680. }
  681. *pResult = 0;
  682. }
  683. void ReplaceDesignNo::OnOK()
  684. {
  685. // TODO: Add extra validation here
  686. CString sql = "update dindan set designreplaceno='" + m_replace + "' where id='" + m_id + "'";
  687. g_sendhead.bsql = 1;
  688. g_pMainWnd->ProcessChatMessageRequest2(sql);
  689. if (g_bSendOK == 0)return;
  690. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  691. }
  692. void ReplaceDesignNo::OnPaint()
  693. {
  694. CPaintDC dc(this); // device context for painting
  695. // TODO: Add your message handler code here
  696. if (m_image)
  697. {
  698. CRect rc;
  699. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  700. ScreenToClient(rc);
  701. RectFitDes(m_image->GetWidth(), m_image->GetHeight(), rc);
  702. Graphics dcgraph(dc.GetSafeHdc());
  703. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  704. dcgraph.DrawImage(m_image, destinationRect, 0, 0, m_image->GetWidth(), m_image->GetHeight(), UnitPixel);
  705. }
  706. // Do not call CDialog::OnPaint() for painting messages
  707. }
  708. void ReplaceDesignNo::OnButton2()
  709. {
  710. // TODO: Add your control notification handler code here
  711. SetDesignNo dlg;
  712. dlg.m_id = m_id;
  713. dlg.DoModal();
  714. CString filter = "id='" + m_id + "'";
  715. g_sendhead.code[0] = 11;
  716. g_sendhead.tabcount = 1;
  717. g_sendhead.bsql = 0;
  718. g_pMainWnd->ProcessChatMessageRequest2(filter);
  719. if (g_bSendOK == 0)
  720. {
  721. return;
  722. }
  723. DataToArray(&g_List1array);
  724. if (g_List1array.GetSize())
  725. {
  726. m_designno = g_List1array.ElementAt(0).ElementAt(58);
  727. }
  728. }
  729. void ReplaceDesignNo::OnClickList4(NMHDR* pNMHDR, LRESULT* pResult)
  730. {
  731. // TODO: Add your control notification handler code here
  732. *pResult = 0;
  733. }
  734. void ReplaceDesignNo::OnLButtonUp(UINT nFlags, CPoint point)
  735. {
  736. // TODO: Add your message handler code here and/or call default
  737. if (this == GetCapture())
  738. {
  739. ReleaseCapture();
  740. CRect rc;
  741. m_List5.GetWindowRect(rc);
  742. ScreenToClient(rc);
  743. if (rc.PtInRect(point))
  744. {
  745. point.x -= rc.left;
  746. point.y -= rc.top;
  747. POSITION ppos;
  748. // ppos=m_List5.GetFirstSelectedItemPosition();
  749. // if(ppos==NULL) return;
  750. int iItem = m_List5.HitTest(point);//m_List5.GetNextSelectedItem(ppos);
  751. if (iItem == -1)return;
  752. m_List5.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  753. CString curno = m_List5.GetItemText(iItem, 0);
  754. ppos = m_List1.GetFirstSelectedItemPosition();
  755. if (ppos == NULL) return;
  756. iItem = m_List1.GetNextSelectedItem(ppos);
  757. CString curtitle = m_List1.GetItemText(iItem, 0);
  758. ppos = m_List4.GetFirstSelectedItemPosition();
  759. if (ppos == NULL) return;
  760. iItem = m_List4.GetNextSelectedItem(ppos);
  761. CString curno2 = m_List4.GetItemText(iItem, 0);
  762. if (curno == curno2)return;
  763. CString title = "$" + curtitle + ":";
  764. CString replace = curno + "->" + curno2;
  765. CString temp;
  766. int pos = m_replace.Find(title);
  767. if (pos != -1)
  768. {
  769. CString oldreplace;
  770. temp = m_replace.Right(m_replace.GetLength() - pos - title.GetLength());
  771. int pos2 = temp.Find("$");
  772. if (pos2 != -1)
  773. {
  774. oldreplace = temp.Left(pos2);
  775. temp = temp.Right(temp.GetLength() - pos2);
  776. }
  777. else
  778. {
  779. oldreplace = temp;
  780. temp.Empty();
  781. }
  782. if (oldreplace.Find(replace) != -1)return;
  783. if (oldreplace.Find(curno + "->") == -1)
  784. {
  785. m_replace = m_replace.Left(pos + title.GetLength());
  786. if (oldreplace.IsEmpty())
  787. {
  788. m_replace += replace;
  789. }
  790. else
  791. {
  792. m_replace += oldreplace + ",";
  793. m_replace += replace;
  794. }
  795. m_replace += temp;
  796. }
  797. else//已存在
  798. {
  799. m_replace = m_replace.Left(pos + title.GetLength());
  800. pos = oldreplace.Find(curno + "->");
  801. CString oldreplaseno = oldreplace.Right(oldreplace.GetLength() - pos - 2 - curno.GetLength());
  802. pos = oldreplaseno.Find(",");
  803. if (pos != -1)
  804. oldreplaseno = oldreplaseno.Left(pos);
  805. CString replace2 = curno + "->" + oldreplaseno;
  806. oldreplace.Replace(replace2, replace);
  807. m_replace += oldreplace;
  808. m_replace += temp;
  809. }
  810. }
  811. else
  812. {
  813. m_replace += title;
  814. m_replace += replace;
  815. }
  816. pos = m_replace.Find(title);
  817. m_replacesingle = m_replace.Right(m_replace.GetLength() - pos);
  818. m_replacesingle.Delete(0, 1);
  819. pos = m_replacesingle.Find("$");
  820. if (pos != -1)
  821. m_replacesingle = m_replacesingle.Left(pos);
  822. m_replacesingle = "$" + m_replacesingle;
  823. UpdateData(false);
  824. }
  825. }
  826. CDialog::OnLButtonUp(nFlags, point);
  827. }
  828. void ReplaceDesignNo::OnBegindragList4(NMHDR* pNMHDR, LRESULT* pResult)
  829. {
  830. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  831. // TODO: Add your control notification handler code here
  832. POSITION ppos;
  833. ppos = m_List1.GetFirstSelectedItemPosition();
  834. if (ppos == NULL)
  835. {
  836. return;
  837. }
  838. ppos = m_List4.GetFirstSelectedItemPosition();
  839. if (ppos == NULL)
  840. {
  841. return;
  842. }
  843. SetCapture();
  844. *pResult = 0;
  845. }