123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014 |
- // ReplaceDesignNo.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ReplaceDesignNo.h"
- #include "ShowPic22.h"
- #include "JPEG.h"
- #include "SetDesignNo.h"
- #define THUMBNAIL_WIDTH 80
- #define THUMBNAIL_HEIGHT 70
- /////////////////////////////////////////////////////////////////////////////
- // ReplaceDesignNo dialog IDC_BU Tdelall
- ReplaceDesignNo::ReplaceDesignNo(CWnd* pParent /*=NULL*/)
- : CDialog(ReplaceDesignNo::IDD, pParent)
- {
- //{{AFX_DATA_INIT(ReplaceDesignNo)
- m_replace = _T("");
- //}}AFX_DATA_INIT
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bTerminate2=false;
- m_bRunning2=false;
- m_hThread2 = NULL;
- m_image=NULL;
- }
- void ReplaceDesignNo::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(ReplaceDesignNo)
- DDX_Control(pDX, IDC_LIST5, m_List5);
- DDX_Control(pDX, IDC_LIST4, m_List4);
- DDX_Control(pDX, IDC_LIST1, m_List1);
- DDX_Text(pDX, IDC_EDIT1, m_replacesingle);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(ReplaceDesignNo, CDialog)
- //{{AFX_MSG_MAP(ReplaceDesignNo)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
- ON_WM_DESTROY()
- ON_NOTIFY(NM_DBLCLK, IDC_LIST4, OnDblclkList4)
- ON_WM_CTLCOLOR()
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- ON_NOTIFY(NM_CLICK, IDC_LIST4, OnClickList4)
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_WM_LBUTTONUP()
- ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST4, OnBegindragList4)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // ReplaceDesignNo message handlers
- extern BOOL CALLBACK EnumChildProc2(HWND hwnd,LPARAM lParam);
- extern float m_WidthScale2;
- extern float m_HeightScale2;
- BOOL ReplaceDesignNo::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- CRect rc2,rc;
- GetWindowRect(rc2);
- rc=CRect(0, 0, g_screenwid, g_screenhei);
- ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW);
- m_WidthScale2 = (float)rc.Width()/(float)rc2.Width(); // new/Old
- m_HeightScale2 = (float)rc.Height()/(float)rc2.Height();
- EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc2,0);
- GetDlgItem(IDC_STATIC1)->GetWindowRect(rc2);
- rc2.right -=rc2.left ;
- rc2.bottom -=rc2.top ;
- rc2.left =rc2.top =0;
- GetDlgItem(IDC_STATIC1)->MoveWindow(rc2);
- GetDlgItem(IDC_STATIC2)->MoveWindow(rc2);
- // GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
- // ScreenToClient(rc);
- // rc.top =rc2.bottom ;
- /// GetDlgItem(IDC_STATIC3)->MoveWindow(rc);
- CString str;
- str="\r\n 功能简介:客人选设计过程中,按照客人要求将原设计版上的照片替换成客人喜欢的照片\r\n 1. 点选左侧要替换的一张设计版,此设计版所用照片将出现在右侧,如果没有设置,可点'重设照片'按钮设置照片.\r\n 2. 在右下方全部客人原片区选中客人喜欢的目标照片拖放至上方需要替换的照片上\r\n 3. 重复前两步全部替换完成后点击保存";
- GetDlgItem(IDC_STATIC1)->SetWindowText(str);
- m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
- m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List4.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL);
- m_ImageListThumb3.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List5.SetImageList(&m_ImageListThumb3, LVSIL_NORMAL);
- CString filter="id='"+m_id+"'";
- g_sendhead.code[0]=11;
- g_sendhead.tabcount=1;
- g_sendhead.bsql=0;
- g_pMainWnd->ProcessChatMessageRequest2(filter);
- if(g_bSendOK==0)
- {
- CDialog::OnCancel ();
- return 0;
- }
- DataToArray(&g_List1array);
- if(g_List1array.GetSize ())
- {
- m_designno=g_List1array.ElementAt (0).ElementAt (58);
- m_replace=g_List1array.ElementAt (0).ElementAt (59);
- }
- LoadPhotos();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- unsigned __stdcall LoadThumbNail13(LPVOID lpParam)
- {
- try
- {
- ReplaceDesignNo *pDlg=(ReplaceDesignNo*)lpParam;
- CListCtrl *ListCtrl=&pDlg->m_List1;
- CImageList* pImgList=&pDlg->m_ImageListThumb;
- // reset our image list
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
- // remove all items from list view
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vFileName.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
- // Set redraw to FALSE to avoid flickering during adding new items
- ListCtrl->SetRedraw(FALSE);
- int nIndex=0;
- CString str, spath;
-
- for(iter=pDlg->m_vFileName.begin(); iter!=pDlg->m_vFileName.end() && pDlg->m_bTerminate!=true; iter++, nIndex++)
- {
- str=*iter;
- spath.Empty ();
- if(str.Left (str.ReverseFind ('\\')+1)!=pDlg->m_path2)
- {
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath= spath.Right (spath.GetLength ()-pDlg->m_path2.GetLength ());
- }
-
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=spath+str.Left (str.GetLength ()-4);
-
- ListCtrl->InsertItem(nIndex, str, nIndex);
- }
- ListCtrl->SetRedraw(TRUE);
- ListCtrl->Invalidate();
- const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
- int XDest, YDest, nDestWidth, nDestHeight;
- nIndex=0;
-
- SolidBrush whitebrush(Color(255,255,255,255));
- for(iter=pDlg->m_vFileName.begin(); iter!=pDlg->m_vFileName.end() && pDlg->m_bTerminate!=true; iter++, nIndex++)
- {
- // Load Image File
- Image *image=NULL;
- Bitmap *pBmp=NULL;
- str=*iter;
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if(::CheckFileExist (spath))
- ::LoadImageFromBuf (&image, spath);
- else
- ::LoadImageFromBuf (&image, str);
- int orientation=GetOrientation(image);
- if(orientation==8)
- image->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- image->RotateFlip( Rotate90FlipNone );
-
- if(image->GetWidth()==0)
- continue;
- // Calculate Rect to fit to canvas
-
- const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
- if(fImgRatio > fRatio)
- {
- nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
- XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
- YDest=0;
- nDestHeight=THUMBNAIL_HEIGHT;
- }
- else
- {
- XDest=0;
- nDestWidth=THUMBNAIL_WIDTH;
- nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
- YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
- }
- pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
- Graphics graph2(pBmp);
- graph2.Clear(Color(255,192,192,192));
-
- graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
- Graphics graph(pBmp);
- Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
- // Draw Image
-
- graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
- delete image;
- // Attach to Bitmap and Replace image in CImageList
- CBitmap bitmap;
- HBITMAP hbmp;
- pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
- bitmap.Attach(hbmp);
- pImgList->Replace(nIndex, &bitmap, NULL);
- delete pBmp;
- // Redraw only a current item for removing flickering and fast speed.
- ListCtrl->RedrawItems(nIndex, nIndex);
- // Release used DC and Object
-
- }
-
- ListCtrl->Invalidate();
- pDlg->m_bRunning=false;
- pDlg->m_bTerminate=false;
- _endthreadex( 0 );
- return 0;
- }
- catch(...)
- {
- }
- }
- unsigned __stdcall LoadThumbNail14(LPVOID lpParam)
- {
- try
- {
- ReplaceDesignNo *pDlg=(ReplaceDesignNo*)lpParam;
- CImageList* pImgList=&pDlg->m_ImageListThumb2;
- CListCtrl *ListCtrl=&pDlg->m_List4;
- // reset our image list
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
- // remove all items from list view
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vFileName2.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
- // Set redraw to FALSE to avoid flickering during adding new items
- ListCtrl->SetRedraw(FALSE);
- int nIndex=0;
- CString str, spath;
-
- for(iter=pDlg->m_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
- {
- str=*iter;
- spath.Empty ();
- if(str.Left (str.ReverseFind ('\\')+1)!=pDlg->m_path)
- {
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath= spath.Right (spath.GetLength ()-pDlg->m_path.GetLength ());
- }
-
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=spath+str.Left (str.GetLength ()-4);
-
- ListCtrl->InsertItem(nIndex, str, nIndex);
- }
- ListCtrl->SetRedraw(TRUE);
- ListCtrl->Invalidate();
- const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
- int XDest, YDest, nDestWidth, nDestHeight;
- nIndex=0;
-
- SolidBrush whitebrush(Color(255,255,255,255));
- for(iter=pDlg->m_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
- {
- // Load Image File
- Image *image=NULL;
- Bitmap *pBmp=NULL;
- str=*iter;
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if(::CheckFileExist (spath))
- ::LoadImageFromBuf (&image, spath);
- else
- ::LoadImageFromBuf (&image, str);
- int orientation=GetOrientation(image);
- if(orientation==8)
- image->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- image->RotateFlip( Rotate90FlipNone );
-
- if(image->GetWidth()==0)
- continue;
- // Calculate Rect to fit to canvas
-
- const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
- if(fImgRatio > fRatio)
- {
- nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
- XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
- YDest=0;
- nDestHeight=THUMBNAIL_HEIGHT;
- }
- else
- {
- XDest=0;
- nDestWidth=THUMBNAIL_WIDTH;
- nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
- YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
- }
- pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
- Graphics graph2(pBmp);
- graph2.Clear(Color(255,192,192,192));
-
- graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
- Graphics graph(pBmp);
- Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
- // Draw Image
-
- graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
- delete image;
- // Attach to Bitmap and Replace image in CImageList
- CBitmap bitmap;
- HBITMAP hbmp;
- pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
- bitmap.Attach(hbmp);
- pImgList->Replace(nIndex, &bitmap, NULL);
- delete pBmp;
- // Redraw only a current item for removing flickering and fast speed.
- ListCtrl->RedrawItems(nIndex, nIndex);
- // Release used DC and Object
-
- }
-
- ListCtrl->Invalidate();
- pDlg->m_bRunning2=false;
- pDlg->m_bTerminate2=false;
- _endthreadex( 0 );
- return 0;
- }
- catch(...)
- {
- }
- }
- void ReplaceDesignNo::LoadThumbImages()
- {
- TerminateThread();
- m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail13,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
- m_bRunning=true;
- }
- BOOL ReplaceDesignNo::TerminateThread()
- {
- if ( !m_bRunning )
- return TRUE;
-
- m_bTerminate=true;
-
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
- break;
-
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread);
- return TRUE;
- }
- void ReplaceDesignNo::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- POSITION pos;
- pos=m_List1.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- int iItem=m_List1.GetNextSelectedItem(pos);
-
- ShowPic22 dlg;
- dlg.m_pos=iItem;
- dlg.m_pPathArray=&m_patharray1;
- dlg.DoModal ();
- *pResult = 0;
- }
- void ReplaceDesignNo::OnDestroy()
- {
- if(m_image)delete m_image;m_image=NULL;
- TerminateThread();TerminateThread2(); CDialog::OnDestroy();
- // TODO: Add your message handler code here
- }
- void ReplaceDesignNo::LoadPhotos()
- {
- m_path2=g_path3+"\\";
- m_path2+=m_id;
- m_path2 +="\\";
- m_patharray1.RemoveAll ();
- m_path2.MakeLower ();
- CStringArray dirarray;
- CString str;
- if(1)
- {
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(m_path2), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_dir();
- for (it = coo.begin();
- coo.end() != it;
- it ++)
- {
- str=(*it).c_str();
- if(FindArray(&dirarray, str)==-1)
- {
- dirarray.Add (str);
- }
- }
- }
- if(1)
- {
- for(int i=0; i<dirarray.GetSize (); i++)
- {
- using namespace helper_coffs;
- ffsco o;
- o.dirs(0);
- o.find(LPCSTR(dirarray.ElementAt (i)), LPCSTR("*.jpg"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- for (it = coo.begin();
- coo.end() != it;
- it ++)
- {
- str=(*it).c_str();
- if(str.GetAt (str.ReverseFind ('\\')+1)=='s')continue;
- if(str.GetAt (str.ReverseFind ('\\')+1)=='m')continue;
- str.MakeLower ();
- m_patharray1.Add (str);
- }
- }
- }
- CStringArray *pArray=&m_patharray1;
- m_vFileName.clear();
- for(int i=0; i<pArray->GetSize (); i++)
- {
- CString filePath=pArray->ElementAt (i);
- filePath.MakeLower();
- m_vFileName.push_back(filePath);
- }
- LoadThumbImages();
- /////////////
- m_path=g_path1+"\\";
- m_path+=m_id;
- m_path +="\\";
- m_patharray2.RemoveAll ();
- m_path.MakeLower ();
- dirarray.RemoveAll ();
- if(1)
- {
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(m_path), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_dir();
- for (it = coo.begin();
- coo.end() != it;
- it ++)
- {
- str=(*it).c_str();
- if(FindArray(&dirarray, str)==-1)
- {
- dirarray.Add (str);
- }
- }
- }
- if(1)
- {
- for(int i=0; i<dirarray.GetSize (); i++)
- {
- using namespace helper_coffs;
- ffsco o;
- o.dirs(0);
- o.find(LPCSTR(dirarray.ElementAt (i)), LPCSTR("*.jpg"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- for (it = coo.begin();
- coo.end() != it;
- it ++)
- {
- str=(*it).c_str();
- if(str.GetAt (str.ReverseFind ('\\')+1)=='s')continue;
- if(str.GetAt (str.ReverseFind ('\\')+1)=='m')continue;
- str.MakeLower ();
- m_patharray2.Add (str);
- }
- }
- }
- if(m_bRunning2)return;
- pArray=&m_patharray2;
- m_vFileName2.clear();
- for( i=0; i<pArray->GetSize (); i++)
- {
- CString filePath=pArray->ElementAt (i);
- filePath.MakeLower();
- m_vFileName2.push_back(filePath);
- }
- TerminateThread2();
- m_hThread2 = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail14,(LPVOID)this,0,&m_dwThreadID2);
- m_bRunning2=true;
-
- }
- BOOL ReplaceDesignNo::TerminateThread2()
- {
- if ( !m_bRunning2 )
- return TRUE;
-
- m_bTerminate2=true;
-
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
- break;
-
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread2);
- return TRUE;
- }
- void ReplaceDesignNo::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- POSITION pos;
- pos=m_List4.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- int iItem=m_List4.GetNextSelectedItem(pos);
- ShowPic22 dlg;
- dlg.m_pos=iItem;
- dlg.m_pPathArray=&m_patharray2;
- dlg.DoModal ();
- *pResult = 0;
- }
- HBRUSH ReplaceDesignNo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // TODO: Change any attributes of the DC here
- if (nCtlColor==CTLCOLOR_STATIC && pWnd->GetDlgCtrlID ()==IDC_STATIC1)
- {
- pDC-> SetBkMode(TRANSPARENT); //设置字体背景为透明
- return (HBRUSH)::GetStockObject(WHITE_BRUSH); // 设置背景色
- }
- // TODO: Return a different brush if the default is not desired
- // TODO: Return a different brush if the default is not desired
- return hbr;
- }
- void ReplaceDesignNo::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- POSITION ppos;
- ppos=m_List1.GetFirstSelectedItemPosition();
- if(ppos==NULL)
- {
- return;
- }
- int iItem=m_List1.GetNextSelectedItem(ppos);
- CString title="$"+m_List1.GetItemText (iItem, 0)+":";
- CString str,spath;
- if(m_image)delete m_image;m_image=NULL;
- str=m_patharray1.ElementAt (iItem);
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if(::CheckFileExist (spath))
- ::LoadImageFromBuf (&m_image, spath);
- else
- ::LoadImageFromBuf (&m_image, str);
- CRect rc;
- GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
- ScreenToClient(rc);
- InvalidateRect(rc);
- CString sel;
- int pos=m_designno.Find (title);
- if(pos!=-1)
- {
- sel=m_designno.Right (m_designno.GetLength ()-pos);
- sel=sel.Right (sel.GetLength ()-title.GetLength ());
- pos=sel.Find ("$");
- if(pos!=-1)
- sel=sel.Left (pos);
- sel.TrimLeft (",");
- sel.TrimRight (",");
- sel=","+sel+",";
- }
- CStringArray list5array;
- for(int i=0; i<m_List4.GetItemCount (); i++)
- {
- title=","+m_List4.GetItemText (i, 0)+",";
- if(sel.Find (title)!=-1)
- list5array.Add (m_patharray2.ElementAt (i));
- }
- try
- {
- ReplaceDesignNo *pDlg=(ReplaceDesignNo*)this;
- CListCtrl *ListCtrl=&pDlg->m_List5;
- CImageList* pImgList=&pDlg->m_ImageListThumb3;
- // reset our image list
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
- // remove all items from list view
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(list5array.GetSize ());
- TCHAR path[MAX_PATH];
-
-
- // Set redraw to FALSE to avoid flickering during adding new items
- ListCtrl->SetRedraw(FALSE);
- int nIndex=0;
- CString str, spath;
-
- for(i=0; i<list5array.GetSize (); i++)
- {
- str=list5array.ElementAt (i);
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=str.Left (str.GetLength ()-4);
- ListCtrl->InsertItem(nIndex, str, nIndex);
- }
- ListCtrl->SetRedraw(TRUE);
- ListCtrl->Invalidate();
- const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
- int XDest, YDest, nDestWidth, nDestHeight;
- nIndex=0;
-
- SolidBrush whitebrush(Color(255,255,255,255));
- for(i=0; i<list5array.GetSize (); i++)
- {
- // Load Image File
- Image *image=NULL;
- Bitmap *pBmp=NULL;
- str=list5array.ElementAt (i);
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if(::CheckFileExist (spath))
- ::LoadImageFromBuf (&image, spath);
- else
- ::LoadImageFromBuf (&image, str);
- int orientation=GetOrientation(image);
- if(orientation==8)
- image->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- image->RotateFlip( Rotate90FlipNone );
-
- if(image->GetWidth()==0)
- continue;
- // Calculate Rect to fit to canvas
-
- const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
- if(fImgRatio > fRatio)
- {
- nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
- XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
- YDest=0;
- nDestHeight=THUMBNAIL_HEIGHT;
- }
- else
- {
- XDest=0;
- nDestWidth=THUMBNAIL_WIDTH;
- nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
- YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
- }
- pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
- Graphics graph2(pBmp);
- graph2.Clear(Color(255,192,192,192));
-
- graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
- Graphics graph(pBmp);
- Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
- // Draw Image
-
- graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
- delete image;
- // Attach to Bitmap and Replace image in CImageList
- CBitmap bitmap;
- HBITMAP hbmp;
- pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
- bitmap.Attach(hbmp);
- pImgList->Replace(i, &bitmap, NULL);
- delete pBmp;
- // Redraw only a current item for removing flickering and fast speed.
- ListCtrl->RedrawItems(i, i);
- // Release used DC and Object
-
- }
- ListCtrl->Invalidate();
- }
- catch(...)
- {
- }
- {
- title="$"+m_List1.GetItemText (iItem, 0)+":";
- int pos=m_replace.Find (title);
- if(pos!=-1)
- {
- m_replacesingle=m_replace.Right (m_replace.GetLength ()-pos);
- m_replacesingle.Delete (0,1);
- pos=m_replacesingle.Find ("$");
- if(pos!=-1)
- m_replacesingle=m_replacesingle.Left (pos);
- m_replacesingle="$"+m_replacesingle;
- }
- else
- m_replacesingle.Empty ();
- UpdateData(false);
- }
- *pResult = 0;
- }
- void ReplaceDesignNo::OnOK()
- {
- // TODO: Add extra validation here
- CString sql="update dindan set designreplaceno='"+m_replace+"' where id='"+m_id+"'";
- g_sendhead.bsql=1;
- g_pMainWnd->ProcessChatMessageRequest2(sql);
- if(g_bSendOK==0)return;
- AfxMessageBox("保存成功!", MB_ICONINFORMATION);
- }
- void ReplaceDesignNo::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- // TODO: Add your message handler code here
- if(m_image)
- {
- CRect rc;
- GetDlgItem(IDC_STATIC3)->GetWindowRect(rc);
- ScreenToClient(rc);
- RectFitDes(m_image->GetWidth(), m_image->GetHeight(), rc);
- Graphics dcgraph(dc.GetSafeHdc());
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- dcgraph.DrawImage(m_image, destinationRect, 0,0,m_image->GetWidth(), m_image->GetHeight(),UnitPixel);
- }
- // Do not call CDialog::OnPaint() for painting messages
- }
- void ReplaceDesignNo::OnButton2()
- {
- // TODO: Add your control notification handler code here
- SetDesignNo dlg;
- dlg.m_id =m_id;
- dlg.DoModal ();
- CString filter="id='"+m_id+"'";
- g_sendhead.code[0]=11;
- g_sendhead.tabcount=1;
- g_sendhead.bsql=0;
- g_pMainWnd->ProcessChatMessageRequest2(filter);
- if(g_bSendOK==0)
- {
- return;
- }
- DataToArray(&g_List1array);
- if(g_List1array.GetSize ())
- {
- m_designno=g_List1array.ElementAt (0).ElementAt (58);
- }
- }
- void ReplaceDesignNo::OnClickList4(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
-
-
- *pResult = 0;
- }
- void ReplaceDesignNo::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(this==GetCapture())
- {
- ReleaseCapture();
- CRect rc;
- m_List5.GetWindowRect (rc);
- ScreenToClient(rc);
- if(rc.PtInRect (point))
- {
- point.x-=rc.left ;
- point.y-=rc.top ;
- POSITION ppos;
- // ppos=m_List5.GetFirstSelectedItemPosition();
- // if(ppos==NULL) return;
- int iItem=m_List5.HitTest(point);//m_List5.GetNextSelectedItem(ppos);
- if(iItem==-1)return;
- m_List5.SetItemState (iItem, LVIS_SELECTED, LVIS_SELECTED);
- CString curno=m_List5.GetItemText (iItem, 0);
- ppos=m_List1.GetFirstSelectedItemPosition();
- if(ppos==NULL) return;
- iItem=m_List1.GetNextSelectedItem(ppos);
- CString curtitle=m_List1.GetItemText (iItem, 0);
- ppos=m_List4.GetFirstSelectedItemPosition();
- if(ppos==NULL) return;
- iItem=m_List4.GetNextSelectedItem(ppos);
- CString curno2=m_List4.GetItemText (iItem, 0);
- if(curno==curno2)return;
- CString title="$"+curtitle+":";
- CString replace=curno+"->"+curno2;
- CString temp;
- int pos=m_replace.Find (title);
- if(pos!=-1)
- {
- CString oldreplace;
- temp=m_replace.Right (m_replace.GetLength ()-pos-title.GetLength ());
- int pos2=temp.Find ("$");
- if(pos2!=-1)
- {
- oldreplace=temp.Left (pos2);
- temp=temp.Right (temp.GetLength ()-pos2);
- }
- else
- {
- oldreplace=temp;
- temp.Empty ();
- }
- if(oldreplace.Find (replace)!=-1)return;
- if(oldreplace.Find (curno+"->")==-1)
- {
- m_replace=m_replace.Left (pos+title.GetLength ());
- if(oldreplace.IsEmpty ())
- {
- m_replace+=replace;
- }
- else
- {
- m_replace+=oldreplace+",";
- m_replace+=replace;
- }
- m_replace+=temp;
- }
- else//已存在
- {
- m_replace=m_replace.Left (pos+title.GetLength ());
- pos=oldreplace.Find (curno+"->");
- CString oldreplaseno=oldreplace.Right (oldreplace.GetLength ()-pos-2-curno.GetLength ());
- pos=oldreplaseno.Find (",");
- if(pos!=-1)
- oldreplaseno=oldreplaseno.Left (pos);
- CString replace2=curno+"->"+oldreplaseno;
- oldreplace.Replace (replace2, replace);
- m_replace+=oldreplace;
- m_replace+=temp;
- }
- }
- else
- {
- m_replace+=title;
- m_replace+=replace;
- }
-
- pos=m_replace.Find (title);
- m_replacesingle=m_replace.Right (m_replace.GetLength ()-pos);
- m_replacesingle.Delete (0,1);
- pos=m_replacesingle.Find ("$");
- if(pos!=-1)
- m_replacesingle=m_replacesingle.Left (pos);
- m_replacesingle="$"+m_replacesingle;
- UpdateData(false);
-
- }
- }
- CDialog::OnLButtonUp(nFlags, point);
- }
- void ReplaceDesignNo::OnBegindragList4(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- // TODO: Add your control notification handler code here
- POSITION ppos;
- ppos=m_List1.GetFirstSelectedItemPosition();
- if(ppos==NULL)
- {
- return;
- }
-
- ppos=m_List4.GetFirstSelectedItemPosition();
- if(ppos==NULL)
- {
- return;
- }
- SetCapture();
- *pResult = 0;
- }
|