// ShowSelPhoto.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "ShowSelPhoto.h" #include "ShowPic22.h" #include "JPEG.h" #define THUMBNAIL_WIDTH 100 #define THUMBNAIL_HEIGHT 90 ///////////////////////////////////////////////////////////////////////////// // ShowSelPhoto dialog IDC_BU Tdelall ShowSelPhoto::ShowSelPhoto(CWnd* pParent /*=NULL*/) : CDialog(ShowSelPhoto::IDD, pParent) { //{{AFX_DATA_INIT(ShowSelPhoto) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bTerminate=false; m_bRunning=false; m_hThread = NULL; m_bTerminate2=false; m_bRunning2=false; m_hThread2 = NULL; } void ShowSelPhoto::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ShowSelPhoto) DDX_Control(pDX, IDC_STATIC1, m_sta1); DDX_Control(pDX, IDC_LIST4, m_List4); DDX_Control(pDX, IDC_LIST1, m_List1); DDX_Control(pDX, IDC_LIST3, m_List3); DDX_Control(pDX, IDC_LIST2, m_List2); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ShowSelPhoto, CDialog) //{{AFX_MSG_MAP(ShowSelPhoto) ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1) ON_WM_DESTROY() ON_NOTIFY(NM_DBLCLK, IDC_LIST4, OnDblclkList4) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ShowSelPhoto message handlers BOOL ShowSelPhoto::OnInitDialog() { CDialog::OnInitDialog(); CRect rc; rc=m_rc; rc.right -=m_rc.Width ()*0.5; MoveWindow(rc); int hei=rc.Height (); m_sta1.GetWindowRect (rc); int hei2=rc.Height (); GetClientRect(rc); rc.bottom -=hei/2; m_List1.MoveWindow (rc); rc.top =rc.bottom+5; rc.bottom =rc.top +hei2; m_sta1.MoveWindow (rc); rc.top =rc.bottom ; rc.bottom =hei; m_List4.MoveWindow (rc); 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_List2.InitStyle(); m_List2.InsertColumn(0,_T("autuid"),LVCFMT_LEFT,0); m_List2.InsertColumn(1,_T("编号"),LVCFMT_LEFT,45); m_List2.InsertColumn(2,_T("商品名称"),LVCFMT_LEFT,150); m_List2.InsertColumn(3,_T("数量"),LVCFMT_LEFT,45); m_List2.InsertColumn(4,_T("照片编号"),LVCFMT_LEFT,410); m_List3.InitStyle(); m_List3.InsertColumn(0,_T("autuid"),LVCFMT_LEFT,0); m_List3.InsertColumn(1,_T("编号"),LVCFMT_LEFT,45); m_List3.InsertColumn(2,_T("商品名称"),LVCFMT_LEFT,150); m_List3.InsertColumn(3,_T("价格"),LVCFMT_LEFT,45); m_List3.InsertColumn(4,_T("数量"),LVCFMT_LEFT,45); m_List3.InsertColumn(5,_T("照片编号"),LVCFMT_LEFT,365); #ifdef CHILD_VERSION CString filter="id='"+m_id+"'"; #else CString filter="id='"+m_id+"' and kind<>'2'"; #endif g_sendhead.code[0]=50; g_sendhead.tabcount=1; g_sendhead.bsql=0; g_pMainWnd->ProcessChatMessageRequest2(filter);if(g_bSendOK==0)return 1; CArraysparray; DataToArray(&sparray); m_patharray1.RemoveAll (); CString str,kind; int list2pos=0; int list3pos=0; m_path=g_path1+"\\"; m_path+=m_id; m_path +="\\"; for(int i=0; im_List1; try { CImageList* pImgList=&pDlg->m_ImageListThumb; // reset our image list for(int i=0; iGetImageCount(); i++) pImgList->Remove(i); // remove all items from list view ListCtrl->DeleteAllItems(); pImgList->SetImageCount(pDlg->m_vFileName.size()); // TCHAR path[MAX_PATH]; vector::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; str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1); str=str.Left (str.Find ('.')); str+=pDlg->GetSelName(str); 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)); Bitmap *pNULLBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB ); Graphics graph2(pNULLBmp); graph2.Clear(Color(255,0,0,0)); 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); BOOL bNullimg=0; if(::CheckFileExist (spath)) ::LoadImageFromBuf (&image, spath); else if(::CheckFileExist (str)) ::LoadImageFromBuf (&image, str); else { bNullimg=1; image=pNULLBmp; } if(image==NULL)continue; if(image->GetWidth()==0) continue; int orientation=GetOrientation(image); if(orientation==8) image->RotateFlip( Rotate270FlipNone ); else if(orientation==6) image->RotateFlip( Rotate90FlipNone ); // 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); if( bNullimg==0) 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 } delete pNULLBmp; ListCtrl->Invalidate(); pDlg->m_bRunning=false; pDlg->m_bTerminate=false; pDlg->PostMessage(WM_USER+200, 0, 0); _endthreadex( 0 ); return 0; } catch(...) { ListCtrl->Invalidate(); pDlg->m_bRunning=false; pDlg->m_bTerminate=false; pDlg->PostMessage(WM_USER+200, 0, 0); _endthreadex( 0 ); } } unsigned __stdcall LoadThumbNail9(LPVOID lpParam) { ShowSelPhoto *pDlg=(ShowSelPhoto*)lpParam; CImageList* pImgList=&pDlg->m_ImageListThumb2; CListCtrl *ListCtrl=&pDlg->m_List4; try { // reset our image list for(int i=0; iGetImageCount(); i++) pImgList->Remove(i); // remove all items from list view ListCtrl->DeleteAllItems(); pImgList->SetImageCount(pDlg->m_vFileName2.size()); TCHAR path[MAX_PATH]; vector::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(...) { ListCtrl->Invalidate(); pDlg->m_bRunning2=false; pDlg->m_bTerminate2=false; _endthreadex( 0 ); } } void ShowSelPhoto::LoadThumbImages() { TerminateThread(); m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail8,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID); m_bRunning=true; } BOOL ShowSelPhoto::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 ShowSelPhoto::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 ShowSelPhoto::OnDestroy() { TerminateThread();TerminateThread2(); CDialog::OnDestroy(); // TODO: Add your message handler code here } void ShowSelPhoto::LoadPhotos() { if(m_bRunning)return; CStringArray *pArray=&m_patharray1; m_vFileName.clear(); int i = 0; for( i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vFileName.push_back(filePath); } LoadThumbImages(); ///////////// m_patharray2.RemoveAll (); m_path.MakeLower (); CStringArray dirarray; CString str; 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( i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vFileName2.push_back(filePath); } TerminateThread2(); m_hThread2 = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail9,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2); m_bRunning2=true; } extern CString GetPathFromNo(CString dir, CString no, CStringArray *pArray); void ShowSelPhoto::GetPath(CString str) { if(m_DirArrayBuf.GetSize ()==0) { CString dir=m_path; dir.TrimRight('\\'); dir+="\\"; CString temp; using namespace helper_coffs; ffsco o; o.dirs(1); o.find(LPCSTR(dir), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); for (it = coo.begin(); coo.end() != it; it ++) { temp=(*it).c_str(); if(::FindArray (&m_DirArrayBuf, temp)==-1 && temp!=dir) { m_DirArrayBuf.Add (temp); } } } str.TrimLeft (","); str.TrimRight (","); if(str.IsEmpty ())return; int pos=str.Find (','); CString path,path2; while(pos!=-1) { path=GetPathFromNo(m_path, str.Left (pos), &m_DirArrayBuf);//+".jpg"; path2=path; path2.Replace ("客户原片", "修好的片"); int pos1=path2.Find (m_id); pos1+=m_id.GetLength (); int pos2=path2.ReverseFind ('\\'); path2=path2.Left (pos1)+path2.Right (path2.GetLength ()-pos2); if(::PathFileExists (path2)) path=path2; if(::FindArray(&m_patharray1, path)==-1)// && ::FindArray(&m_patharray1, &path)!=-1) { m_patharray1.Add (path); } str=str.Right (str.GetLength ()-pos-1); pos=str.Find (','); } path=GetPathFromNo(m_path, str, &m_DirArrayBuf);//+".jpg"; path2=path; path2.Replace ("客户原片", "修好的片"); int pos1=path2.Find (m_id); pos1+=m_id.GetLength (); int pos2=path2.ReverseFind ('\\'); path2=path2.Left (pos1)+path2.Right (path2.GetLength ()-pos2); if(::PathFileExists (path2)) path=path2; if(::FindArray(&m_patharray1, path)==-1)// && ::FindArray(&m_patharray1, &path)!=-1) m_patharray1.Add (path); } CString ShowSelPhoto::GetSelName(CString name) { CString ret; name=","+name+","; int i = 0; for( i=0; iPumpMessage()) break; } } ::CloseHandle(m_hThread2); return TRUE; } void ShowSelPhoto::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; }