12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640 |
- // ShowPic22.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowPic22.h"
- #include "MyLock.h"
- #include "ShowEffect.h"
- #include "CutPhoto.h"
- #define PCL_R(p) (((RGBQUAD*)(p))->rgbRed)
- #define PCL_G(p) (((RGBQUAD*)(p))->rgbGreen)
- #define PCL_B(p) (((RGBQUAD*)(p))->rgbBlue)
- #define PCL_A(p) (((RGBQUAD*)(p))->rgbReserved)
- /////////////////////////////////////////////////////////////////////////////
- // PicBar m_PicBar;
- 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 IDC_STATIC2
- //}}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;
- m_bShowName=0;
- m_bShowEffect=0;
- m_pPathArray=NULL;
- m_pPathArrayBigsize=NULL;
- m_bChooseBig=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()
- ON_WM_CTLCOLOR()
- ON_MESSAGE(WM_USER+200, ShowInfo2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // ShowPic22 message handlers
- 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);
- if( pThis->m_bChooseBig && pThis->m_pos==pos)
- {
- path=pThis->m_pPathArrayBigsize->ElementAt (pos);
- pThis->m_bChooseBig=0;
- }
- Image *img=NULL;
- Image *imgsmall=NULL;
- ::LoadImageFromBuf (&img, path);
- if(img==NULL)
- {
- Bitmap *pNULLBmp=new Bitmap(100, 100, PixelFormat24bppRGB );
- Graphics graph2(pNULLBmp);
- graph2.Clear(Color(255,0,0,0));
- Bitmap *pNULLBmp2=new Bitmap(100, 100, PixelFormat24bppRGB );
- Graphics graph3(pNULLBmp2);
- graph3.Clear(Color(255,0,0,0));
- pThis->m_pImageArray.Add (pNULLBmp);
- pThis->m_pImageSmallArray.Add (pNULLBmp2);
- pThis->m_nPosArray.Add (pos);
- Unlock(handle);
- continue;
- }
- if(img->GetWidth()==0)
- {
- Bitmap *pNULLBmp=new Bitmap(100, 100, PixelFormat24bppRGB );
- Graphics graph2(pNULLBmp);
- graph2.Clear(Color(255,0,0,0));
- Bitmap *pNULLBmp2=new Bitmap(100, 100, PixelFormat24bppRGB );
- Graphics graph3(pNULLBmp2);
- graph3.Clear(Color(255,0,0,0));
- pThis->m_pImageArray.Add (pNULLBmp);
- pThis->m_pImageSmallArray.Add (pNULLBmp2);
- pThis->m_nPosArray.Add (pos);
- Unlock(handle);
- continue;
- }
- 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() );
- int orientation=GetOrientation(img);
- if(orientation==8)
- {
- imgsmall->RotateFlip( Rotate270FlipNone );
- img->RotateFlip( Rotate270FlipNone );
- }
- else if(orientation==6)
- {
- imgsmall->RotateFlip( Rotate90FlipNone );
- img->RotateFlip( Rotate90FlipNone );
- }
- 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 (200);
- }
- pThis->m_bRunning=false;
- pThis->m_bTerminate=false;
- _endthreadex( 0 );
- return 0;
- }
- catch(...)
- {
- }
- }
- BOOL ShowPic22::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_bShowName=1;
- try
- {
- g_nSendCode=0;
- RunPicThread();
- if(m_bShowName)
- {
-
- GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
- }
-
- // TODO: Add extra initialization here
- m_rcscreen=CRect(0, 0, g_screenwid, g_screenhei);
- ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW);
- // m_pbmp=new Bitmap(g_screenwid, g_screenhei, PixelFormat24bppRGB );
- m_pbmp=new Bitmap(g_screenwid, g_screenhei, PixelFormat32bppARGB );
- // 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);
- if(m_PicBar.GetSafeHwnd ()==NULL)
- {
- if(m_pParent==NULL)
- m_PicBar.m_bShowCut=0;
- else if(m_pParent->m_mode2) m_PicBar.m_bShowCut=0;
- m_PicBar.PreLoad();
- m_PicBar.SetLiaPath ("4.lia");
- m_PicBar.Create (IDD_DLGmydlg, this);
- }
- if(m_PreviewDlg.GetSafeHwnd ()==NULL)
- {
- m_PreviewDlg.Create (IDD_DIALOG30, this);
- CRect rc;
- rc.top =50;
- rc.bottom =g_screenhei-50;
- rc.right =g_screenwid-10;
- rc.left =rc.right -100;
- ///////////////////////////
- rc.left=g_screenwid-20;
- rc.right=rc.left+100;
- ///////////////////////////
- m_PreviewDlg.MoveWindow (rc);
- m_PreviewDlg.m_pPathArray=m_pPathArray;
- m_PreviewDlg.InitCtrl();
-
- }
- // m_PicBar.SetParent (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_screenhei-10;
- m_picbarrc.top =m_picbarrc.bottom-hei;
- m_PicBar.MoveWindow (m_picbarrc);
- m_startpt2.x=m_startpt2.y=0;
- }
-
-
- m_sta1.SetFocus();
- // ::SetForegroundWindow (m_hWnd);
- LoadImage(); m_PreviewDlg.ShowWindow (SW_SHOW);
- }
- catch(...)
- {
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- inline void RGBtoHLS (int R, int G, int B, double* H, double* L, double* S)
- {
- const int n_cmax = max(B, max(R, G)),
- n_cmin = min(B, min(R, G));
- *L = (n_cmax + n_cmin) / 2.0 / 255.0 ;
- if (n_cmax == n_cmin)
- {
- *S = *H = 0.0 ;
- return ;
- }
- const double r = (double)R / 255.0,
- g = (double)G / 255.0,
- b = (double)B / 255.0,
- cmax = n_cmax / 255.0,
- cmin = n_cmin / 255.0,
- delta = cmax - cmin ;
- if (*L < 0.5)
- *S = delta / (cmax+cmin) ;
- else
- *S = delta / (2.0-cmax-cmin) ;
- if (R == n_cmax)
- *H = (g-b) / delta ;
- else if (G == n_cmax)
- *H = 2.0 + (b-r) / delta ;
- else
- *H = 4.0 + (r-g) / delta ;
- *H /= 6.0 ;
- if (*H < 0.0)
- *H += 1.0 ;
- }
- RGBQUAD __DoubleRGB_to_RGB (const double& r, const double& g, const double& b)
- {
- RGBQUAD rgb;
- rgb.rgbRed=max(0,min(255, (int)r*255));
- rgb.rgbGreen=max(0,min(255, (int)g*255));
- rgb.rgbBlue=max(0,min(255, (int)b*255));
-
- return rgb ;
- }
- inline double __HLS_Value (const double& m1, const double& m2, double h)
- {
- if (h > 6.0)
- h -= 6.0 ;
- else if (h < 0.0)
- h += 6.0 ;
- if (h < 1.0)
- return m1 + (m2 - m1) * h ;
- else if (h < 3.0)
- return m2 ;
- else if (h < 4.0)
- return m1 + (m2 - m1) * (4.0 - h) ;
- return m1 ;
- }
- inline RGBQUAD HLStoRGB (const double& H, const double& L, const double& S)
- {
- double m1, m2 ;
- if (L < 0.5)
- m2 = L * (1.0 + S) ;
- else
- m2 = L + S - L*S ;
- m1 = 2.0*L - m2 ;
- return __DoubleRGB_to_RGB (__HLS_Value (m1, m2, H*6.0 + 2.0),
- __HLS_Value (m1, m2, H*6.0),
- __HLS_Value (m1, m2, H*6.0 - 2.0)) ;
- }
- void Autocontrast(Bitmap *pBmpImage)
- {return;
- try
- {
- if(pBmpImage==NULL)return;
-
- BitmapData bitmapData;
- UINT* pixels;
- Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
- pBmpImage->LockBits(
- rc,
- ImageLockModeWrite,
- PixelFormat32bppARGB ,
- &bitmapData);
- // Write to the temporary buffer provided by LockBits. RGB
- pixels = (UINT*)bitmapData.Scan0;
- DWORD wids=bitmapData.Stride/4;
- Color color;
- BYTE R,G,B;
- double H, L, S ;
- int iPercent =128 * 110 / 100 ; // 转换成x/128
- int iPercentSat = 128 * 120 / 100 ; // 转换成x/128
- RGBQUAD rgb2;RGBTRIPLE rgb;
- for(INT row = 0; row < rc.Height; ++row)
- {
- for(INT col = 0; col < rc.Width; ++col)
- {
- color.SetValue(pixels[row * wids + col]);
- R=min(255, max(0, 128 + (color.GetR()-128) * iPercent / 128 ));
- G=min(255, max(0, 128 + (color.GetG()-128) * iPercent / 128 ));
- B=min(255, max(0, 128 + (color.GetB()-128) * iPercent / 128 ));
- rgb.rgbtRed =color.GetR();
- rgb.rgbtGreen =color.GetG();
- rgb.rgbtBlue =color.GetB();
- FCColor::RGBtoHLS (&rgb, &H, &L, &S) ;
- S = S * iPercentSat / 128 ;
- rgb2 = FCColor::HLStoRGB (H, L, S) ;
- pixels[row * wids + col]=Color::MakeARGB(255, rgb2.rgbRed, rgb2.rgbGreen, rgb2.rgbBlue );
-
- // pixels[row * wids + col]=Color::MakeARGB(255, R, G, B );
- }
- }
- pBmpImage->UnlockBits(&bitmapData);
- }
- catch(...)
- {
- }
- }
- void Autosaturation(Bitmap *pBmpImage)
- {
- #ifdef HIGH_VERSION
- try
- {
- if(pBmpImage==NULL)return;
- if(g_pMainWnd->m_pToneColorDlg2->m_saturation==100)return;
- BitmapData bitmapData;
- UINT* pixels;
- Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
- pBmpImage->LockBits(
- rc,
- ImageLockModeWrite,
- PixelFormat32bppARGB ,
- &bitmapData);
- // Write to the temporary buffer provided by LockBits. RGB
- pixels = (UINT*)bitmapData.Scan0;
- DWORD wids=bitmapData.Stride/4;
- Color color;
-
- double H, L, S ;
- RGBTRIPLE rgb;
- RGBQUAD rgb2;
- int iPercentSat = 128 * g_pMainWnd->m_pToneColorDlg2->m_saturation / 100 ; // 转换成x/128
- for(INT row = 0; row < rc.Height; ++row)
- {
- for(INT col = 0; col < rc.Width; ++col)
- {
- color.SetValue(pixels[row * wids + col]);
- rgb.rgbtRed =color.GetR();
- rgb.rgbtGreen =color.GetG();
- rgb.rgbtBlue =color.GetB();
- FCColor::RGBtoHLS (&rgb, &H, &L, &S) ;
- S = S * iPercentSat / 128 ;
- rgb2 = FCColor::HLStoRGB (H, L, S) ;
- pixels[row * wids + col]=Color::MakeARGB(color.GetA(), rgb2.rgbRed, rgb2.rgbGreen, rgb2.rgbBlue );
- }
- }
- pBmpImage->UnlockBits(&bitmapData);
- }
- catch(...)
- {
- }
- #endif
- }
- 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.SetInterpolationMode(InterpolationModeHighQualityBicubic);
- graph.DrawImage(img, destinationRect, 0,0,width,height,UnitPixel);
-
-
- Graphics graph2(dc.GetSafeHdc ());
- Autocontrast(m_pbmp);
- graph2.DrawImage(m_pbmp,0,0);
-
- }
- else
- {
- // dc.FillSolidRect (rc, 0);
- }
- }
- catch(...)
- {
- }
- // Do not call CDialog::OnPaint() for painting messages
- }
- void ShowPic22::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(...)
- {
- }
- CDialog::OnDestroy();
- // m_pic.UnloadPicture ();
- // TODO: Add your message handler code here
- }
- void ShowPic22::LoadImage()
- {
- try
- {
- ::SetForegroundWindow (m_hWnd);
- KillTimer(5);
- if(m_pPathArray->GetSize ()==0)return;//2011-03-09
- 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);
- if( m_bChooseBig )
- {
- path=m_pPathArrayBigsize->ElementAt (m_pos);
- }
- ::LoadImageFromBuf (&m_pImage, path);
- if(m_pImage==NULL)
- {
- Bitmap *pNULLBmp=new Bitmap(100, 100, PixelFormat24bppRGB );
- Graphics graph2(pNULLBmp);
- graph2.Clear(Color(255,0,0,0));
- m_pImage=pNULLBmp;
- }
- if(m_pImage->GetWidth()==0)
- {
- m_bChooseBig=0;
- Unlock(handle);
- return;
- }
- 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() );
- int orientation=GetOrientation(m_pImage);
- if(orientation==8)
- { m_pImage->RotateFlip( Rotate270FlipNone );
- m_pImagesmall->RotateFlip( Rotate270FlipNone );
- }
- else if(orientation==6)
- {
- m_pImage->RotateFlip( Rotate90FlipNone );
- m_pImagesmall->RotateFlip( Rotate90FlipNone );
- }
- 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);
- }
- }
-
- m_bChooseBig=0;
- Unlock(handle);
- }
- else if(m_pImage==NULL)
- {
- SetTimer(5, 1, NULL);
- return ;
- }
-
- if(m_pImagetemp) delete m_pImagetemp;m_pImagetemp=NULL;
- InitRc();
- 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_screenwid, g_screenhei , 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
- {
- ShowInfo();
- Invalidate();
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- SetCapture();
- m_startpt=m_startpt3=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;
- }m_startpt3=point;
- }
- 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_startpt3=point;
- }
- 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();
- if(point.x-m_startpt3.x>30)
- Next();
- else if(m_startpt3.x-point.x>30)
- Pre();
- 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_bShowEffect)return 1;
- 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 )
- { if(m_bShowEffect)return 1;
- switch (pMsg->wParam)
- {
- case VK_RETURN:
- return 1;
- case VK_ESCAPE:
- KillTimer(6);
- SetTimer(6, 100, NULL);
- return 1;
- case VK_F2:
- return 1;
- if(m_pParent==NULL)return 1;
- if(m_pParent->m_mode2)return 1;
- if(m_bShowEffect)return 1;
- if(m_bauto)
- {
- m_bauto=0;
- KillTimer(1);
- m_dlg.TerminateThread ();
- m_dlg.ShowWindow (SW_HIDE);
- }
- if(m_pImage)
- {
- m_bShowEffect=1;
- CutPhoto2();
- // ShowEffectDlg dlg;
- // dlg.DoModal();
- m_bShowEffect=0;
- }
- return 1;
- case VK_F3:
- AutoPic();
- break;
- case VK_UP:
- Rotate1();
- return 1;
- case VK_PRIOR:
- case VK_LEFT:
- Pre();
- return 1;
- case VK_DOWN:
- Rotate2();
- return 1;
- case VK_RIGHT:
- case VK_NEXT:
- Next();
- return 1;
- case VK_SHIFT:
- {
- if(m_bauto)return 1;if(m_bProcessing)return 1;
- if(m_pPathArrayBigsize && m_bChooseBig==0 )
- {
- HANDLE handle=Lock("shgenimagethread");
- 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);
- break;
- }
- }
- Unlock(handle);
- m_bChooseBig=1;
- LoadImage();
- }
- }
- 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);
- }
- // HANDLE handle=Lock("shgenimagethread");
- if(m_pParent->OnDel())
- {
- TerminateThread();
- ::SetForegroundWindow (m_hWnd);
- m_pImage=m_pImagesmall=NULL;
- for(int n=m_nPosArray.GetSize ()-1; n>=0; 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_pPathArrayBigsize)
- {
- m_pPathArrayBigsize->RemoveAll();
- m_pPathArray->RemoveAll();
- CStringArray *pArray=m_pParent->GetCurArray();
- m_pPathArrayBigsize->Copy(*pArray);
- for(int i=0; i<m_pPathArrayBigsize->GetSize(); i++)
- {
- CString str=m_pPathArrayBigsize->ElementAt(i);
- CString spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="m";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if(::PathFileExists(spath))
- m_pPathArray->Add(spath);
- else
- m_pPathArray->Add(str);
- }
- }
- if(m_pos>=this->m_pPathArray->GetSize ())
- m_pos=0;
- // Unlock(handle);
- RunPicThread();
- 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_PreviewDlg.ShowMin();
- if(m_pos>=this->m_pPathArray->GetSize ())
- 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
- {if(m_bShowEffect)return;
- ::SetForegroundWindow (m_hWnd);
- if(nIDEvent==1)
- {
- KillTimer(1);
- m_pos++;
- if(m_pos>=this->m_pPathArray->GetSize ())
- {
- KillTimer(1);
-
- m_dlg.TerminateThread ();
- m_dlg.ShowWindow (SW_HIDE);
- m_PicBar.ChangeBtn();
- AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
- m_bauto=0; m_bProcessing=0;
- m_pos-=2;Next();
- 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_screenhei-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();
-
- CDialog::OnOK ();
- m_bProcessing=0;
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- if(m_pParent)
- {
- if(m_bProcessing)return;
- m_bProcessing=1;
- {
- TerminateThread();
- ::SetForegroundWindow (m_hWnd);
- m_pImage=m_pImagesmall=NULL;
- for(int n=m_nPosArray.GetSize ()-1; n>=0; 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_pPathArrayBigsize)
- {
- m_pPathArrayBigsize->RemoveAll();
- m_pPathArray->RemoveAll();
- CStringArray *pArray=m_pParent->GetCurArray();
- m_pPathArrayBigsize->Copy(*pArray);
- for(int i=0; i<m_pPathArrayBigsize->GetSize(); i++)
- {
- CString str=m_pPathArrayBigsize->ElementAt(i);
- CString spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="m";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if(::PathFileExists(spath))
- m_pPathArray->Add(spath);
- else
- m_pPathArray->Add(str);
- }
- }
- if(m_pos>=this->m_pPathArray->GetSize ())
- m_pos=0;
- if(this->m_pPathArray->GetSize ()==0)
- {
-
- m_bProcessing=0;
- KillTimer(6);
- SetTimer(6, 100, NULL);
- }
- else
- {
- RunPicThread();
- LoadImage();
- }
- }
- m_bProcessing=0;
- }
- }
- void ShowPic22::InitRc()
- {
- try
- {
- if(m_pImage==NULL)return;
- CRect rc;
- GetClientRect(rc);
- m_rc=rc;
- int width,height;
- if(m_pImagesmall)
- {
- width=m_pImagesmall->GetWidth();
- height=m_pImagesmall->GetHeight();
- }
- else
- {
- 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;
- m_bChooseBig=0;
- LoadImage();m_PreviewDlg.ShowPic(m_pos);
- }
- }
- 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; AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
- }
- m_bChooseBig=0;
- LoadImage();
- m_PreviewDlg.ShowPic(m_pos);
- }
- }
- catch(...)
- {
- }
- }
- void ShowPic22::SetEffect(int effect)
- {
- ::SetForegroundWindow (m_hWnd);
- m_dlg.m_effect=effect;
-
- }
- 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(...)
- {
- }
- }
- HBRUSH ShowPic22::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
-
- // TODO: Change any attributes of the DC here
- if(nCtlColor==CTLCOLOR_STATIC)
- {
- pDC->SetBkMode (TRANSPARENT);
- pDC->SetTextColor (RGB(255,255,255));
- return (HBRUSH)::GetStockObject(NULL_BRUSH);
- }
- // TODO: Return a different brush if the default is not desired
- return hbr;
- }
- void ShowPic22::RunPicThread()
- {
- if(m_pPathArray->GetSize ()==0)return;//2011-03-09
- TerminateThread();
- m_hThread = (HANDLE)_beginthreadex(NULL,0, GenThumbImgThread,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
- m_bRunning=true;
- }
- void ShowPic22::OnMouseWheel2(BOOL bZoomOut)
- {
- if(m_pImage==NULL)return ;
- if(m_bauto)return ;if(m_bProcessing)return ;
- m_bScroll=1;
- if(bZoomOut)
- {
- // 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 ;
- 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();
- }
- KillTimer(2);
- SetTimer(2, 100, NULL);
- }
- long ShowPic22::ShowInfo2(WPARAM inWParam, LPARAM inLParam)
- {
- if(inWParam==1)
- {
- if(m_bauto)AutoPic();
- return 1;
- }
- ShowInfo();
- return 1;
- }
- void ShowPic22::ShowInfo()
- {
- Invalidate();
- if(m_bShowName)
- {
- CString str= m_pPathArray->ElementAt (m_pos);
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=str.Left (str.GetLength ()-4);
- str.TrimLeft("m");
- str="编号:"+str+" ";
- if(m_pParent)
- str+=m_pParent->GetZSInfo(m_pos);
- SetDlgItemText(IDC_STATIC2, str);
- }
- }
- void ShowPic22::CutPhoto2()
- {
- if(m_pParent==NULL)return;
- CutPhoto dlg;
- CString path=m_pPathArray->ElementAt (m_pos);
- if(m_pPathArrayBigsize)path=m_pPathArrayBigsize->ElementAt (m_pos);
- path=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
- path=path.Left (path.Find ("."));
- dlg.m_path=path;
- dlg.m_photowidth=m_pImage->GetWidth();
- dlg.m_photoheight=m_pImage->GetHeight();
- dlg.m_pImg=m_pImagesmall;
- dlg.m_id=m_pParent->m_strOrderNumber;
- dlg.DoModal();
- }
- void ShowPic22::CutPhoto3()
- {
- if(m_pParent==NULL)return;
- if(m_pParent->m_mode2)return;
-
- if(m_bShowEffect)return;
- if(m_bauto)
- {
- m_bauto=0;
- KillTimer(1);
- m_dlg.TerminateThread ();
- m_dlg.ShowWindow (SW_HIDE);
- }
- if(m_pImage)
- {
- m_bShowEffect=1;
- CutPhoto2();
- // ShowEffectDlg dlg;
- // dlg.DoModal();
- m_bShowEffect=0;
- }
- }
-
|