123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- // ShowSelPhoto2.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowSelPhoto2.h"
- #include "ShowPic22.h"
- #include "JPEG.h"
- #include "ComparePhoto.h"
- #define THUMBNAIL_WIDTH 100
- #define THUMBNAIL_HEIGHT 90
-
- ShowSelPhoto2::ShowSelPhoto2(CWnd* pParent /*=NULL*/) : CDialog(ShowSelPhoto2::IDD, pParent)
- {
- m_bTerminate2=false;
- m_bRunning2=false;
- m_hThread2 = NULL;
- }
- void ShowSelPhoto2::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LIST4, m_List4);
- }
- BEGIN_MESSAGE_MAP(ShowSelPhoto2, CDialog)
- ON_WM_DESTROY()
- ON_NOTIFY(NM_DBLCLK, IDC_LIST4, OnDblclkList4)
- END_MESSAGE_MAP()
- BOOL ShowSelPhoto2::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- CRect rc;
- rc=m_rc;
- rc.right -=m_rc.Width ()*0.5;
- MoveWindow(rc);
- GetClientRect(rc);
- m_List4.MoveWindow (rc);
- m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List4.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL);
- m_path=g_path1+"\\";
- m_path+=m_id;
- m_path +="\\";
-
- LoadPhotos();
- return TRUE;
- }
-
- unsigned __stdcall LoadThumbNail10(LPVOID lpParam)
- {
- ShowSelPhoto2 *pDlg=(ShowSelPhoto2*)lpParam;
- CImageList* pImgList=&pDlg->m_ImageListThumb2;
- CListCtrl *ListCtrl=&pDlg->m_List4;
- try
- {
- // 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++)
- {
- ListCtrl->InsertItem(nIndex, pDlg->m_patharray2.ElementAt (nIndex), 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 (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_bRunning2=false;
- pDlg->m_bTerminate2=false;
- _endthreadex( 0 );
- return 0;
- }
- catch(...)
- {
- ListCtrl->Invalidate();
- pDlg->m_bRunning2=false;
- pDlg->m_bTerminate2=false;
- _endthreadex( 0 );
- }
- }
- void ShowSelPhoto2::OnDestroy()
- {
- TerminateThread2();
- CDialog::OnDestroy();
- }
- void ShowSelPhoto2::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)
- {
- CString spath,name;
- for(int i=0; i<dirarray.GetSize (); i++)
- {
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1);
- 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);
- {
- spath.Empty ();
- if(str.Left (str.ReverseFind ('\\')+1)!=m_path)
- {
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath= spath.Right (spath.GetLength ()-m_path.GetLength ());
- }
- name=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- name=spath+name.Left (name.GetLength ()-4);
- m_patharray2.Add (name);
- }
- str.Replace ("¿Í»§ÔƬ", "ÐÞºÃµÄÆ¬");
- int pos1=str.Find (m_id);
- pos1+=m_id.GetLength ();
- int pos2=str.ReverseFind ('\\');
- str=str.Left (pos1)+str.Right (str.GetLength ()-pos2);
- if(::PathFileExists (str))
- {
- m_patharray1.Add (str);
- m_patharray2.Add (name+"-ÐÞÆ¬");
- }
- }
- }
- }
- if(m_bRunning2)return;
- CStringArray *pArray=&m_patharray1;
- m_vFileName2.clear();
- for(int 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, LoadThumbNail10,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
- m_bRunning2=true;
- }
-
- BOOL ShowSelPhoto2::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 ShowSelPhoto2::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
- {
- 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_patharray1;
- dlg.DoModal ();
- *pResult = 0;
- }
- BOOL ShowSelPhoto2::PreTranslateMessage(MSG* pMsg)
- {
- if(pMsg->message==WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- case VK_F1:
- {
- ShowWindow(0);
- }
- break;
- case VK_RETURN:
- {
- POSITION pos;
- pos=m_List4.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return 1;
- }
- CArray<int,int>posarray;
- int iItem=m_List4.GetNextSelectedItem(pos);
- posarray.Add (iItem);
- while (pos)
- {
- int iItem=m_List4.GetNextSelectedItem(pos);
- posarray.Add (iItem);
- if(posarray.GetSize ()>1)break;
- }
- if(posarray.GetSize ()>=2)
- {
- CComparePhoto dlg;
- dlg.m_path1=m_patharray1.ElementAt (posarray.ElementAt(0));
- dlg.m_path2=m_patharray1.ElementAt (posarray.ElementAt(1));
- dlg.DoModal();
- return 1;
- }
- }
- return 1;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
|