ReplaceDesignNo.cpp 24 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. 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. m_patharray1.RemoveAll ();
  366. m_path2.MakeLower ();
  367. CStringArray dirarray;
  368. CString str;
  369. if(1)
  370. {
  371. using namespace helper_coffs;
  372. ffsco o;
  373. o.dirs(1);
  374. o.find(LPCSTR(m_path2), LPCSTR("*.*"));
  375. ffsco::typeT coo;
  376. ffsco::typeT::iterator it;
  377. coo = o.co_dir();
  378. for (it = coo.begin();
  379. coo.end() != it;
  380. it ++)
  381. {
  382. str=(*it).c_str();
  383. if(FindArray(&dirarray, str)==-1)
  384. {
  385. dirarray.Add (str);
  386. }
  387. }
  388. }
  389. if(1)
  390. {
  391. for(int i=0; i<dirarray.GetSize (); i++)
  392. {
  393. using namespace helper_coffs;
  394. ffsco o;
  395. o.dirs(0);
  396. o.find(LPCSTR(dirarray.ElementAt (i)), LPCSTR("*.jpg"));
  397. ffsco::typeT coo;
  398. ffsco::typeT::iterator it;
  399. coo = o.co_file();
  400. for (it = coo.begin();
  401. coo.end() != it;
  402. it ++)
  403. {
  404. str=(*it).c_str();
  405. if(str.GetAt (str.ReverseFind ('\\')+1)=='s')continue;
  406. if(str.GetAt (str.ReverseFind ('\\')+1)=='m')continue;
  407. str.MakeLower ();
  408. m_patharray1.Add (str);
  409. }
  410. }
  411. }
  412. CStringArray *pArray=&m_patharray1;
  413. m_vFileName.clear();
  414. for(int i=0; i<pArray->GetSize (); i++)
  415. {
  416. CString filePath=pArray->ElementAt (i);
  417. filePath.MakeLower();
  418. m_vFileName.push_back(filePath);
  419. }
  420. LoadThumbImages();
  421. /////////////
  422. m_path=g_path1+"\\";
  423. m_path+=m_id;
  424. m_path +="\\";
  425. m_patharray2.RemoveAll ();
  426. m_path.MakeLower ();
  427. dirarray.RemoveAll ();
  428. if(1)
  429. {
  430. using namespace helper_coffs;
  431. ffsco o;
  432. o.dirs(1);
  433. o.find(LPCSTR(m_path), LPCSTR("*.*"));
  434. ffsco::typeT coo;
  435. ffsco::typeT::iterator it;
  436. coo = o.co_dir();
  437. for (it = coo.begin();
  438. coo.end() != it;
  439. it ++)
  440. {
  441. str=(*it).c_str();
  442. if(FindArray(&dirarray, str)==-1)
  443. {
  444. dirarray.Add (str);
  445. }
  446. }
  447. }
  448. if(1)
  449. {
  450. for(int i=0; i<dirarray.GetSize (); i++)
  451. {
  452. using namespace helper_coffs;
  453. ffsco o;
  454. o.dirs(0);
  455. o.find(LPCSTR(dirarray.ElementAt (i)), LPCSTR("*.jpg"));
  456. ffsco::typeT coo;
  457. ffsco::typeT::iterator it;
  458. coo = o.co_file();
  459. for (it = coo.begin();
  460. coo.end() != it;
  461. it ++)
  462. {
  463. str=(*it).c_str();
  464. if(str.GetAt (str.ReverseFind ('\\')+1)=='s')continue;
  465. if(str.GetAt (str.ReverseFind ('\\')+1)=='m')continue;
  466. str.MakeLower ();
  467. m_patharray2.Add (str);
  468. }
  469. }
  470. }
  471. if(m_bRunning2)return;
  472. pArray=&m_patharray2;
  473. m_vFileName2.clear();
  474. for( i=0; i<pArray->GetSize (); i++)
  475. {
  476. CString filePath=pArray->ElementAt (i);
  477. filePath.MakeLower();
  478. m_vFileName2.push_back(filePath);
  479. }
  480. TerminateThread2();
  481. m_hThread2 = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail14,(LPVOID)this,0,&m_dwThreadID2);
  482. m_bRunning2=true;
  483. }
  484. BOOL ReplaceDesignNo::TerminateThread2()
  485. {
  486. if ( !m_bRunning2 )
  487. return TRUE;
  488. m_bTerminate2=true;
  489. for( ; ; )
  490. {
  491. if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
  492. break;
  493. MSG msg;
  494. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  495. {
  496. if (!AfxGetApp()->PumpMessage())
  497. break;
  498. }
  499. }
  500. ::CloseHandle(m_hThread2);
  501. return TRUE;
  502. }
  503. void ReplaceDesignNo::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
  504. {
  505. // TODO: Add your control notification handler code here
  506. POSITION pos;
  507. pos=m_List4.GetFirstSelectedItemPosition();
  508. if(pos==NULL)
  509. {
  510. return;
  511. }
  512. int iItem=m_List4.GetNextSelectedItem(pos);
  513. ShowPic22 dlg;
  514. dlg.m_pos=iItem;
  515. dlg.m_pPathArray=&m_patharray2;
  516. dlg.DoModal ();
  517. *pResult = 0;
  518. }
  519. HBRUSH ReplaceDesignNo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  520. {
  521. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  522. // TODO: Change any attributes of the DC here
  523. if (nCtlColor==CTLCOLOR_STATIC && pWnd->GetDlgCtrlID ()==IDC_STATIC1)
  524. {
  525. pDC-> SetBkMode(TRANSPARENT); //设置字体背景为透明
  526. return (HBRUSH)::GetStockObject(WHITE_BRUSH); // 设置背景色
  527. }
  528. // TODO: Return a different brush if the default is not desired
  529. // TODO: Return a different brush if the default is not desired
  530. return hbr;
  531. }
  532. void ReplaceDesignNo::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  533. {
  534. // TODO: Add your control notification handler code here
  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(::CheckFileExist (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(int 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(int 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(::CheckFileExist (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. }