ReplaceDesignNo.cpp 24 KB

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