// ShowPic.cpp : implementation file // #include "stdafx.h" #include "LYFZIPManage.h" #include "ShowPic.h" #include "ShowPic22.h" #include "JPEG.h" #define THUMBNAIL_WIDTH 100 #define THUMBNAIL_HEIGHT 90 ///////////////////////////////////////////////////////////////////////////// // ShowPic dialog ShowPic::ShowPic(CWnd* pParent /*=NULL*/) : CDialog(ShowPic::IDD, pParent) { //{{AFX_DATA_INIT(ShowPic) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bTerminate=false; m_bRunning=false; m_hThread = NULL; m_mode=0; } void ShowPic::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ShowPic) DDX_Control(pDX, IDC_LIST1, m_List1); DDX_Control(pDX, IDC_COMBO1, m_combo1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ShowPic, CDialog) //{{AFX_MSG_MAP(ShowPic) ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTdelall, OnBUTdelall) ON_BN_CLICKED(IDC_BUTdel, OnBUTdel) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // ShowPic message handlers BOOL ShowPic::OnInitDialog() { CDialog::OnInitDialog(); CRect rc2; GetWindowRect(rc2); ::MoveWindow(m_hWnd,g_rc.left,g_rc.top,g_rc.Width(),g_rc.Height(),TRUE); EnumChildWindows(m_hWnd,(WNDENUMPROC)EnumChildProc,0); GetClientRect(rc2); rc2.top +=35*g_fscaley; m_List1.MoveWindow (rc2); GetDlgItem(IDC_BUTdelall)->GetWindowRect(rc2); int hei=rc2.Height (); ScreenToClient(rc2); rc2.top =5; rc2.bottom =rc2.top +hei; GetDlgItem(IDC_BUTdelall)->MoveWindow(rc2); GetDlgItem(IDC_BUTdel)->GetWindowRect(rc2); ScreenToClient(rc2); rc2.top =5; rc2.bottom =rc2.top +hei; GetDlgItem(IDC_BUTdel)->MoveWindow(rc2); GetDlgItem(IDOK)->GetWindowRect(rc2); ScreenToClient(rc2); rc2.top =5; rc2.bottom =rc2.top +hei; GetDlgItem(IDOK)->MoveWindow(rc2); if(m_mode==1)//拍照 { GetDlgItem(IDC_BUTdelall)->EnableWindow(IsHasRights2new(34)); GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(34)); } else if(m_mode==2)//初修 { GetDlgItem(IDC_BUTdelall)->EnableWindow(IsHasRights2new(35)); GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(35)); } else if(m_mode==3)//精修 { GetDlgItem(IDC_BUTdelall)->EnableWindow(IsHasRights2new(36)); GetDlgItem(IDC_BUTdel)->EnableWindow(IsHasRights2new(36)); } /* CString path; // TODO: Add extra initialization here using namespace helper_coffs; ffsco o; o.dirs(0); o.find(LPCSTR(m_path), LPCSTR("*.jpg")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); for (it = coo.begin(); coo.end() != it; it ++) { path=(*it).c_str(); if(path.GetAt (path.ReverseFind ('\\')+1)!='s') { path.MakeLower (); m_patharray1.Add (path); } }*/ ////////// LoadPhotos(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void LoadImageFromFile(Image **img, CString path) { try { if(!::PathFileExists (path))return; if(*img)delete *img; *img=NULL; BSTR bstr= path.AllocSysString(); *img= Image::FromFile(bstr); SysFreeString(bstr); } catch(...) { } } unsigned __stdcall LoadThumbNail(LPVOID lpParam) { try { ShowPic *pDlg=(ShowPic*)lpParam; CListCtrl *ListCtrl=&pDlg->m_List1; 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; 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_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(::PathFileExists (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; return 0; } catch(...) { } } void ShowPic::LoadThumbImages() { } BOOL ShowPic::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 ShowPic::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 ShowPic::OnDestroy() { CDialog::OnDestroy(); TerminateThread(); // TODO: Add your message handler code here } void DeleteDirectory(CString strDir) { try { // 首先删除文件及子文件夹 CFileFind ff; BOOL bFound = ff.FindFile(strDir+"\\*", 0); while(bFound) { bFound = ff.FindNextFile(); if(ff.GetFileName()=="."||ff.GetFileName()=="..") continue; // 去掉文件(夹)只读等属性 SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL); if(ff.IsDirectory()) { // 递归删除子文件夹 DeleteDirectory(ff.GetFilePath()); RemoveDirectory(ff.GetFilePath()); } else { DeleteFile(ff.GetFilePath()); // 删除文件 } } ff.Close(); // 然后删除该文件夹 RemoveDirectory(strDir); } catch(...) { } // int SHFileOperation( LPSHFILEOPSTRUCT lpFileOp ); } void ShowPic::LoadPhotos() { m_patharray1.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(int i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vFileName.push_back(filePath); } LoadThumbImages(); } void ShowPic::OnBUTdelall() { /* static BOOL bmode=0; bmode=!bmode; CDC *pDC=GetDC(); if(1) { Graphics graph(pDC->GetSafeHdc ()); DWORD begin=::GetTickCount (); CString str; for(int i=0; iGetThumbnailImage(800,600, NULL, NULL); graph.DrawImage(m_pTemp, 0, 0); delete img; delete m_pTemp; } str.Format ("gdi+:%d, count:%d", ::GetTickCount ()-begin, m_patharray1.GetSize ()); MessageBox(str); } else { CRect rc(0,0,100,100); DWORD begin=::GetTickCount (); CString str; for(int i=0; i