123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- // 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; 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_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; 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;
- str.MakeLower ();
- m_patharray1.Add (str);
- }
- }
- }
- m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
- if(m_bRunning)return;
- 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();
- }
- 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; i<m_patharray1.GetSize (); i++)
- {
- Image *img=NULL;
- ::LoadImageFromBuf(&img, m_patharray1.ElementAt (i));
- Image *m_pTemp=img->GetThumbnailImage(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<m_patharray1.GetSize (); i++)
- {
- CPicture pic;
- pic.Load (m_patharray1.ElementAt (i));
- pic.RenderBmp (pDC, rc);
- pic.UnloadPicture ();
- }
- str.Format ("jpg:%d, count:%d", ::GetTickCount ()-begin, m_patharray1.GetSize ());
- MessageBox(str);
- }
- ReleaseDC(pDC);
- return; */
- // TODO: Add your control notification handler code here
- if(AfxMessageBox("删除后将无法恢复, 确认删除吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- CString path=m_path;
- path.TrimRight ('\\');
- DeleteDirectory(path);
- LoadPhotos();
- }
- void ShowPic::OnBUTdel()
- {
- // TODO: Add your control notification handler code here
- POSITION pos;
- pos=m_List1.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- AfxMessageBox("请先选中您要删除的照片!", MB_ICONINFORMATION);
- return;
- }
- if(AfxMessageBox("删除后将无法恢复, 确认删除吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- while (pos)
- {
- int iItem=m_List1.GetNextSelectedItem(pos);
- CString title=m_List1.GetItemText (iItem, 0);
- ::DeleteFile (m_path+title+".jpg");
- ::DeleteFile (m_path+"s"+title+".jpg");
- }
- LoadPhotos();
- }
|