123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- #include "stdafx.h"
- #include "LYFZSendMsg.h"
- #include "ShowPic.h"
- #include "ShowPic22.h"
- #include "JPEG.h"
- #define THUMBNAIL_WIDTH 100
- #define THUMBNAIL_HEIGHT 90
-
- ShowPic::ShowPic(CWnd* pParent )
- : CDialog(ShowPic::IDD, pParent)
- {
-
-
-
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_mode=0;
- }
- void ShowPic::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
-
- DDX_Control(pDX, IDC_LIST1, m_List1);
- DDX_Control(pDX, IDC_COMBO1, m_combo1);
-
- }
- BEGIN_MESSAGE_MAP(ShowPic, CDialog)
-
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_BUTdelall, OnBUTdelall)
- ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
-
- END_MESSAGE_MAP()
- 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));
- }
- LoadPhotos();
- return TRUE;
-
- }
- 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;
-
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
-
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vFileName.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
-
- 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++)
- {
-
- 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;
-
-
- 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);
-
-
- graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
- delete image;
-
- CBitmap bitmap;
- HBITMAP hbmp;
- pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
- bitmap.Attach(hbmp);
- pImgList->Replace(nIndex, &bitmap, NULL);
- delete pBmp;
-
- ListCtrl->RedrawItems(nIndex, nIndex);
-
-
- }
-
- 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)
- {
-
- 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();
-
- }
- 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(...)
- {
- }
- }
- 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()
- {
-
-
- if(AfxMessageBox("删除后将无法恢复, 确认删除吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
- CString path=m_path;
- path.TrimRight ('\\');
- DeleteDirectory(path);
- LoadPhotos();
- }
- void ShowPic::OnBUTdel()
- {
-
- 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();
- }
|