ReplaceDesignNo.cpp 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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. int i = 0;
  363. m_path2=g_path3+"\\";
  364. m_path2+=m_id;
  365. m_path2 +="\\";
  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();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_pos=iItem;
  508. dlg.m_pPathArray=&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. int i = 0;
  529. POSITION ppos;
  530. ppos=m_List1.GetFirstSelectedItemPosition();
  531. if(ppos==NULL)
  532. {
  533. return;
  534. }
  535. int iItem=m_List1.GetNextSelectedItem(ppos);
  536. CString title="$"+m_List1.GetItemText (iItem, 0)+":";
  537. CString str,spath;
  538. if(m_image)delete m_image;m_image=NULL;
  539. str=m_patharray1.ElementAt (iItem);
  540. spath=str.Left (str.ReverseFind ('\\')+1);
  541. spath+="s";
  542. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  543. if(::CheckFileExist (spath))
  544. ::LoadImageFromBuf (&m_image, spath);
  545. else
  546. ::LoadImageFromBuf (&m_image, str);
  547. CRect rc;
  548. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  549. ScreenToClient(rc);
  550. InvalidateRect(rc);
  551. CString sel;
  552. int pos=m_designno.Find (title);
  553. if(pos!=-1)
  554. {
  555. sel=m_designno.Right (m_designno.GetLength ()-pos);
  556. sel=sel.Right (sel.GetLength ()-title.GetLength ());
  557. pos=sel.Find ("$");
  558. if(pos!=-1)
  559. sel=sel.Left (pos);
  560. sel.TrimLeft (",");
  561. sel.TrimRight (",");
  562. sel=","+sel+",";
  563. }
  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(::CheckFileExist (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. }