123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089 |
- // ShowPic22.cpp : implementation file
- //
- #include "stdafx.h"
- #include "LYFZIPManage.h"
- #include "ShowPic22.h"
- #include "MyLock.h"
- /////////////////////////////////////////////////////////////////////////////
- // ShowPic22 dialog
- HANDLE Lock(char* name)
- {
- try
- {
- HANDLE mutex;
- // Try to open an exist mutex firstly.
- mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name);
- if(NULL == mutex) // If the mutex does not exist, create it with the certain name.
- {
- mutex = CreateMutex(NULL, TRUE, name);
- }
- else // If the mutex already exist, wait for other thread release it.
- {
- WaitForSingleObject(mutex, INFINITE);
- }
- return mutex;
- }
- catch(...)
- {
- }
- }
- bool Unlock(HANDLE mutex)
- {
- try
- {
- if(0 == ReleaseMutex(mutex)) // Failed to release mutex
- {
- return false;
- }
- else // Successed in release mutex
- {
- CloseHandle(mutex);
- mutex = NULL;
- return true;
- }
- }
- catch(...)
- {
- }
- }
- ShowPic22::ShowPic22(CWnd* pParent /*=NULL*/)
- : CDialog(ShowPic22::IDD, pParent)
- {
- //{{AFX_DATA_INIT(ShowPic22)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_pImage=NULL;
- m_pImagesmall=NULL;
- m_pImagetemp=NULL;
- m_pbmp=NULL;
- m_pParent=NULL;
- m_bauto=0;
- m_fscale=1;
- m_bScroll=0;
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bProcessing=0;
- m_bInit=0;
- }
- void ShowPic22::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(ShowPic22)
- DDX_Control(pDX, IDC_STATIC1, m_sta1);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(ShowPic22, CDialog)
- //{{AFX_MSG_MAP(ShowPic22)
- ON_WM_PAINT()
- ON_WM_DESTROY()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEWHEEL()
- ON_WM_ERASEBKGND()
- ON_WM_RBUTTONDOWN()
- ON_WM_TIMER()
- ON_WM_CLOSE()
- ON_WM_MOUSEMOVE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // ShowPic22 message handlers
- extern void LoadImageFromFile(Image **img, CString path);
- BOOL ShowPic22::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- return 1;
- }
- unsigned __stdcall GenThumbImgThread(LPVOID lpParam)
- {
- try
- {
- ShowPic22 *pThis=(ShowPic22*)lpParam;
- int posbak=pThis->m_pos;
- int pos;
- BOOL bNext=1;
- BOOL bFirst=1;
- int count;
- while(1)
- {
- if(pThis->m_bTerminate)break;
- if( pThis->m_bauto || (pThis->m_bInit==0 && bFirst==0) )
- {
- ::Sleep (1000);
- continue;
- }
- if(bFirst)
- count=2;
- else
- count=5;
- bFirst=0;
- for(int i=0; i<count; i++)
- {
- if(pThis->m_bTerminate)break;
- if(pThis->m_bauto)break;
- if(posbak!=pThis->m_pos)
- {
- if(pThis->m_pos>posbak)
- bNext=1;
- else
- bNext=0;
- posbak=pThis->m_pos;i=0;continue;
- }
- if(bNext)
- {
- switch(i)
- {
- case 0:
- pos=posbak;
- break;
- case 1:
- pos=posbak+1;
- break;
- case 2:
- pos=posbak+2;
- break;
- case 3:
- pos=posbak-1;
- break;
- case 4:
- pos=posbak+3;
- break;
- }
- }
- else
- {
- switch(i)
- {
- case 0:
- pos=posbak;
- break;
- case 1:
- pos=posbak-1;
- break;
- case 2:
- pos=posbak-2;
- break;
- case 3:
- pos=posbak+1;
- break;
- case 4:
- pos=posbak-3;
- break;
- }
- }
- HANDLE handle=Lock("shgenimagethread");
- while(pos>=pThis->m_pPathArray->GetSize ())
- pos-=pThis->m_pPathArray->GetSize ();
- while(pos<0)
- pos+=pThis->m_pPathArray->GetSize ();
- BOOL bFind=0;
- for(int n=0; n<pThis->m_nPosArray.GetSize (); n++)
- {
- if(pos==pThis->m_nPosArray.ElementAt (n))
- {
- bFind=1;
- break;
- }
- }
- if(bFind)
- {
- Unlock(handle);
- continue;
- }
- CString path=pThis->m_pPathArray->ElementAt (pos);
- Image *img=NULL;
- Image *imgsmall=NULL;
- ::LoadImageFromBuf (&img, path);
- if(img==NULL)
- {
- Unlock(handle);
- continue;
- }
- if(img->GetWidth()==0)
- {
- Unlock(handle);
- continue;
- }
- int orientation=GetOrientation(img);
- if(orientation==8)
- img->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- img->RotateFlip( Rotate90FlipNone );
- CRect rc;
- pThis->InitRc(img, rc);
- imgsmall=img->GetThumbnailImage(rc.Width (), rc.Height (), NULL, NULL);
- Graphics graphic(imgsmall);//防止GetThumbnailImage影响质量
- graphic.DrawImage(img, 0,0,imgsmall->GetWidth(), imgsmall->GetHeight() );
- pThis->m_pImageArray.Add (img);
- pThis->m_pImageSmallArray.Add (imgsmall);
- pThis->m_nPosArray.Add (pos);
- if(pThis->m_pImageArray.GetSize ()>10)
- {
- if(pThis->m_pImage!=pThis->m_pImageArray.ElementAt (0))
- {
- delete pThis->m_pImageArray.ElementAt (0);
- delete pThis->m_pImageSmallArray.ElementAt (0);
- pThis->m_pImageArray.RemoveAt(0);
- pThis->m_pImageSmallArray.RemoveAt(0);
- pThis->m_nPosArray.RemoveAt(0);
- }
- }
- Unlock(handle);
- }
- ::Sleep (1000);
- }
- pThis->m_bRunning=false;
-
- return 0;
- }
- catch(...)
- {
- }
- }
- BOOL ShowPic22::OnInitDialog()
- {
- CDialog::OnInitDialog();
- try
- {
- g_nSendCode=0;
- TerminateThread();
-
- g_bInSkin=1;
- // TODO: Add extra initialization here
- m_rcscreen=CRect(0, 0, g_dm.dmPelsWidth, g_dm.dmPelsHeight);
- ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_dm.dmPelsWidth,g_dm.dmPelsHeight,SWP_SHOWWINDOW);
- m_pbmp=new Bitmap(g_dm.dmPelsWidth, g_dm.dmPelsHeight, PixelFormat24bppRGB );
- // LoadImage();
- if(m_pParent)
- m_pParent->m_showpichwd=m_hWnd;
- m_dlg.Create (IDD_DLGAnimateWindow, this);
- m_dlg.m_pParent =this;
- m_dlg.m_pbmp =m_pbmp;
- m_dlg.m_pRc=&m_rc;
- m_dlg.MoveWindow (m_rcscreen);
-
- m_PicBar.SetLiaPath ("4.lia");
- m_PicBar.Create (IDD_DLGmydlg, this);
- if(m_PicBar.m_bInit)
- {
- m_PicBar.m_pParent =this;
- int hei;
- m_PicBar.GetWindowRect (m_picbarrc);
- hei=m_picbarrc.Height ();
- m_picbarrc.bottom =g_dm.dmPelsHeight-10;
- m_picbarrc.top =m_picbarrc.bottom-hei;
- m_PicBar.MoveWindow (m_picbarrc);
- m_startpt2.x=m_startpt2.y=0;
- }
- // SetTimer(4, 500, NULL);
- m_sta1.SetFocus();
- // ::SetForegroundWindow (m_hWnd);
- LoadImage();
- }
- catch(...)
- {
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void ShowPic22::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: Add your message handler code here
- try
- {
- CRect rc;
- GetClientRect(rc);
- if(m_pImage && m_bauto==0)
- {
- Graphics graph(m_pbmp);
- graph.Clear(Color(255,0,0,0));
- Image *img;
- if(m_pImagetemp && m_bScroll==0)
- img=m_pImagetemp;
- else
- img=m_pImagesmall;
- m_bScroll=0;
- int width,height;
- width=img->GetWidth();
- height=img->GetHeight();
- ///////////////
- Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () );
- graph.DrawImage(img, destinationRect, 0,0,width,height,UnitPixel);
- Graphics graph2(dc.GetSafeHdc ());
- graph2.DrawImage(m_pbmp,0,0);
- }
- else
- {
- // dc.FillSolidRect (rc, 0);
- }
- }
- catch(...)
- {
- }
- // Do not call CDialog::OnPaint() for painting messages
- }
- void ShowPic22::OnDestroy()
- {
- CDialog::OnDestroy();
- try
- {
- g_nSendCode=0;
- for(int n=0; n<m_nPosArray.GetSize (); n++)
- {
- m_pImage=m_pImageArray.ElementAt (n);
- m_pImagesmall=m_pImageSmallArray.ElementAt (n);
- delete m_pImage;
- delete m_pImagesmall;
- }
-
- if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
- if(m_pbmp) delete m_pbmp;m_pbmp=NULL;
- KillTimer(1);
- }
- catch(...)
- {
- }
- // m_pic.UnloadPicture ();
- // TODO: Add your message handler code here
- }
- void ShowPic22::LoadImage()
- {
- try
- {
- ::SetForegroundWindow (m_hWnd);
- KillTimer(5);
- m_pImage=m_pImagesmall=NULL;
- for(int n=0; n<m_nPosArray.GetSize (); n++)
- {
- if(m_pos==m_nPosArray.ElementAt (n))
- {
- m_pImage=m_pImageArray.ElementAt (n);
- m_pImagesmall=m_pImageSmallArray.ElementAt (n);
- break;
- }
- }
- if( m_pImage==NULL && ( m_bauto || m_bInit==0) )
- {
- HANDLE handle=Lock("shgenimagethread");
- CString path=m_pPathArray->ElementAt (m_pos);
- ::LoadImageFromBuf (&m_pImage, path);
- if(m_pImage==NULL)
- {
- Unlock(handle);
- return;
- }
- if(m_pImage->GetWidth()==0)
- {
- Unlock(handle);
- return;
- }
- int orientation=GetOrientation(m_pImage);
- if(orientation==8)
- m_pImage->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- m_pImage->RotateFlip( Rotate90FlipNone );
- InitRc();
- m_pImagesmall=m_pImage->GetThumbnailImage(m_rc.Width (), m_rc.Height (), NULL, NULL);
- Graphics graphic(m_pImagesmall);//防止GetThumbnailImage影响质量
- graphic.DrawImage(m_pImage, 0,0,m_pImagesmall->GetWidth(), m_pImagesmall->GetHeight() );
- m_pImageArray.Add (m_pImage);
- m_pImageSmallArray.Add (m_pImagesmall);
- m_nPosArray.Add (m_pos);
- if(m_pImageArray.GetSize ()>10)
- {
- if(m_pImage!=m_pImageArray.ElementAt (0))
- {
- delete m_pImageArray.ElementAt (0);
- delete m_pImageSmallArray.ElementAt (0);
- m_pImageArray.RemoveAt(0);
- m_pImageSmallArray.RemoveAt(0);
- m_nPosArray.RemoveAt(0);
- }
- }
- Unlock(handle);
- }
- else if(m_pImage==NULL)
- {
- SetTimer(5, 1, NULL);
- return ;
- }
-
- // if(m_pImage) delete m_pImage;m_pImage=NULL;
- // if(m_pImagesmall) delete m_pImagesmall;m_pImagesmall=NULL;
- if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
- /* CString path=m_pPathArray->ElementAt (m_pos);
- ::LoadImageFromBuf (&m_pImage, path);
- if(m_pImage==NULL)return;
- if(m_pImage->GetWidth()==0)return;
- int orientation=GetOrientation(m_pImage);
- if(orientation==8)
- m_pImage->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- m_pImage->RotateFlip( Rotate90FlipNone );*/
- InitRc();
- // m_pImagesmall=m_pImage->GetThumbnailImage(m_rc.Width (), m_rc.Height (), NULL, NULL);
- // Graphics graphic(m_pImagesmall);//防止GetThumbnailImage影响质量
- // graphic.DrawImage(m_pImage, 0,0,m_pImagesmall->GetWidth(), m_pImagesmall->GetHeight() );
- if(m_bauto )
- {
- if(m_dlg.m_effect ==1 || m_dlg.m_effect ==2)
- {
- CDC *pDC=GetDC();
- HDC hdc=::GetDC(NULL);
- ::BitBlt (pDC->GetSafeHdc (), 0, 0, g_dm.dmPelsWidth, g_dm.dmPelsHeight , hdc, 0, 0, SRCCOPY);
- ReleaseDC(pDC);
- }
-
- m_dlg.m_time =m_PicBar.m_time*1000;
- m_dlg.SetImage (m_pImagesmall);
- if(m_dlg.m_effect ==1 || m_dlg.m_effect ==2)
- {
- m_dlg.ShowWindow (SW_HIDE);
- }
- m_dlg.ShowAlpha();
- }
- else
- Invalidate();
- }
- catch(...)
- {
- }
- }
- void ShowPic22::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- SetCapture();
- m_startpt=point;
- CDialog::OnLButtonDown(nFlags, point);
- }
- void ShowPic22::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(GetCapture()!=this)return;
- if(m_rc.Width ()>m_rcscreen.Width ())
- {
- if(m_rc.left <m_rcscreen.left && point.x>m_startpt.x)
- {
- int dt=min(point.x-m_startpt.x, m_rcscreen.left-m_rc.left);
- m_rc.left +=dt;
- m_rc.right +=dt;
- }
- else if(m_rc.right >m_rcscreen.right && point.x<m_startpt.x)
- {
- int dt=min(m_startpt.x-point.x, m_rc.right-m_rcscreen.right);
- m_rc.left -=dt;
- m_rc.right -=dt;
- }
- }
- if(m_rc.Height ()>m_rcscreen.Height ())
- {
- if(m_rc.top <m_rcscreen.top && point.y>m_startpt.y)
- {
- int dt=min(point.y-m_startpt.y, m_rcscreen.top-m_rc.top);
- m_rc.top +=dt;
- m_rc.bottom +=dt;
- }
- else if(m_rc.bottom >m_rcscreen.bottom && point.y<m_startpt.y)
- {
- int dt=min(m_startpt.y-point.y, m_rc.bottom-m_rcscreen.bottom);
- m_rc.top -=dt;
- m_rc.bottom -=dt;
- }
- }
- m_startpt=point;
- Invalidate();
- CDialog::OnMouseMove(nFlags, point);
- }
- void ShowPic22::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(GetCapture()!=this)return;
- ReleaseCapture();
- CDialog::OnLButtonUp(nFlags, point);
- }
- BOOL ShowPic22::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_pImage==NULL)return 1;
- if(m_bauto)return 1;if(m_bProcessing)return 1;
- m_bScroll=1;
- if(zDelta>0)
- {
- // if(m_fscale>4)return 1;
- m_fscale*=1.2;
- int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
- int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
-
- m_rc.left -=dtx;
- m_rc.right +=dtx;
- m_rc.top -=dty;
- m_rc.bottom +=dty;
-
- Invalidate();
- }
- else
- {
- if(m_fscale<=1)return 1;
- m_fscale/=1.2;
- if(m_fscale<1)m_fscale=1;
- int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
- int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
-
- m_rc.left -=dtx;
- m_rc.right +=dtx;
- m_rc.top -=dty;
- m_rc.bottom +=dty;
- if(m_rcbak.Height ()==m_rcscreen.Height ())
- {
- if(m_rc.top <m_rcscreen.top && m_rc.bottom < m_rcscreen.bottom )
- {
- dtx=m_rcscreen.bottom -m_rc.bottom;
- m_rc.top +=dtx;
- m_rc.bottom +=dtx;
- }
- else if(m_rc.top >m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom )
- {
- dtx=m_rc.top-m_rcscreen.top;
- m_rc.top -=dtx;
- m_rc.bottom -=dtx;
- }
- dtx=m_rc.Width ();
- m_rc.left =(m_rcscreen.Width ()-dtx)/2;
- m_rc.right =m_rc.left +dtx;
-
- }
- if(m_rcbak.Width ()==m_rcscreen.Width ())
- {
- if(m_rc.left <m_rcscreen.left && m_rc.right < m_rcscreen.right )
- {
- dtx=m_rcscreen.right -m_rc.right;
- m_rc.left +=dtx;
- m_rc.right +=dtx;
- }
- else if(m_rc.left >m_rcscreen.left && m_rc.right > m_rcscreen.right )
- {
- dtx=m_rc.left-m_rcscreen.left;
- m_rc.left -=dtx;
- m_rc.right -=dtx;
- }
- dtx=m_rc.Height ();
- m_rc.top =(m_rcscreen.Height ()-dtx)/2;
- m_rc.bottom =m_rc.top +dtx;
-
- }
- Invalidate();
- /* int dtx=(m_fscale-1)*m_rcbak.Width ()/2.0;
- int dty=(m_fscale-1)*m_rcbak.Height ()/2.0;
- m_rc=m_rcbak;
- m_rc.left -=dtx;
- m_rc.right +=dtx;
- m_rc.top -=dty;
- m_rc.bottom +=dty;
- Invalidate();*/
- }
- KillTimer(2);
- SetTimer(2, 100, NULL);
- return CDialog::OnMouseWheel(nFlags, zDelta, pt);
- }
- BOOL ShowPic22::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(pMsg->message==WM_MOUSEMOVE )
- {
- if(m_PicBar.m_bInit && m_pImage)
- {
- CPoint point;
- ::GetCursorPos (&point);
- if( abs(m_startpt2.x -point.x )>5 || abs(m_startpt2.y -point.y )>5)
- {
- m_startpt2=point;
- m_PicBar.ShowWindow (SW_SHOW);
- SetTimer(3, 1500, NULL);
- }
- }
- }
- else if(pMsg->message==WM_KEYDOWN )
- {
- switch (pMsg->wParam)
- {
- case VK_RETURN:
- return 1;
- case VK_ESCAPE:
- KillTimer(6);
- SetTimer(6, 100, NULL);
- return 1;
- case VK_F3:
- AutoPic();
- break;
- case VK_UP:
- Rotate1();
- return 1;
- case VK_LEFT:
- Pre();
- return 1;
- case VK_DOWN:
- Rotate2();
- return 1;
- case VK_RIGHT:
- Next();
- return 1;
- case VK_DELETE:
- if(m_bauto)return 1;
- if(m_pParent)
- {
- if(m_bProcessing)return 1;
- m_bProcessing=1;
- ::SetForegroundWindow (m_hWnd);
- if(m_pParent)
- {
- for(int i=0; i<m_pParent->m_List1.GetItemCount (); i++)
- {
- m_pParent->m_List1.SetItemState (i, 0, -1);
- }
- m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
- }
- if(m_pParent->OnDel())
- {
- ::SetForegroundWindow (m_hWnd);
- // TerminateThread();
- HANDLE handle=Lock("shgenimagethread");
- m_pImage=m_pImagesmall=NULL;
- for(int n=0; n<m_nPosArray.GetSize (); n++)
- {
- if(m_pos==m_nPosArray.ElementAt (n))
- {
- delete m_pImageArray.ElementAt (n);
- delete m_pImageSmallArray.ElementAt (n);
- m_pImageArray.RemoveAt(n);
- m_pImageSmallArray.RemoveAt(n);
- m_nPosArray.RemoveAt(n);
- }
- }
- if(m_pos>=this->m_pPathArray->GetSize ())
- m_pos=0;
- Unlock(handle);
-
- LoadImage();
- m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
- }
- m_bProcessing=0;
- return 1;
- }
- }
- ::SetForegroundWindow (m_hWnd);
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void ShowPic22::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_bauto)return;if(m_bProcessing)return;
- if(m_pParent)
- {
- for(int i=0; i<m_pParent->m_List1.GetItemCount (); i++)
- {
- m_pParent->m_List1.SetItemState (i, 0, -1);
- }
- m_pParent->m_List1.SetItemState (m_pos, LVIS_SELECTED, LVIS_SELECTED);
- m_pParent->OnRclickList1();
- }
- CDialog::OnRButtonDown(nFlags, point);
- }
- void ShowPic22::AutoPic()
- {
- try
- {
- if(m_bProcessing)return;
- m_dlg.m_effect=m_PicBar.m_nType;
- m_bauto=!m_bauto;
- m_PicBar.ChangeBtn();
- if(m_bauto)
- {
- m_pos=0;
- LoadImage();
- }
- else
- {
- KillTimer(1);
- m_dlg.TerminateThread ();
- m_dlg.ShowWindow (SW_HIDE);
- }
- ::SetForegroundWindow (m_hWnd);
- }
- catch(...)
- {
- }
- }
- void ShowPic22::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- try
- {
- ::SetForegroundWindow (m_hWnd);
- if(nIDEvent==1)
- {
- KillTimer(1);
- m_pos++;
- if(m_pos>=this->m_pPathArray->GetSize ())
- {
- KillTimer(1);
- m_bauto=0;
- m_dlg.TerminateThread ();
- m_dlg.ShowWindow (SW_HIDE);
- m_PicBar.ChangeBtn();
- AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
- return;
- }
- LoadImage();
- }
- else if(nIDEvent==2)
- {
- KillTimer(2);
- if(m_pImagetemp)
- {
- if(m_rc.Width ()>m_pImagetemp->GetWidth())
- {
- if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
- m_pImagetemp=m_pImage->GetThumbnailImage(min(m_pImage->GetWidth(),m_rc.Width ()), min(m_pImage->GetHeight(),m_rc.Height ()), NULL, NULL);
- Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
- graphic.DrawImage(m_pImage, 0,0,m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight() );
- }
- }
- else
- {
- m_pImagetemp=m_pImage->GetThumbnailImage(min(m_pImage->GetWidth(),m_rc.Width ()), min(m_pImage->GetHeight(),m_rc.Height ()), NULL, NULL);
- Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
- graphic.DrawImage(m_pImage, 0,0,m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight() );
- }
- Invalidate();
- }
- else if(nIDEvent==3)
- {
- KillTimer(3);
- CPoint pt;
- ::GetCursorPos (&pt);
- if(m_picbarrc.PtInRect (pt))
- {
- SetTimer(3, 1500, NULL);
- }
- else
- m_PicBar.ShowWindow (SW_HIDE);
- ::SetForegroundWindow (m_hWnd);
- }
- else if(nIDEvent==4)
- {
- KillTimer(4);
- m_PicBar.SetLiaPath ("4.lia");
- m_PicBar.Create (IDD_DLGmydlg, this);
- if(m_PicBar.m_bInit)
- {
- m_PicBar.m_pParent =this;
- int hei;
- m_PicBar.GetWindowRect (m_picbarrc);
- hei=m_picbarrc.Height ();
- m_picbarrc.bottom =g_dm.dmPelsHeight-10;
- m_picbarrc.top =m_picbarrc.bottom-hei;
- m_PicBar.MoveWindow (m_picbarrc);
- SetTimer(3, 1500, NULL);
- m_startpt2.x=m_startpt2.y=0;
- }
- ::SetForegroundWindow (m_hWnd);
- }
- else if(nIDEvent==5)
- {
- KillTimer(5);
- LoadImage();
- }
- else if(nIDEvent==6)
- {
- if(m_bProcessing)return;
- m_bProcessing=1;
- g_nSendCode=0;
- TerminateThread();
- m_dlg.TerminateThread();
- g_bInSkin=0;
- CDialog::OnOK ();
- m_bProcessing=0;
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- /* TerminateThread();
- for(int n=0; n<m_nPosArray.GetSize (); n++)
- {
- m_pImage=m_pImageArray.ElementAt (n);
- m_pImagesmall=m_pImageSmallArray.ElementAt (n);
- delete m_pImage;
- delete m_pImagesmall;
- }
- m_pImageArray.RemoveAll ();
- m_pImageSmallArray.RemoveAll ();
- m_nPosArray.RemoveAll ();*/
- try
- {
- m_pImage=m_pImagesmall=NULL;
- HANDLE handle=Lock("shgenimagethread");
- m_pImage=m_pImagesmall=NULL;
- for(int n=0; n<m_nPosArray.GetSize (); n++)
- {
- if(m_pos==m_nPosArray.ElementAt (n))
- {
- delete m_pImageArray.ElementAt (n);
- delete m_pImageSmallArray.ElementAt (n);
- m_pImageArray.RemoveAt(n);
- m_pImageSmallArray.RemoveAt(n);
- m_nPosArray.RemoveAt(n);
- }
- }
- if(m_pos>=this->m_pPathArray->GetSize ())
- m_pos=0;
- Unlock(handle);
-
- LoadImage();
- }
- catch(...)
- {
- }
- }
- void ShowPic22::InitRc()
- {
- try
- {
- if(m_pImage==NULL)return;
- CRect rc;
- GetClientRect(rc);
- m_rc=rc;
- int width,height;
- width=m_pImage->GetWidth();
- height=m_pImage->GetHeight();
- //////////
- float fscale=(float)width/(float)height;
- float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
- int rcwid=m_rc.Width ();
- int rchei=m_rc.Height ();
- int dt=0;
- if(rcscale<fscale)
- {
- dt=(rchei-rcwid/fscale)/2;
- m_rc.top+=dt;
- m_rc.bottom-=dt;
- }
- else
- {
- dt=(rcwid-rchei*fscale)/2;
- m_rc.left +=dt;
- m_rc.right-=dt;
- }
- m_rcbak=m_rc;
- }
- catch(...)
- {
- }
- }
- void ShowPic22::Rotate1()
- {
- if(m_bauto)return;if(m_bProcessing)return;
- try
- {
- if(m_pImage)
- {
- m_pImage->RotateFlip( Rotate270FlipNone );
- if(m_pImagesmall) m_pImagesmall->RotateFlip( Rotate270FlipNone );
- if(m_pImagetemp) m_pImagetemp->RotateFlip( Rotate270FlipNone );
- InitRc();
- Invalidate();
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::Rotate2()
- {
- if(m_bauto)return;if(m_bProcessing)return;
- try
- {
- if(m_pImage)
- {
- m_pImage->RotateFlip( Rotate90FlipNone );
- if(m_pImagesmall) m_pImagesmall->RotateFlip( Rotate90FlipNone );
- if(m_pImagetemp) m_pImagetemp->RotateFlip( Rotate90FlipNone );
- InitRc();
- Invalidate();
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::Pre()
- {
- if(m_bauto)return;if(m_bProcessing)return;
- m_bInit=1;
- try
- {
- {
- m_pos--;
- if(m_pos<0)
- m_pos=this->m_pPathArray->GetSize ()-1;
- LoadImage();
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::Next()
- {
- if(m_bauto)return;if(m_bProcessing)return;
- m_bInit=1;
- try
- {
- {
- m_pos++;
- if(m_pos>=this->m_pPathArray->GetSize ())
- m_pos=0;
- LoadImage();
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::SetEffect(int effect)
- {
- ::SetForegroundWindow (m_hWnd);
- m_dlg.m_effect=effect;
- // if(effect==0)
- // SetTimer(1, 3000, NULL);
- }
- void ShowPic22::TerminateThread()
- {
- try
- {
- if ( m_bRunning )
- {
- 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);
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::InitRc(Image *img, CRect &rc)
- {
- try
- {
- if(img==NULL)return;
- CRect rc2;
- GetClientRect(rc2);
- rc=rc2;
- int width,height;
- width=img->GetWidth();
- height=img->GetHeight();
- //////////
- float fscale=(float)width/(float)height;
- float rcscale=((float)rc.Width ())/((float)rc.Height ());
- int rcwid=rc.Width ();
- int rchei=rc.Height ();
- int dt=0;
- if(rcscale<fscale)
- {
- dt=(rchei-rcwid/fscale)/2;
- rc.top+=dt;
- rc.bottom-=dt;
- }
- else
- {
- dt=(rcwid-rchei*fscale)/2;
- rc.left +=dt;
- rc.right-=dt;
- }
- }
- catch(...)
- {
- }
- }
|