SetDesignNo.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. // SetDesignNo.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SetDesignNo.h"
  6. #include "ShowPic22.h"
  7. #include "JPEG.h"
  8. #define THUMBNAIL_WIDTH 80
  9. #define THUMBNAIL_HEIGHT 70
  10. /////////////////////////////////////////////////////////////////////////////
  11. // SetDesignNo dialog IDC_BU Tdelall
  12. SetDesignNo::SetDesignNo(CWnd* pParent /*=NULL*/)
  13. : CDialog(SetDesignNo::IDD, pParent)
  14. {
  15. //{{AFX_DATA_INIT(SetDesignNo)
  16. // NOTE: the ClassWizard will add member initialization here
  17. //}}AFX_DATA_INIT
  18. m_bTerminate = false;
  19. m_bRunning = false;
  20. m_hThread = NULL;
  21. m_bTerminate2 = false;
  22. m_bRunning2 = false;
  23. m_hThread2 = NULL;
  24. m_image = NULL;
  25. }
  26. void SetDesignNo::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(SetDesignNo)
  30. DDX_Control(pDX, IDC_LIST4, m_List4);
  31. DDX_Control(pDX, IDC_LIST1, m_List1);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(SetDesignNo, CDialog)
  35. //{{AFX_MSG_MAP(SetDesignNo)
  36. ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
  37. ON_WM_DESTROY()
  38. ON_NOTIFY(NM_DBLCLK, IDC_LIST4, OnDblclkList4)
  39. ON_WM_CTLCOLOR()
  40. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  41. ON_NOTIFY(NM_CLICK, IDC_LIST4, OnClickList4)
  42. ON_WM_PAINT()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // SetDesignNo message handlers
  47. extern BOOL CALLBACK EnumChildProc2(HWND hwnd, LPARAM lParam);
  48. BOOL SetDesignNo::OnInitDialog()
  49. {
  50. CDialog::OnInitDialog();
  51. CRect rc2, rc;
  52. GetWindowRect(rc2);
  53. MoveWindow(g_rc);
  54. g_WidthScale2 = (float)g_rc.Width() / (float)rc2.Width(); // new/Old
  55. g_HeightScale2 = (float)g_rc.Height() / (float)rc2.Height();
  56. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc2, 0);
  57. GetDlgItem(IDC_STATIC1)->GetWindowRect(rc2);
  58. rc2.right -= rc2.left;
  59. rc2.bottom -= rc2.top;
  60. rc2.left = rc2.top = 0;
  61. GetDlgItem(IDC_STATIC1)->MoveWindow(rc2);
  62. GetDlgItem(IDC_STATIC2)->MoveWindow(rc2);
  63. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  64. ScreenToClient(rc);
  65. rc.top = rc2.bottom;
  66. GetDlgItem(IDC_STATIC3)->MoveWindow(rc);
  67. CString str;
  68. str = "\r\n 功能简介:设置每一张设计版面所用的客人照片编号\r\n 1. 点选左侧要设置的一张设计版 2. Ctrl+点选右侧此设计版所用的原片 3. 重复前两步全部设置完成点击保存";
  69. GetDlgItem(IDC_STATIC1)->SetWindowText(str);
  70. m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  71. m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
  72. m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  73. m_List4.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL);
  74. CString filter = "id='" + m_id + "'";
  75. g_sendhead.code[0] = 11;
  76. g_sendhead.tabcount = 1;
  77. g_sendhead.bsql = 0;
  78. g_pMainWnd->ProcessChatMessageRequest2(filter);
  79. if (g_bSendOK == 0)
  80. {
  81. CDialog::OnCancel();
  82. return 0;
  83. }
  84. DataToArray(&g_List1array);
  85. if (g_List1array.GetSize())
  86. {
  87. m_designno = g_List1array.ElementAt(0).ElementAt(58);
  88. }
  89. LoadPhotos();
  90. return TRUE; // return TRUE unless you set the focus to a control
  91. // EXCEPTION: OCX Property Pages should return FALSE
  92. }
  93. unsigned __stdcall LoadThumbNail11(LPVOID lpParam)
  94. {
  95. try
  96. {
  97. SetDesignNo *pDlg = (SetDesignNo*)lpParam;
  98. CListCtrl *ListCtrl = &pDlg->m_List1;
  99. CImageList* pImgList = &pDlg->m_ImageListThumb;
  100. // reset our image list
  101. for (int i = 0; i < pImgList->GetImageCount(); i++)
  102. pImgList->Remove(i);
  103. // remove all items from list view
  104. ListCtrl->DeleteAllItems();
  105. pImgList->SetImageCount(pDlg->m_vFileName.size());
  106. TCHAR path[MAX_PATH];
  107. vector<CString>::iterator iter;
  108. // Set redraw to FALSE to avoid flickering during adding new items
  109. ListCtrl->SetRedraw(FALSE);
  110. int nIndex = 0;
  111. CString str, spath;
  112. for (iter = pDlg->m_vFileName.begin(); iter != pDlg->m_vFileName.end() && pDlg->m_bTerminate != true; iter++, nIndex++)
  113. {
  114. str = *iter;
  115. spath.Empty();
  116. if (str.Left(str.ReverseFind('\\') + 1) != pDlg->m_path2)
  117. {
  118. spath = str.Left(str.ReverseFind('\\') + 1);
  119. spath = spath.Right(spath.GetLength() - pDlg->m_path2.GetLength());
  120. }
  121. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  122. str = spath + str.Left(str.GetLength() - 4);
  123. ListCtrl->InsertItem(nIndex, str, nIndex);
  124. }
  125. ListCtrl->SetRedraw(TRUE);
  126. ListCtrl->Invalidate();
  127. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  128. int XDest, YDest, nDestWidth, nDestHeight;
  129. nIndex = 0;
  130. SolidBrush whitebrush(Color(255, 255, 255, 255));
  131. for (iter = pDlg->m_vFileName.begin(); iter != pDlg->m_vFileName.end() && pDlg->m_bTerminate != true; iter++, nIndex++)
  132. {
  133. // Load Image File
  134. Image *image = NULL;
  135. Bitmap *pBmp = NULL;
  136. str = *iter;
  137. spath = str.Left(str.ReverseFind('\\') + 1);
  138. spath += "s";
  139. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  140. if (PathFileExists(spath))
  141. ::LoadImageFromBuf(&image, spath);
  142. else
  143. ::LoadImageFromBuf(&image, str);
  144. int orientation = GetOrientation(image);
  145. if (orientation == 8)
  146. image->RotateFlip(Rotate270FlipNone);
  147. else if (orientation == 6)
  148. image->RotateFlip(Rotate90FlipNone);
  149. if (image->GetWidth() == 0)
  150. continue;
  151. // Calculate Rect to fit to canvas
  152. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  153. if (fImgRatio > fRatio)
  154. {
  155. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  156. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  157. YDest = 0;
  158. nDestHeight = THUMBNAIL_HEIGHT;
  159. }
  160. else
  161. {
  162. XDest = 0;
  163. nDestWidth = THUMBNAIL_WIDTH;
  164. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  165. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  166. }
  167. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  168. Graphics graph2(pBmp);
  169. graph2.Clear(Color(255, 192, 192, 192));
  170. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  171. Graphics graph(pBmp);
  172. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  173. // Draw Image
  174. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  175. delete image;
  176. // Attach to Bitmap and Replace image in CImageList
  177. CBitmap bitmap;
  178. HBITMAP hbmp;
  179. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  180. bitmap.Attach(hbmp);
  181. pImgList->Replace(nIndex, &bitmap, NULL);
  182. delete pBmp;
  183. // Redraw only a current item for removing flickering and fast speed.
  184. ListCtrl->RedrawItems(nIndex, nIndex);
  185. // Release used DC and Object
  186. }
  187. ListCtrl->Invalidate();
  188. pDlg->m_bRunning = false;
  189. pDlg->m_bTerminate = false;
  190. _endthreadex(0);
  191. return 0;
  192. }
  193. catch (...)
  194. {
  195. }
  196. }
  197. unsigned __stdcall LoadThumbNail12(LPVOID lpParam)
  198. {
  199. try
  200. {
  201. SetDesignNo *pDlg = (SetDesignNo*)lpParam;
  202. CImageList* pImgList = &pDlg->m_ImageListThumb2;
  203. CListCtrl *ListCtrl = &pDlg->m_List4;
  204. // reset our image list
  205. for (int i = 0; i < pImgList->GetImageCount(); i++)
  206. pImgList->Remove(i);
  207. // remove all items from list view
  208. ListCtrl->DeleteAllItems();
  209. pImgList->SetImageCount(pDlg->m_vFileName2.size());
  210. TCHAR path[MAX_PATH];
  211. vector<CString>::iterator iter;
  212. // Set redraw to FALSE to avoid flickering during adding new items
  213. ListCtrl->SetRedraw(FALSE);
  214. int nIndex = 0;
  215. CString str, spath;
  216. for (iter = pDlg->m_vFileName2.begin(); iter != pDlg->m_vFileName2.end() && pDlg->m_bTerminate2 != true; iter++, nIndex++)
  217. {
  218. str = *iter;
  219. spath.Empty();
  220. if (str.Left(str.ReverseFind('\\') + 1) != pDlg->m_path)
  221. {
  222. spath = str.Left(str.ReverseFind('\\') + 1);
  223. spath = spath.Right(spath.GetLength() - pDlg->m_path.GetLength());
  224. }
  225. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  226. str = spath + str.Left(str.GetLength() - 4);
  227. ListCtrl->InsertItem(nIndex, str, nIndex);
  228. }
  229. ListCtrl->SetRedraw(TRUE);
  230. ListCtrl->Invalidate();
  231. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  232. int XDest, YDest, nDestWidth, nDestHeight;
  233. nIndex = 0;
  234. SolidBrush whitebrush(Color(255, 255, 255, 255));
  235. for (iter = pDlg->m_vFileName2.begin(); iter != pDlg->m_vFileName2.end() && pDlg->m_bTerminate2 != true; iter++, nIndex++)
  236. {
  237. // Load Image File
  238. Image *image = NULL;
  239. Bitmap *pBmp = NULL;
  240. str = *iter;
  241. spath = str.Left(str.ReverseFind('\\') + 1);
  242. spath += "s";
  243. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  244. if (PathFileExists(spath))
  245. ::LoadImageFromBuf(&image, spath);
  246. else
  247. ::LoadImageFromBuf(&image, str);
  248. int orientation = GetOrientation(image);
  249. if (orientation == 8)
  250. image->RotateFlip(Rotate270FlipNone);
  251. else if (orientation == 6)
  252. image->RotateFlip(Rotate90FlipNone);
  253. if (image->GetWidth() == 0)
  254. continue;
  255. // Calculate Rect to fit to canvas
  256. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  257. if (fImgRatio > fRatio)
  258. {
  259. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  260. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  261. YDest = 0;
  262. nDestHeight = THUMBNAIL_HEIGHT;
  263. }
  264. else
  265. {
  266. XDest = 0;
  267. nDestWidth = THUMBNAIL_WIDTH;
  268. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  269. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  270. }
  271. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  272. Graphics graph2(pBmp);
  273. graph2.Clear(Color(255, 192, 192, 192));
  274. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  275. Graphics graph(pBmp);
  276. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  277. // Draw Image
  278. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  279. delete image;
  280. // Attach to Bitmap and Replace image in CImageList
  281. CBitmap bitmap;
  282. HBITMAP hbmp;
  283. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  284. bitmap.Attach(hbmp);
  285. pImgList->Replace(nIndex, &bitmap, NULL);
  286. delete pBmp;
  287. // Redraw only a current item for removing flickering and fast speed.
  288. ListCtrl->RedrawItems(nIndex, nIndex);
  289. // Release used DC and Object
  290. }
  291. ListCtrl->Invalidate();
  292. pDlg->m_bRunning2 = false;
  293. pDlg->m_bTerminate2 = false;
  294. _endthreadex(0);
  295. return 0;
  296. }
  297. catch (...)
  298. {
  299. }
  300. }
  301. void SetDesignNo::LoadThumbImages()
  302. {
  303. TerminateThread();
  304. m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail11, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  305. m_bRunning = true;
  306. }
  307. BOOL SetDesignNo::TerminateThread()
  308. {
  309. if (!m_bRunning)
  310. return TRUE;
  311. m_bTerminate = true;
  312. for (;;)
  313. {
  314. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  315. break;
  316. MSG msg;
  317. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  318. {
  319. if (!AfxGetApp()->PumpMessage())
  320. break;
  321. }
  322. }
  323. ::CloseHandle(m_hThread);
  324. return TRUE;
  325. }
  326. void SetDesignNo::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
  327. {
  328. // TODO: Add your control notification handler code here
  329. POSITION pos;
  330. pos = m_List1.GetFirstSelectedItemPosition();
  331. if (pos == NULL)
  332. {
  333. return;
  334. }
  335. int iItem = m_List1.GetNextSelectedItem(pos);
  336. ShowPic22 dlg;
  337. dlg.m_pos = iItem;
  338. dlg.m_pPathArray = &m_patharray1;
  339. dlg.DoModal();
  340. *pResult = 0;
  341. }
  342. void SetDesignNo::OnDestroy()
  343. {
  344. if (m_image)delete m_image; m_image = NULL;
  345. TerminateThread(); TerminateThread2(); CDialog::OnDestroy();
  346. // TODO: Add your message handler code here
  347. }
  348. void SetDesignNo::LoadPhotos()
  349. {
  350. int i = 0;
  351. m_path2 = g_path3 + "\\";
  352. m_path2 += m_id;
  353. m_path2 += "\\";
  354. m_patharray1.RemoveAll();
  355. m_path2.MakeLower();
  356. CStringArray dirarray;
  357. CString str;
  358. if (1)
  359. {
  360. using namespace helper_coffs;
  361. ffsco o;
  362. o.dirs(1);
  363. o.find(LPCSTR(m_path2), LPCSTR("*.*"));
  364. ffsco::typeT coo;
  365. ffsco::typeT::iterator it;
  366. coo = o.co_dir();
  367. for (it = coo.begin();
  368. coo.end() != it;
  369. it++)
  370. {
  371. str = (*it).c_str();
  372. if (FindArray(&dirarray, str) == -1)
  373. {
  374. dirarray.Add(str);
  375. }
  376. }
  377. }
  378. if (1)
  379. {
  380. for ( i = 0; i < dirarray.GetSize(); i++)
  381. {
  382. using namespace helper_coffs;
  383. ffsco o;
  384. o.dirs(0);
  385. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  386. ffsco::typeT coo;
  387. ffsco::typeT::iterator it;
  388. coo = o.co_file();
  389. for (it = coo.begin();
  390. coo.end() != it;
  391. it++)
  392. {
  393. str = (*it).c_str();
  394. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  395. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  396. str.MakeLower();
  397. m_patharray1.Add(str);
  398. }
  399. }
  400. }
  401. CStringArray *pArray = &m_patharray1;
  402. m_vFileName.clear();
  403. for ( i = 0; i < pArray->GetSize(); i++)
  404. {
  405. CString filePath = pArray->ElementAt(i);
  406. filePath.MakeLower();
  407. m_vFileName.push_back(filePath);
  408. }
  409. LoadThumbImages();
  410. /////////////
  411. m_path = g_path1 + "\\";
  412. m_path += m_id;
  413. m_path += "\\";
  414. m_patharray2.RemoveAll();
  415. m_path.MakeLower();
  416. dirarray.RemoveAll();
  417. if (1)
  418. {
  419. using namespace helper_coffs;
  420. ffsco o;
  421. o.dirs(1);
  422. o.find(LPCSTR(m_path), LPCSTR("*.*"));
  423. ffsco::typeT coo;
  424. ffsco::typeT::iterator it;
  425. coo = o.co_dir();
  426. for (it = coo.begin();
  427. coo.end() != it;
  428. it++)
  429. {
  430. str = (*it).c_str();
  431. if (FindArray(&dirarray, str) == -1)
  432. {
  433. dirarray.Add(str);
  434. }
  435. }
  436. }
  437. if (1)
  438. {
  439. for ( i = 0; i < dirarray.GetSize(); i++)
  440. {
  441. using namespace helper_coffs;
  442. ffsco o;
  443. o.dirs(0);
  444. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  445. ffsco::typeT coo;
  446. ffsco::typeT::iterator it;
  447. coo = o.co_file();
  448. for (it = coo.begin();
  449. coo.end() != it;
  450. it++)
  451. {
  452. str = (*it).c_str();
  453. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  454. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  455. str.MakeLower();
  456. m_patharray2.Add(str);
  457. }
  458. }
  459. }
  460. if (m_bRunning2)return;
  461. pArray = &m_patharray2;
  462. m_vFileName2.clear();
  463. for (i = 0; i < pArray->GetSize(); i++)
  464. {
  465. CString filePath = pArray->ElementAt(i);
  466. filePath.MakeLower();
  467. m_vFileName2.push_back(filePath);
  468. }
  469. TerminateThread2();
  470. m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail12, (LPVOID)this, 0, &m_dwThreadID2);
  471. m_bRunning2 = true;
  472. }
  473. BOOL SetDesignNo::TerminateThread2()
  474. {
  475. if (!m_bRunning2)
  476. return TRUE;
  477. m_bTerminate2 = true;
  478. for (;;)
  479. {
  480. if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0)
  481. break;
  482. MSG msg;
  483. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  484. {
  485. if (!AfxGetApp()->PumpMessage())
  486. break;
  487. }
  488. }
  489. ::CloseHandle(m_hThread2);
  490. return TRUE;
  491. }
  492. void SetDesignNo::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
  493. {
  494. // TODO: Add your control notification handler code here
  495. POSITION pos;
  496. pos = m_List4.GetFirstSelectedItemPosition();
  497. if (pos == NULL)
  498. {
  499. return;
  500. }
  501. int iItem = m_List4.GetNextSelectedItem(pos);
  502. ShowPic22 dlg;
  503. dlg.m_pos = iItem;
  504. dlg.m_pPathArray = &m_patharray2;
  505. dlg.DoModal();
  506. *pResult = 0;
  507. }
  508. HBRUSH SetDesignNo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  509. {
  510. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  511. // TODO: Change any attributes of the DC here
  512. if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_STATIC1)
  513. {
  514. pDC->SetBkMode(TRANSPARENT); //设置字体背景为透明
  515. return (HBRUSH)::GetStockObject(WHITE_BRUSH); // 设置背景色
  516. }
  517. // TODO: Return a different brush if the default is not desired
  518. // TODO: Return a different brush if the default is not desired
  519. return hbr;
  520. }
  521. void SetDesignNo::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  522. {
  523. // TODO: Add your control notification handler code here
  524. POSITION ppos;
  525. ppos = m_List1.GetFirstSelectedItemPosition();
  526. if (ppos == NULL)
  527. {
  528. return;
  529. }
  530. int iItem = m_List1.GetNextSelectedItem(ppos);
  531. CString title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  532. CString str, spath;
  533. if (m_image)delete m_image; m_image = NULL;
  534. str = m_patharray1.ElementAt(iItem);
  535. spath = str.Left(str.ReverseFind('\\') + 1);
  536. spath += "s";
  537. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  538. if (PathFileExists(spath))
  539. ::LoadImageFromBuf(&m_image, spath);
  540. else
  541. ::LoadImageFromBuf(&m_image, str);
  542. CRect rc;
  543. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  544. ScreenToClient(rc);
  545. InvalidateRect(rc);
  546. CString sel;
  547. // m_designno="$10x8寸晶透水晶\\005:001,002,003";
  548. //$xxxx:001,002,003,004$
  549. int pos = m_designno.Find(title);
  550. if (pos != -1)
  551. {
  552. sel = m_designno.Right(m_designno.GetLength() - pos);
  553. sel = sel.Right(sel.GetLength() - title.GetLength());
  554. pos = sel.Find("$");
  555. if (pos != -1)
  556. sel = sel.Left(pos);
  557. sel.TrimLeft(",");
  558. sel.TrimRight(",");
  559. sel = "," + sel + ",";
  560. }
  561. for (int i = 0; i < m_List4.GetItemCount(); i++)
  562. {
  563. title = "," + m_List4.GetItemText(i, 0) + ",";
  564. if (sel.Find(title) != -1)
  565. m_List4.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
  566. else
  567. m_List4.SetItemState(i, 0, LVIS_SELECTED);
  568. }
  569. m_List4.SetFocus();
  570. *pResult = 0;
  571. }
  572. void SetDesignNo::OnClickList4(NMHDR* pNMHDR, LRESULT* pResult)
  573. {
  574. // TODO: Add your control notification handler code here
  575. POSITION ppos;
  576. ppos = m_List1.GetFirstSelectedItemPosition();
  577. if (ppos == NULL)
  578. {
  579. return;
  580. }
  581. int iItem = m_List1.GetNextSelectedItem(ppos);
  582. CString title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  583. CString sel, temp;
  584. {//
  585. POSITION pos;
  586. pos = m_List4.GetFirstSelectedItemPosition();
  587. while (pos)
  588. {
  589. iItem = m_List4.GetNextSelectedItem(pos);
  590. sel += m_List4.GetItemText(iItem, 0);
  591. sel += ",";
  592. }
  593. sel.TrimRight(",");
  594. }//
  595. // m_designno="$10x18寸晶透水晶\\005:001,002,003$10x28寸晶透水晶\\005:001,002,003$10x18寸晶透水晶\\005:001,002,003";
  596. //$xxxx:001,002,003,004$
  597. int pos = m_designno.Find(title);
  598. if (pos != -1)
  599. {
  600. temp = m_designno.Right(m_designno.GetLength() - pos - title.GetLength());
  601. int pos2 = temp.Find("$");
  602. if (pos2 != -1)
  603. temp = temp.Right(temp.GetLength() - pos2);
  604. else
  605. temp.Empty();
  606. m_designno = m_designno.Left(pos + title.GetLength());
  607. m_designno += sel;
  608. m_designno += temp;
  609. }
  610. else
  611. {
  612. m_designno += title;
  613. m_designno += sel;
  614. }
  615. *pResult = 0;
  616. }
  617. void SetDesignNo::OnOK()
  618. {
  619. // TODO: Add extra validation here
  620. CString sql = "update dindan set designno='" + m_designno + "' where id='" + m_id + "'";
  621. g_sendhead.bsql = 1;
  622. g_pMainWnd->ProcessChatMessageRequest2(sql);
  623. if (g_bSendOK == 0)return;
  624. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  625. }
  626. void SetDesignNo::OnPaint()
  627. {
  628. CPaintDC dc(this); // device context for painting
  629. // TODO: Add your message handler code here
  630. if (m_image)
  631. {
  632. CRect rc;
  633. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  634. ScreenToClient(rc);
  635. RectFitDes(m_image->GetWidth(), m_image->GetHeight(), rc);
  636. Graphics dcgraph(dc.GetSafeHdc());
  637. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  638. dcgraph.DrawImage(m_image, destinationRect, 0, 0, m_image->GetWidth(), m_image->GetHeight(), UnitPixel);
  639. }
  640. // Do not call CDialog::OnPaint() for painting messages
  641. }