SetDesignNo.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. return true;
  197. }
  198. unsigned __stdcall LoadThumbNail12(LPVOID lpParam)
  199. {
  200. try
  201. {
  202. SetDesignNo *pDlg = (SetDesignNo*)lpParam;
  203. CImageList* pImgList = &pDlg->m_ImageListThumb2;
  204. CListCtrl *ListCtrl = &pDlg->m_List4;
  205. // reset our image list
  206. for (int i = 0; i < pImgList->GetImageCount(); i++)
  207. pImgList->Remove(i);
  208. // remove all items from list view
  209. ListCtrl->DeleteAllItems();
  210. pImgList->SetImageCount(pDlg->m_vFileName2.size());
  211. TCHAR path[MAX_PATH];
  212. vector<CString>::iterator iter;
  213. // Set redraw to FALSE to avoid flickering during adding new items
  214. ListCtrl->SetRedraw(FALSE);
  215. int nIndex = 0;
  216. CString str, spath;
  217. for (iter = pDlg->m_vFileName2.begin(); iter != pDlg->m_vFileName2.end() && pDlg->m_bTerminate2 != true; iter++, nIndex++)
  218. {
  219. str = *iter;
  220. spath.Empty();
  221. if (str.Left(str.ReverseFind('\\') + 1) != pDlg->m_path)
  222. {
  223. spath = str.Left(str.ReverseFind('\\') + 1);
  224. spath = spath.Right(spath.GetLength() - pDlg->m_path.GetLength());
  225. }
  226. str = str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  227. str = spath + str.Left(str.GetLength() - 4);
  228. ListCtrl->InsertItem(nIndex, str, nIndex);
  229. }
  230. ListCtrl->SetRedraw(TRUE);
  231. ListCtrl->Invalidate();
  232. const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH;
  233. int XDest, YDest, nDestWidth, nDestHeight;
  234. nIndex = 0;
  235. SolidBrush whitebrush(Color(255, 255, 255, 255));
  236. for (iter = pDlg->m_vFileName2.begin(); iter != pDlg->m_vFileName2.end() && pDlg->m_bTerminate2 != true; iter++, nIndex++)
  237. {
  238. // Load Image File
  239. Image *image = NULL;
  240. Bitmap *pBmp = NULL;
  241. str = *iter;
  242. spath = str.Left(str.ReverseFind('\\') + 1);
  243. spath += "s";
  244. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  245. if (PathFileExists(spath))
  246. ::LoadImageFromBuf(&image, spath);
  247. else
  248. ::LoadImageFromBuf(&image, str);
  249. int orientation = GetOrientation(image);
  250. if (orientation == 8)
  251. image->RotateFlip(Rotate270FlipNone);
  252. else if (orientation == 6)
  253. image->RotateFlip(Rotate90FlipNone);
  254. if (image->GetWidth() == 0)
  255. continue;
  256. // Calculate Rect to fit to canvas
  257. const float fImgRatio = (float)image->GetHeight() / image->GetWidth();
  258. if (fImgRatio > fRatio)
  259. {
  260. nDestWidth = THUMBNAIL_HEIGHT / fImgRatio;
  261. XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2;
  262. YDest = 0;
  263. nDestHeight = THUMBNAIL_HEIGHT;
  264. }
  265. else
  266. {
  267. XDest = 0;
  268. nDestWidth = THUMBNAIL_WIDTH;
  269. nDestHeight = THUMBNAIL_WIDTH*fImgRatio;
  270. YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2;
  271. }
  272. pBmp = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB);
  273. Graphics graph2(pBmp);
  274. graph2.Clear(Color(255, 192, 192, 192));
  275. graph2.FillRectangle(&whitebrush, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
  276. Graphics graph(pBmp);
  277. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  278. // Draw Image
  279. graph.DrawImage(image, desRect, 0, 0, image->GetWidth(), image->GetHeight(), UnitPixel);
  280. delete image;
  281. // Attach to Bitmap and Replace image in CImageList
  282. CBitmap bitmap;
  283. HBITMAP hbmp;
  284. pBmp->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
  285. bitmap.Attach(hbmp);
  286. pImgList->Replace(nIndex, &bitmap, NULL);
  287. delete pBmp;
  288. // Redraw only a current item for removing flickering and fast speed.
  289. ListCtrl->RedrawItems(nIndex, nIndex);
  290. // Release used DC and Object
  291. }
  292. ListCtrl->Invalidate();
  293. pDlg->m_bRunning2 = false;
  294. pDlg->m_bTerminate2 = false;
  295. _endthreadex(0);
  296. return 0;
  297. }
  298. catch (...)
  299. {
  300. }
  301. return true;
  302. }
  303. void SetDesignNo::LoadThumbImages()
  304. {
  305. TerminateThread();
  306. m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail11, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  307. m_bRunning = true;
  308. }
  309. BOOL SetDesignNo::TerminateThread()
  310. {
  311. if (!m_bRunning)
  312. return TRUE;
  313. m_bTerminate = true;
  314. for (;;)
  315. {
  316. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  317. break;
  318. MSG msg;
  319. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  320. {
  321. if (!AfxGetApp()->PumpMessage())
  322. break;
  323. }
  324. }
  325. ::CloseHandle(m_hThread);
  326. return TRUE;
  327. }
  328. void SetDesignNo::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
  329. {
  330. // TODO: Add your control notification handler code here
  331. POSITION pos;
  332. pos = m_List1.GetFirstSelectedItemPosition();
  333. if (pos == NULL)
  334. {
  335. return;
  336. }
  337. int iItem = m_List1.GetNextSelectedItem(pos);
  338. ShowPic22 dlg;
  339. dlg.m_nCurImgPos = iItem;
  340. dlg.m_AryOfImgPath = &m_patharray1;
  341. dlg.DoModal();
  342. *pResult = 0;
  343. }
  344. void SetDesignNo::OnDestroy()
  345. {
  346. if (m_image)delete m_image; m_image = NULL;
  347. TerminateThread(); TerminateThread2(); CDialog::OnDestroy();
  348. // TODO: Add your message handler code here
  349. }
  350. void SetDesignNo::LoadPhotos()
  351. {
  352. m_path2 = g_path3 + "\\";
  353. m_path2 += m_id;
  354. m_path2 += "\\";
  355. int i = 0;
  356. m_patharray1.RemoveAll();
  357. m_path2.MakeLower();
  358. CStringArray dirarray;
  359. CString str;
  360. if (1)
  361. {
  362. using namespace helper_coffs;
  363. ffsco o;
  364. o.dirs(1);
  365. o.find(LPCSTR(m_path2), LPCSTR("*.*"));
  366. ffsco::typeT coo;
  367. ffsco::typeT::iterator it;
  368. coo = o.co_dir();
  369. for (it = coo.begin();coo.end() != it;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();coo.end() != it;it++)
  390. {
  391. str = (*it).c_str();
  392. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  393. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  394. str.MakeLower();
  395. m_patharray1.Add(str);
  396. }
  397. }
  398. }
  399. CStringArray *pArray = &m_patharray1;
  400. m_vFileName.clear();
  401. for ( i = 0; i < pArray->GetSize(); i++)
  402. {
  403. CString filePath = pArray->ElementAt(i);
  404. filePath.MakeLower();
  405. m_vFileName.push_back(filePath);
  406. }
  407. LoadThumbImages();
  408. /////////////
  409. m_path = g_path1 + "\\";
  410. m_path += m_id;
  411. m_path += "\\";
  412. m_patharray2.RemoveAll();
  413. m_path.MakeLower();
  414. dirarray.RemoveAll();
  415. if (1)
  416. {
  417. using namespace helper_coffs;
  418. ffsco o;
  419. o.dirs(1);
  420. o.find(LPCSTR(m_path), LPCSTR("*.*"));
  421. ffsco::typeT coo;
  422. ffsco::typeT::iterator it;
  423. coo = o.co_dir();
  424. for (it = coo.begin();coo.end() != it;it++)
  425. {
  426. str = (*it).c_str();
  427. if (FindArray(&dirarray, str) == -1)
  428. {
  429. dirarray.Add(str);
  430. }
  431. }
  432. }
  433. if (1)
  434. {
  435. for ( i = 0; i < dirarray.GetSize(); i++)
  436. {
  437. using namespace helper_coffs;
  438. ffsco o;
  439. o.dirs(0);
  440. o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg"));
  441. ffsco::typeT coo;
  442. ffsco::typeT::iterator it;
  443. coo = o.co_file();
  444. for (it = coo.begin();coo.end() != it;it++)
  445. {
  446. str = (*it).c_str();
  447. if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue;
  448. if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue;
  449. str.MakeLower();
  450. m_patharray2.Add(str);
  451. }
  452. }
  453. }
  454. if (m_bRunning2)return;
  455. pArray = &m_patharray2;
  456. m_vFileName2.clear();
  457. for (i = 0; i < pArray->GetSize(); i++)
  458. {
  459. CString filePath = pArray->ElementAt(i);
  460. filePath.MakeLower();
  461. m_vFileName2.push_back(filePath);
  462. }
  463. TerminateThread2();
  464. m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail12, (LPVOID)this, 0, &m_dwThreadID2);
  465. m_bRunning2 = true;
  466. }
  467. BOOL SetDesignNo::TerminateThread2()
  468. {
  469. if (!m_bRunning2)
  470. return TRUE;
  471. m_bTerminate2 = true;
  472. for (;;)
  473. {
  474. if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0)
  475. break;
  476. MSG msg;
  477. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  478. {
  479. if (!AfxGetApp()->PumpMessage())
  480. break;
  481. }
  482. }
  483. ::CloseHandle(m_hThread2);
  484. return TRUE;
  485. }
  486. void SetDesignNo::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
  487. {
  488. // TODO: Add your control notification handler code here
  489. POSITION pos;
  490. pos = m_List4.GetFirstSelectedItemPosition();
  491. if (pos == NULL)
  492. {
  493. return;
  494. }
  495. int iItem = m_List4.GetNextSelectedItem(pos);
  496. ShowPic22 dlg;
  497. dlg.m_nCurImgPos = iItem;
  498. dlg.m_AryOfImgPath = &m_patharray2;
  499. dlg.DoModal();
  500. *pResult = 0;
  501. }
  502. HBRUSH SetDesignNo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  503. {
  504. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  505. // TODO: Change any attributes of the DC here
  506. if (nCtlColor == CTLCOLOR_STATIC && pWnd->GetDlgCtrlID() == IDC_STATIC1)
  507. {
  508. pDC->SetBkMode(TRANSPARENT); //设置字体背景为透明
  509. return (HBRUSH)::GetStockObject(WHITE_BRUSH); // 设置背景色
  510. }
  511. // TODO: Return a different brush if the default is not desired
  512. // TODO: Return a different brush if the default is not desired
  513. return hbr;
  514. }
  515. void SetDesignNo::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  516. {
  517. // TODO: Add your control notification handler code here
  518. POSITION ppos;
  519. ppos = m_List1.GetFirstSelectedItemPosition();
  520. if (ppos == NULL)
  521. {
  522. return;
  523. }
  524. int iItem = m_List1.GetNextSelectedItem(ppos);
  525. CString title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  526. CString str, spath;
  527. if (m_image)delete m_image; m_image = NULL;
  528. str = m_patharray1.ElementAt(iItem);
  529. spath = str.Left(str.ReverseFind('\\') + 1);
  530. spath += "s";
  531. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  532. if (PathFileExists(spath))
  533. ::LoadImageFromBuf(&m_image, spath);
  534. else
  535. ::LoadImageFromBuf(&m_image, str);
  536. CRect rc;
  537. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  538. ScreenToClient(rc);
  539. InvalidateRect(rc);
  540. CString sel;
  541. // m_designno="$10x8寸晶透水晶\\005:001,002,003";
  542. //$xxxx:001,002,003,004$
  543. int pos = m_designno.Find(title);
  544. if (pos != -1)
  545. {
  546. sel = m_designno.Right(m_designno.GetLength() - pos);
  547. sel = sel.Right(sel.GetLength() - title.GetLength());
  548. pos = sel.Find("$");
  549. if (pos != -1)
  550. sel = sel.Left(pos);
  551. sel.TrimLeft(",");
  552. sel.TrimRight(",");
  553. sel = "," + sel + ",";
  554. }
  555. for (int i = 0; i < m_List4.GetItemCount(); i++)
  556. {
  557. title = "," + m_List4.GetItemText(i, 0) + ",";
  558. if (sel.Find(title) != -1)
  559. m_List4.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
  560. else
  561. m_List4.SetItemState(i, 0, LVIS_SELECTED);
  562. }
  563. m_List4.SetFocus();
  564. *pResult = 0;
  565. }
  566. void SetDesignNo::OnClickList4(NMHDR* pNMHDR, LRESULT* pResult)
  567. {
  568. // TODO: Add your control notification handler code here
  569. POSITION ppos;
  570. ppos = m_List1.GetFirstSelectedItemPosition();
  571. if (ppos == NULL)
  572. {
  573. return;
  574. }
  575. int iItem = m_List1.GetNextSelectedItem(ppos);
  576. CString title = "$" + m_List1.GetItemText(iItem, 0) + ":";
  577. CString sel, temp;
  578. {//
  579. POSITION pos;
  580. pos = m_List4.GetFirstSelectedItemPosition();
  581. while (pos)
  582. {
  583. iItem = m_List4.GetNextSelectedItem(pos);
  584. sel += m_List4.GetItemText(iItem, 0);
  585. sel += ",";
  586. }
  587. sel.TrimRight(",");
  588. }//
  589. // m_designno="$10x18寸晶透水晶\\005:001,002,003$10x28寸晶透水晶\\005:001,002,003$10x18寸晶透水晶\\005:001,002,003";
  590. //$xxxx:001,002,003,004$
  591. int pos = m_designno.Find(title);
  592. if (pos != -1)
  593. {
  594. temp = m_designno.Right(m_designno.GetLength() - pos - title.GetLength());
  595. int pos2 = temp.Find("$");
  596. if (pos2 != -1)
  597. temp = temp.Right(temp.GetLength() - pos2);
  598. else
  599. temp.Empty();
  600. m_designno = m_designno.Left(pos + title.GetLength());
  601. m_designno += sel;
  602. m_designno += temp;
  603. }
  604. else
  605. {
  606. m_designno += title;
  607. m_designno += sel;
  608. }
  609. *pResult = 0;
  610. }
  611. void SetDesignNo::OnOK()
  612. {
  613. // TODO: Add extra validation here
  614. CString sql = "update dindan set designno='" + m_designno + "' where id='" + m_id + "'";
  615. g_sendhead.bsql = 1;
  616. g_pMainWnd->ProcessChatMessageRequest2(sql);
  617. if (g_bSendOK == 0)return;
  618. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  619. }
  620. void SetDesignNo::OnPaint()
  621. {
  622. CPaintDC dc(this); // device context for painting
  623. // TODO: Add your message handler code here
  624. if (m_image)
  625. {
  626. CRect rc;
  627. GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
  628. ScreenToClient(rc);
  629. RectFitDes(m_image->GetWidth(), m_image->GetHeight(), rc);
  630. Graphics dcgraph(dc.GetSafeHdc());
  631. Rect destinationRect(rc.left, rc.top, rc.Width(), rc.Height());
  632. dcgraph.DrawImage(m_image, destinationRect, 0, 0, m_image->GetWidth(), m_image->GetHeight(), UnitPixel);
  633. }
  634. // Do not call CDialog::OnPaint() for painting messages
  635. }