ReplaceDesignNo.cpp 25 KB

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