ReplaceDesignNo.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. int i = 0;
  364. m_patharray1.RemoveAll();
  365. m_path2.MakeLower();
  366. CStringArray dirarray;
  367. CString str;
  368. if (1)
  369. {
  370. using namespace helper_coffs;
  371. ffsco o;
  372. o.dirs(1);
  373. o.find(LPCSTR(m_path2), LPCSTR("*.*"));
  374. ffsco::typeT coo;
  375. ffsco::typeT::iterator it;
  376. coo = o.co_dir();
  377. for (it = coo.begin();
  378. coo.end() != it;
  379. 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 (int 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();
  400. coo.end() != it;
  401. it++)
  402. {
  403. str = (*it).c_str();
  404. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  405. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  406. str.MakeLower();
  407. m_patharray1.Add(str);
  408. }
  409. }
  410. }
  411. CStringArray *pArray = &m_patharray1;
  412. m_vFileName.clear();
  413. for ( i = 0; i < pArray->GetSize(); i++)
  414. {
  415. CString filePath = pArray->ElementAt(i);
  416. filePath.MakeLower();
  417. m_vFileName.push_back(filePath);
  418. }
  419. LoadThumbImages();
  420. /////////////
  421. m_path = g_path1 + "\\";
  422. m_path += m_id;
  423. m_path += "\\";
  424. m_patharray2.RemoveAll();
  425. m_path.MakeLower();
  426. dirarray.RemoveAll();
  427. if (1)
  428. {
  429. using namespace helper_coffs;
  430. ffsco o;
  431. o.dirs(1);
  432. o.find(LPCSTR(m_path), LPCSTR("*.*"));
  433. ffsco::typeT coo;
  434. ffsco::typeT::iterator it;
  435. coo = o.co_dir();
  436. for (it = coo.begin();
  437. coo.end() != it;
  438. it++)
  439. {
  440. str = (*it).c_str();
  441. if (FindArray(&dirarray, str) == -1)
  442. {
  443. dirarray.Add(str);
  444. }
  445. }
  446. }
  447. if (1)
  448. {
  449. for ( i = 0; i < dirarray.GetSize(); i++)
  450. {
  451. using namespace helper_coffs;
  452. ffsco o;
  453. o.dirs(0);
  454. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  455. ffsco::typeT coo;
  456. ffsco::typeT::iterator it;
  457. coo = o.co_file();
  458. for (it = coo.begin();
  459. coo.end() != it;
  460. it++)
  461. {
  462. str = (*it).c_str();
  463. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  464. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  465. str.MakeLower();
  466. m_patharray2.Add(str);
  467. }
  468. }
  469. }
  470. if (m_bRunning2)return;
  471. pArray = &m_patharray2;
  472. m_vFileName2.clear();
  473. for (i = 0; i < pArray->GetSize(); i++)
  474. {
  475. CString filePath = pArray->ElementAt(i);
  476. filePath.MakeLower();
  477. m_vFileName2.push_back(filePath);
  478. }
  479. TerminateThread2();
  480. m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail14, (LPVOID)this, 0, &m_dwThreadID2);
  481. m_bRunning2 = true;
  482. }
  483. BOOL ReplaceDesignNo::TerminateThread2()
  484. {
  485. if (!m_bRunning2)
  486. return TRUE;
  487. m_bTerminate2 = true;
  488. for (;;)
  489. {
  490. if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0)
  491. break;
  492. MSG msg;
  493. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  494. {
  495. if (!AfxGetApp()->PumpMessage())
  496. break;
  497. }
  498. }
  499. ::CloseHandle(m_hThread2);
  500. return TRUE;
  501. }
  502. void ReplaceDesignNo::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
  503. {
  504. // TODO: Add your control notification handler code here
  505. POSITION pos;
  506. pos = m_List4.GetFirstSelectedItemPosition();
  507. if (pos == NULL)
  508. {
  509. return;
  510. }
  511. int iItem = m_List4.GetNextSelectedItem(pos);
  512. ShowPic22 dlg;
  513. dlg.m_pos = iItem;
  514. dlg.m_pPathArray = &m_patharray2;
  515. dlg.DoModal();
  516. *pResult = 0;
  517. }
  518. HBRUSH ReplaceDesignNo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  519. {
  520. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  521. // TODO: Change any attributes of the DC here
  522. if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_STATIC1)
  523. {
  524. pDC->SetBkMode(TRANSPARENT); //设置字体背景为透明
  525. return (HBRUSH)::GetStockObject(WHITE_BRUSH); // 设置背景色
  526. }
  527. // TODO: Return a different brush if the default is not desired
  528. // TODO: Return a different brush if the default is not desired
  529. return hbr;
  530. }
  531. void ReplaceDesignNo::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  532. {
  533. // TODO: Add your control notification handler code here
  534. int i = 0;
  535. POSITION ppos;
  536. ppos = m_List1.GetFirstSelectedItemPosition();
  537. if (ppos == NULL)
  538. {
  539. return;
  540. }
  541. int iItem = m_List1.GetNextSelectedItem(ppos);
  542. CString title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  543. CString str, spath;
  544. if (m_image)delete m_image; m_image = NULL;
  545. str = m_patharray1.ElementAt(iItem);
  546. spath = str.Left(str.ReverseFind('\\') + 1);
  547. spath += "s";
  548. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  549. if (PathFileExists(spath))
  550. ::LoadImageFromBuf(&m_image, spath);
  551. else
  552. ::LoadImageFromBuf(&m_image, str);
  553. CRect rc;
  554. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  555. ScreenToClient(rc);
  556. InvalidateRect(rc);
  557. CString sel;
  558. int pos = m_designno.Find(title);
  559. if (pos != -1)
  560. {
  561. sel = m_designno.Right(m_designno.GetLength() - pos);
  562. sel = sel.Right(sel.GetLength() - title.GetLength());
  563. pos = sel.Find("$");
  564. if (pos != -1)
  565. sel = sel.Left(pos);
  566. sel.TrimLeft(",");
  567. sel.TrimRight(",");
  568. sel = "," + sel + ",";
  569. }
  570. CStringArray list5array;
  571. for ( i = 0; i < m_List4.GetItemCount(); i++)
  572. {
  573. title = "," + m_List4.GetItemText(i, 0) + ",";
  574. if (sel.Find(title) != -1)
  575. list5array.Add(m_patharray2.ElementAt(i));
  576. }
  577. try
  578. {
  579. ReplaceDesignNo *pDlg = (ReplaceDesignNo*)this;
  580. CListCtrl *ListCtrl = &pDlg->m_List5;
  581. CImageList* pImgList = &pDlg->m_ImageListThumb3;
  582. // reset our image list
  583. for ( i = 0; i < pImgList->GetImageCount(); i++)
  584. pImgList->Remove(i);
  585. // remove all items from list view
  586. ListCtrl->DeleteAllItems();
  587. pImgList->SetImageCount(list5array.GetSize());
  588. TCHAR path[MAX_PATH];
  589. // Set redraw to FALSE to avoid flickering during adding new items
  590. ListCtrl->SetRedraw(FALSE);
  591. int nIndex = 0;
  592. CString str, spath;
  593. for (i = 0; i < list5array.GetSize(); i++)
  594. {
  595. str = list5array.ElementAt(i);
  596. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  597. str = str.Left(str.GetLength() - 4);
  598. ListCtrl->InsertItem(nIndex, str, nIndex);
  599. }
  600. ListCtrl->SetRedraw(TRUE);
  601. ListCtrl->Invalidate();
  602. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  603. int XDest, YDest, nDestWidth, nDestHeight;
  604. nIndex = 0;
  605. SolidBrush whitebrush(Color(255, 255, 255, 255));
  606. for (i = 0; i < list5array.GetSize(); i++)
  607. {
  608. // Load Image File
  609. Image *image = NULL;
  610. Bitmap *pBmp = NULL;
  611. str = list5array.ElementAt(i);
  612. spath = str.Left(str.ReverseFind('\\') + 1);
  613. spath += "s";
  614. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  615. if (PathFileExists(spath))
  616. ::LoadImageFromBuf(&image, spath);
  617. else
  618. ::LoadImageFromBuf(&image, str);
  619. int orientation = GetOrientation(image);
  620. if (orientation == 8)
  621. image->RotateFlip(Rotate270FlipNone);
  622. else if (orientation == 6)
  623. image->RotateFlip(Rotate90FlipNone);
  624. if (image->GetWidth() == 0)
  625. continue;
  626. // Calculate Rect to fit to canvas
  627. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  628. if (fImgRatio > fRatio)
  629. {
  630. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  631. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  632. YDest = 0;
  633. nDestHeight = THUMBNAIL_HEIGHT;
  634. }
  635. else
  636. {
  637. XDest = 0;
  638. nDestWidth = THUMBNAIL_WIDTH;
  639. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  640. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  641. }
  642. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  643. Graphics graph2(pBmp);
  644. graph2.Clear(Color(255, 192, 192, 192));
  645. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  646. Graphics graph(pBmp);
  647. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  648. // Draw Image
  649. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  650. delete image;
  651. // Attach to Bitmap and Replace image in CImageList
  652. CBitmap bitmap;
  653. HBITMAP hbmp;
  654. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  655. bitmap.Attach(hbmp);
  656. pImgList->Replace(i, &bitmap, NULL);
  657. delete pBmp;
  658. // Redraw only a current item for removing flickering and fast speed.
  659. ListCtrl->RedrawItems(i, i);
  660. // Release used DC and Object
  661. }
  662. ListCtrl->Invalidate();
  663. }
  664. catch (...)
  665. {
  666. }
  667. {
  668. title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  669. int pos = m_replace.Find(title);
  670. if (pos != -1)
  671. {
  672. m_replacesingle = m_replace.Right(m_replace.GetLength() - pos);
  673. m_replacesingle.Delete(0, 1);
  674. pos = m_replacesingle.Find("$");
  675. if (pos != -1)
  676. m_replacesingle = m_replacesingle.Left(pos);
  677. m_replacesingle = "$" + m_replacesingle;
  678. }
  679. else
  680. m_replacesingle.Empty();
  681. UpdateData(false);
  682. }
  683. *pResult = 0;
  684. }
  685. void ReplaceDesignNo::OnOK()
  686. {
  687. // TODO: Add extra validation here
  688. CString sql = "update dindan set designreplaceno='" + m_replace + "' where id='" + m_id + "'";
  689. g_sendhead.bsql = 1;
  690. g_pMainWnd->ProcessChatMessageRequest2(sql);
  691. if (g_bSendOK == 0)return;
  692. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  693. }
  694. void ReplaceDesignNo::OnPaint()
  695. {
  696. CPaintDC dc(this); // device context for painting
  697. // TODO: Add your message handler code here
  698. if (m_image)
  699. {
  700. CRect rc;
  701. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  702. ScreenToClient(rc);
  703. RectFitDes(m_image->GetWidth(), m_image->GetHeight(), rc);
  704. Graphics dcgraph(dc.GetSafeHdc());
  705. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  706. dcgraph.DrawImage(m_image, destinationRect, 0, 0, m_image->GetWidth(), m_image->GetHeight(), UnitPixel);
  707. }
  708. // Do not call CDialog::OnPaint() for painting messages
  709. }
  710. void ReplaceDesignNo::OnButton2()
  711. {
  712. // TODO: Add your control notification handler code here
  713. SetDesignNo dlg;
  714. dlg.m_id = m_id;
  715. dlg.DoModal();
  716. CString filter = "id='" + m_id + "'";
  717. g_sendhead.code[0] = 11;
  718. g_sendhead.tabcount = 1;
  719. g_sendhead.bsql = 0;
  720. g_pMainWnd->ProcessChatMessageRequest2(filter);
  721. if (g_bSendOK == 0)
  722. {
  723. return;
  724. }
  725. DataToArray(&g_List1array);
  726. if (g_List1array.GetSize())
  727. {
  728. m_designno = g_List1array.ElementAt(0).ElementAt(58);
  729. }
  730. }
  731. void ReplaceDesignNo::OnClickList4(NMHDR* pNMHDR, LRESULT* pResult)
  732. {
  733. // TODO: Add your control notification handler code here
  734. *pResult = 0;
  735. }
  736. void ReplaceDesignNo::OnLButtonUp(UINT nFlags, CPoint point)
  737. {
  738. // TODO: Add your message handler code here and/or call default
  739. if (this == GetCapture())
  740. {
  741. ReleaseCapture();
  742. CRect rc;
  743. m_List5.GetWindowRect(rc);
  744. ScreenToClient(rc);
  745. if (rc.PtInRect(point))
  746. {
  747. point.x -= rc.left;
  748. point.y -= rc.top;
  749. POSITION ppos;
  750. // ppos=m_List5.GetFirstSelectedItemPosition();
  751. // if(ppos==NULL) return;
  752. int iItem = m_List5.HitTest(point);//m_List5.GetNextSelectedItem(ppos);
  753. if (iItem == -1)return;
  754. m_List5.SetItemState(iItem, LVIS_SELECTED, LVIS_SELECTED);
  755. CString curno = m_List5.GetItemText(iItem, 0);
  756. ppos = m_List1.GetFirstSelectedItemPosition();
  757. if (ppos == NULL) return;
  758. iItem = m_List1.GetNextSelectedItem(ppos);
  759. CString curtitle = m_List1.GetItemText(iItem, 0);
  760. ppos = m_List4.GetFirstSelectedItemPosition();
  761. if (ppos == NULL) return;
  762. iItem = m_List4.GetNextSelectedItem(ppos);
  763. CString curno2 = m_List4.GetItemText(iItem, 0);
  764. if (curno == curno2)return;
  765. CString title = "$" + curtitle + ":";
  766. CString replace = curno + "->" + curno2;
  767. CString temp;
  768. int pos = m_replace.Find(title);
  769. if (pos != -1)
  770. {
  771. CString oldreplace;
  772. temp = m_replace.Right(m_replace.GetLength() - pos - title.GetLength());
  773. int pos2 = temp.Find("$");
  774. if (pos2 != -1)
  775. {
  776. oldreplace = temp.Left(pos2);
  777. temp = temp.Right(temp.GetLength() - pos2);
  778. }
  779. else
  780. {
  781. oldreplace = temp;
  782. temp.Empty();
  783. }
  784. if (oldreplace.Find(replace) != -1)return;
  785. if (oldreplace.Find(curno + "->") == -1)
  786. {
  787. m_replace = m_replace.Left(pos + title.GetLength());
  788. if (oldreplace.IsEmpty())
  789. {
  790. m_replace += replace;
  791. }
  792. else
  793. {
  794. m_replace += oldreplace + ",";
  795. m_replace += replace;
  796. }
  797. m_replace += temp;
  798. }
  799. else//已存在
  800. {
  801. m_replace = m_replace.Left(pos + title.GetLength());
  802. pos = oldreplace.Find(curno + "->");
  803. CString oldreplaseno = oldreplace.Right(oldreplace.GetLength() - pos - 2 - curno.GetLength());
  804. pos = oldreplaseno.Find(",");
  805. if (pos != -1)
  806. oldreplaseno = oldreplaseno.Left(pos);
  807. CString replace2 = curno + "->" + oldreplaseno;
  808. oldreplace.Replace(replace2, replace);
  809. m_replace += oldreplace;
  810. m_replace += temp;
  811. }
  812. }
  813. else
  814. {
  815. m_replace += title;
  816. m_replace += replace;
  817. }
  818. pos = m_replace.Find(title);
  819. m_replacesingle = m_replace.Right(m_replace.GetLength() - pos);
  820. m_replacesingle.Delete(0, 1);
  821. pos = m_replacesingle.Find("$");
  822. if (pos != -1)
  823. m_replacesingle = m_replacesingle.Left(pos);
  824. m_replacesingle = "$" + m_replacesingle;
  825. UpdateData(false);
  826. }
  827. }
  828. CDialog::OnLButtonUp(nFlags, point);
  829. }
  830. void ReplaceDesignNo::OnBegindragList4(NMHDR* pNMHDR, LRESULT* pResult)
  831. {
  832. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  833. // TODO: Add your control notification handler code here
  834. POSITION ppos;
  835. ppos = m_List1.GetFirstSelectedItemPosition();
  836. if (ppos == NULL)
  837. {
  838. return;
  839. }
  840. ppos = m_List4.GetFirstSelectedItemPosition();
  841. if (ppos == NULL)
  842. {
  843. return;
  844. }
  845. SetCapture();
  846. *pResult = 0;
  847. }