123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698 |
- // ShowPic22.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowPic22.h"
- #include "MyLock.h"
- #include "ShowEffect.h"
- #include "CutPhoto.h"
- #include "ChoosePhotoBase.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)
- /////////////////////////////////////////////////////////////////////////////
- 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) : CDialog(ShowPic22::IDD, pParent)
- {
- m_pCurShowImg = NULL;
- m_pCurShowSmallImg = 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_bShowImgInfo = 0;
- m_bShowEffect = 0;
- m_AryOfImgPath = NULL;
- m_pPathArrayBigsize = NULL;
- m_bChooseBig = 0;
- }
- void ShowPic22::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_STATIC1, m_sta1);
- }
- BEGIN_MESSAGE_MAP(ShowPic22, CDialog)
- 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)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- BOOL ShowPic22::OnEraseBkgnd(CDC* pDC)
- {
- return 1;
- }
- unsigned __stdcall GenThumbImgThread(LPVOID lpParam)
- {
- try
- {
- ShowPic22 *pThis = (ShowPic22*)lpParam;
- int posbak = pThis->m_nCurImgPos; // m_pos 选片时选中的相片列编号,即要查看的相片;
-
- // 以下4个变量用途何为?
- int pos(0);
- BOOL bNext = 1; // 图片位置与posbak一致时保持不变;
- BOOL bFirst = 1; // 记录第一次运行的什么情况?
- int count(0); // 用于记录什么的数量?
- while (1)
- {
- // 对话框销毁,线程退出;
- if (pThis->m_bTerminate)
- break;
- // 播放幻灯或未初始化时,线程进入睡眠,让出CPU周期;
- 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_nCurImgPos)
- {
- if (pThis->m_nCurImgPos > posbak)
- bNext = 1;
- else
- bNext = 0;
- posbak = pThis->m_nCurImgPos;
- 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_AryOfImgPath->GetSize())
- pos -= pThis->m_AryOfImgPath->GetSize();
- while (pos < 0)
- pos += pThis->m_AryOfImgPath->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;
- }// for;
- if (bFind){
- Unlock(handle);
- continue;
- }// if;
- // 获取相片路径;
- CString path = pThis->m_AryOfImgPath->ElementAt(pos);
- if (pThis->m_bChooseBig && pThis->m_nCurImgPos == pos)
- {
- path = pThis->m_pPathArrayBigsize->ElementAt(pos);
- pThis->m_bChooseBig = 0;
- }
- // img为"m"图或大图,加载指定名称的图片;
- 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_AryOfImgPtr.Add(pNULLBmp);
- pThis->m_AryOfSmallImgPtr.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_AryOfImgPtr.Add(pNULLBmp);
- pThis->m_AryOfSmallImgPtr.Add(pNULLBmp2);
- pThis->m_nPosArray.Add(pos);
- Unlock(handle);
- continue;
- }
- CRect rc;
- pThis->InitRc(img, rc); //
- //GetThumbnailImage进行图片缩放操作
- 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_AryOfImgPtr.Add(img);
- pThis->m_AryOfSmallImgPtr.Add(imgsmall);
- pThis->m_nPosArray.Add(pos);
- //10张图片缓存
- if (pThis->m_AryOfImgPtr.GetSize() > 10)
- {// 如果加载的图片超过10过,删除最早加载的第一张;
- if (pThis->m_pCurShowImg != pThis->m_AryOfImgPtr.ElementAt(0))
- {// 如果第一张不是当前显示的图片,从内存中删除掉;
- delete pThis->m_AryOfImgPtr.ElementAt(0);
- delete pThis->m_AryOfSmallImgPtr.ElementAt(0);
- pThis->m_AryOfImgPtr.RemoveAt(0);
- pThis->m_AryOfSmallImgPtr.RemoveAt(0);
- pThis->m_nPosArray.RemoveAt(0);
- }
- }
- Unlock(handle);
- }
- ::Sleep(200);
- }
- pThis->m_bRunning = false;
- pThis->m_bTerminate = false;
- _endthreadex(0);
- }
- catch (...)
- {
- }
- return 0;
- }
- BOOL ShowPic22::OnInitDialog() // 初始化;
- {
- CDialog::OnInitDialog();
- m_bShowImgInfo = 1;
- try
- {
- g_nSendCode = 0;
- RunPicThread();
- if (m_bShowImgInfo)
- GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
- 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_rcImgShow;
- m_dlg.MoveWindow(m_rcScreen);
- if (m_PicBar.GetSafeHwnd() == NULL)
- {
- if (m_pParent == NULL)
- m_PicBar.m_bShowCut = 0;
- else if (m_pParent->m_Runingmode)
- 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_AryOfImgPath;
- 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();
- LoadImage();
- m_PreviewDlg.ShowWindow(SW_SHOW);
- }
- catch (...)
- {
- }
- return TRUE;
- }
- 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);
- try
- {
- CRect rc;
- GetClientRect(rc);
- if (m_pCurShowImg && m_bauto == 0)
- {// m_bauto 自动播放; m_pCurShowImg当前需要显示的相片指针;
- 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_pCurShowSmallImg;
- m_bScroll = 0;
- int width, height;
- width = img->GetWidth();
- height = img->GetHeight();
- ///////////////
- Rect destinationRect(m_rcImgShow.left, m_rcImgShow.top, m_rcImgShow.Width(), m_rcImgShow.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 (...)
- {
- }
- }
- void ShowPic22::OnDestroy()
- {
- try
- {
- g_nSendCode = 0;
- for (int n = 0; n < m_nPosArray.GetSize(); n++)
- {
- m_pCurShowImg = m_AryOfImgPtr.ElementAt(n);
- m_pCurShowSmallImg = m_AryOfSmallImgPtr.ElementAt(n);
- delete m_pCurShowImg;
- delete m_pCurShowSmallImg;
- }
- DELETEP(m_pImagetemp)
- DELETEP(m_pbmp)
- KillTimer(1);
- }
- catch (...)
- {
- }
- CDialog::OnDestroy();
- }
- void ShowPic22::LoadImage()
- {
- try
- {
- ::SetForegroundWindow(m_hWnd);
- KillTimer(5);
- if (m_AryOfImgPath->GetSize() == 0)
- return;
- m_pCurShowImg = m_pCurShowSmallImg = NULL;
- for (int n = 0; n < m_nPosArray.GetSize(); n++){
- if (m_nCurImgPos == m_nPosArray.ElementAt(n)){
- m_pCurShowImg = m_AryOfImgPtr.ElementAt(n);
- m_pCurShowSmallImg = m_AryOfSmallImgPtr.ElementAt(n);
- break;
- }//if;
- }//for;
- if (m_pCurShowImg == NULL && (m_bauto || m_bInit == 0))
- {
- HANDLE handle = Lock("shgenimagethread");
- CString path = m_AryOfImgPath->ElementAt(m_nCurImgPos);
- if (m_bChooseBig && m_pPathArrayBigsize && m_pPathArrayBigsize->GetSize() > m_nCurImgPos)
- {// 如果使用的是原图模式,加载原图;
- path = m_pPathArrayBigsize->ElementAt(m_nCurImgPos);
- }
- // 从文件中加载图片;
- LoadImageFromBuf(&m_pCurShowImg, path);
- if (m_pCurShowImg == NULL)
- {//如果加载相片失败,使用空白图片代替;
- Bitmap *pNULLBmp = new Bitmap(100, 100, PixelFormat24bppRGB);
- Graphics graph2(pNULLBmp);
- graph2.Clear(Color(255, 0, 0, 0));
- m_pCurShowImg = pNULLBmp;
- }
- if (m_pCurShowImg->GetWidth() == 0)
- {
- m_bChooseBig = 0;
- Unlock(handle);
- return;
- }
- InitRc();
- m_pCurShowSmallImg = m_pCurShowImg->GetThumbnailImage(m_rcImgShow.Width(), m_rcImgShow.Height(), NULL, NULL);
- Graphics graphic(m_pCurShowSmallImg);//防止GetThumbnailImage影响质量
- graphic.DrawImage(m_pCurShowImg, 0, 0, m_pCurShowSmallImg->GetWidth(), m_pCurShowSmallImg->GetHeight());
- int orientation = GetOrientation(m_pCurShowImg);
- if (orientation == 8)
- {
- m_pCurShowImg->RotateFlip(Rotate270FlipNone);
- m_pCurShowSmallImg->RotateFlip(Rotate270FlipNone);
- }
- else if (orientation == 6)
- {
- m_pCurShowImg->RotateFlip(Rotate90FlipNone);
- m_pCurShowSmallImg->RotateFlip(Rotate90FlipNone);
- }
- // 存入到数组中;
- m_AryOfImgPtr.Add(m_pCurShowImg);
- m_AryOfSmallImgPtr.Add(m_pCurShowSmallImg);
- m_nPosArray.Add(m_nCurImgPos);
- if (m_AryOfImgPtr.GetSize() > 10)
- {// 如果加载的图片超过10张,删除第一张;
- if (m_pCurShowImg != m_AryOfImgPtr.ElementAt(0))
- {
- delete m_AryOfImgPtr.ElementAt(0);
- delete m_AryOfSmallImgPtr.ElementAt(0);
- m_AryOfImgPtr.RemoveAt(0);
- m_AryOfSmallImgPtr.RemoveAt(0);
- m_nPosArray.RemoveAt(0);
- }
- }
- m_bChooseBig = 0;
- Unlock(handle);
- }
- else if (m_pCurShowImg == 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_pCurShowSmallImg);
- if (m_dlg.m_effect == 1 || m_dlg.m_effect == 2)
- {
- m_dlg.ShowWindow(SW_HIDE);
- }
- // ShowAlpha里有SetTimer(1);
- m_dlg.ShowAlpha();
- }
- else
- {
- ShowInfo();
- Invalidate();
- }
- }
- catch (...)
- {
- }
- }
- void ShowPic22::OnLButtonDown(UINT nFlags, CPoint point)
- {
- SetCapture(); // 设置窗口捕获鼠标;
- m_startpt = m_startpt3 = point;
- CDialog::OnLButtonDown(nFlags, point);
- }
- void ShowPic22::OnMouseMove(UINT nFlags, CPoint point)
- {
- if (GetCapture() != this)
- return;
- if (m_rcImgShow.Width() > m_rcScreen.Width())
- {
- if (m_rcImgShow.left <m_rcScreen.left && point.x>m_startpt.x)
- {
- int dt = min(point.x - m_startpt.x, m_rcScreen.left - m_rcImgShow.left);
- m_rcImgShow.left += dt;
- m_rcImgShow.right += dt;
- }
- else if (m_rcImgShow.right > m_rcScreen.right && point.x < m_startpt.x)
- {
- int dt = min(m_startpt.x - point.x, m_rcImgShow.right - m_rcScreen.right);
- m_rcImgShow.left -= dt;
- m_rcImgShow.right -= dt;
- }m_startpt3 = point;
- }
- if (m_rcImgShow.Height() > m_rcScreen.Height())
- {
- if (m_rcImgShow.top <m_rcScreen.top && point.y>m_startpt.y)
- {
- int dt = min(point.y - m_startpt.y, m_rcScreen.top - m_rcImgShow.top);
- m_rcImgShow.top += dt;
- m_rcImgShow.bottom += dt;
- }
- else if (m_rcImgShow.bottom > m_rcScreen.bottom && point.y < m_startpt.y)
- {
- int dt = min(m_startpt.y - point.y, m_rcImgShow.bottom - m_rcScreen.bottom);
- m_rcImgShow.top -= dt;
- m_rcImgShow.bottom -= dt;
- }m_startpt3 = point;
- }
- m_startpt = point;
- Invalidate();
- CDialog::OnMouseMove(nFlags, point);
- }
- void ShowPic22::OnLButtonUp(UINT nFlags, CPoint point)
- {
- 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)
- {
- if (m_pCurShowImg == 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_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
- int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
- m_rcImgShow.left -= dtx;
- m_rcImgShow.right += dtx;
- m_rcImgShow.top -= dty;
- m_rcImgShow.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_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
- int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
- m_rcImgShow.left -= dtx;
- m_rcImgShow.right += dtx;
- m_rcImgShow.top -= dty;
- m_rcImgShow.bottom += dty;
- if (m_rcImgShowBack.Height() == m_rcScreen.Height())
- {
- if (m_rcImgShow.top < m_rcScreen.top && m_rcImgShow.bottom < m_rcScreen.bottom)
- {
- dtx = m_rcScreen.bottom - m_rcImgShow.bottom;
- m_rcImgShow.top += dtx;
- m_rcImgShow.bottom += dtx;
- }
- else if (m_rcImgShow.top >m_rcScreen.top && m_rcImgShow.bottom > m_rcScreen.bottom)
- {
- dtx = m_rcImgShow.top - m_rcScreen.top;
- m_rcImgShow.top -= dtx;
- m_rcImgShow.bottom -= dtx;
- }
- dtx = m_rcImgShow.Width();
- m_rcImgShow.left = (m_rcScreen.Width() - dtx) / 2;
- m_rcImgShow.right = m_rcImgShow.left + dtx;
- }
- if (m_rcImgShowBack.Width() == m_rcScreen.Width())
- {
- if (m_rcImgShow.left < m_rcScreen.left && m_rcImgShow.right < m_rcScreen.right)
- {
- dtx = m_rcScreen.right - m_rcImgShow.right;
- m_rcImgShow.left += dtx;
- m_rcImgShow.right += dtx;
- }
- else if (m_rcImgShow.left >m_rcScreen.left && m_rcImgShow.right > m_rcScreen.right)
- {
- dtx = m_rcImgShow.left - m_rcScreen.left;
- m_rcImgShow.left -= dtx;
- m_rcImgShow.right -= dtx;
- }
- dtx = m_rcImgShow.Height();
- m_rcImgShow.top = (m_rcScreen.Height() - dtx) / 2;
- m_rcImgShow.bottom = m_rcImgShow.top + dtx;
- }
- Invalidate();
- /* int dtx=(m_fscale-1)*m_rcImgShowBack.Width ()/2.0;
- int dty=(m_fscale-1)*m_rcImgShowBack.Height ()/2.0;
- m_rcImgShow=m_rcImgShowBack;
- m_rcImgShow.left -=dtx;
- m_rcImgShow.right +=dtx;
- m_rcImgShow.top -=dty;
- m_rcImgShow.bottom +=dty;
- Invalidate();*/
- }
- KillTimer(2);
- SetTimer(2, 100, NULL);
- return CDialog::OnMouseWheel(nFlags, zDelta, pt);
- }
- BOOL ShowPic22::PreTranslateMessage(MSG* pMsg) // 键盘和按钮响应事件;
- {
- if (pMsg->message == WM_MOUSEMOVE)
- {
- if (m_bShowEffect)return 1;
- if (m_PicBar.m_bInit && m_pCurShowImg)
- {
- 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_Runingmode)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_pCurShowImg)
- {
- 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_nCurImgPos == m_nPosArray.ElementAt(n))
- {
- delete m_AryOfImgPtr.ElementAt(n);
- delete m_AryOfSmallImgPtr.ElementAt(n);
- m_AryOfImgPtr.RemoveAt(n);
- m_AryOfSmallImgPtr.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_nCurImgPos, LVIS_SELECTED, LVIS_SELECTED);
- }
- // HANDLE handle=Lock("shgenimagethread");
- if (m_pParent->OnDel())
- {
- TerminateThread();
- ::SetForegroundWindow(m_hWnd);
- m_pCurShowImg = m_pCurShowSmallImg = NULL;
- for (int n = m_nPosArray.GetSize() - 1; n >= 0; n--)
- {
- //if(m_pos==m_nPosArray.ElementAt (n))
- {
- delete m_AryOfImgPtr.ElementAt(n);
- delete m_AryOfSmallImgPtr.ElementAt(n);
- m_AryOfImgPtr.RemoveAt(n);
- m_AryOfSmallImgPtr.RemoveAt(n);
- m_nPosArray.RemoveAt(n);
- }
- }
- if (m_pPathArrayBigsize)
- {
- m_pPathArrayBigsize->RemoveAll();
- m_AryOfImgPath->RemoveAll();
- CStringArray *pArray = m_pParent->GetCurArray(m_pParent->m_SelectCategory);
- 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_AryOfImgPath->Add(spath);
- else
- m_AryOfImgPath->Add(str);
- }
- }
- if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
- m_nCurImgPos = 0;
- // Unlock(handle);
- RunPicThread();
- LoadImage();
- m_pParent->m_List1.SetItemState(m_nCurImgPos, LVIS_SELECTED, LVIS_SELECTED);
- }
- m_bProcessing = 0;
- return 1;
- }
- }
- ::SetForegroundWindow(m_hWnd);
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- //---------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:OnRButtonDown
- // 描述:鼠标右键
- // 参数:
- // nFlags:表示各种虚拟按键是否下降
- // point: 指定x和光标的y坐标
- // 返回:无
- //---------------------------------------------------------------
- void ShowPic22::OnRButtonDown(UINT nFlags, CPoint point) // 鼠标右键;
- {
- 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_nCurImgPos, LVIS_SELECTED, LVIS_SELECTED);
- m_pParent->OnRclickList1();
- }
- CDialog::OnRButtonDown(nFlags, point);
- }
- //---------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:AutoPic
- // 描述:播放幻灯片按钮
- // 参数:无
- // 返回:无
- //---------------------------------------------------------------
- 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_nCurImgPos >= this->m_AryOfImgPath->GetSize())
- m_nCurImgPos = 0;
- LoadImage();
- }
- else
- {
- KillTimer(1);
- m_dlg.TerminateThread();
- m_dlg.ShowWindow(SW_HIDE);
- }
- ::SetForegroundWindow(m_hWnd);
- }
- catch (...)
- {
- }
- }
- void ShowPic22::OnTimer(UINT nIDEvent)
- {
- try
- {
- if (m_bShowEffect)
- return;
- ::SetForegroundWindow(m_hWnd);
- if (nIDEvent == 1)
- {// 自动播放相片;
- KillTimer(1);
- m_nCurImgPos++;
- if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
- {
- KillTimer(1);
- m_dlg.TerminateThread();
- m_dlg.ShowWindow(SW_HIDE);
- m_PicBar.ChangeBtn();
- AfxMessageBox(_T("您的照片已浏览完毕!"), MB_ICONINFORMATION);
- m_bauto = FALSE;
- m_bProcessing = FALSE;
- m_nCurImgPos -= 2;
- Next();
- return;
- }
- LoadImage();
- }
- else if (nIDEvent == 2)
- {// 鼠标滚动轴事件引起,放大或缩小图片;
- KillTimer(2);
- if (m_pImagetemp)
- {
- if (m_rcImgShow.Width() > m_pImagetemp->GetWidth())
- {
- DELETEP(m_pImagetemp)
- m_pImagetemp = m_pCurShowImg->GetThumbnailImage(min(m_pCurShowImg->GetWidth(), m_rcImgShow.Width()), min(m_pCurShowImg->GetHeight(), m_rcImgShow.Height()), NULL, NULL);
- Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
- graphic.DrawImage(m_pCurShowImg, 0, 0, m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight());
- }
- }
- else
- {
- m_pImagetemp = m_pCurShowImg->GetThumbnailImage(min(m_pCurShowImg->GetWidth(), m_rcImgShow.Width()), min(m_pCurShowImg->GetHeight(), m_rcImgShow.Height()), NULL, NULL);
- Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
- graphic.DrawImage(m_pCurShowImg, 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()
- {
- if (m_pParent)
- {
- if (m_bProcessing)return;
- m_bProcessing = 1;
- {
- TerminateThread();
- ::SetForegroundWindow(m_hWnd);
- m_pCurShowImg = m_pCurShowSmallImg = NULL;
- for (int n = m_nPosArray.GetSize() - 1; n >= 0; n--)
- {
- delete m_AryOfImgPtr.ElementAt(n);
- delete m_AryOfSmallImgPtr.ElementAt(n);
- m_AryOfImgPtr.RemoveAt(n);
- m_AryOfSmallImgPtr.RemoveAt(n);
- m_nPosArray.RemoveAt(n);
- }
- if (m_pPathArrayBigsize)
- {
- m_pPathArrayBigsize->RemoveAll();
- m_AryOfImgPath->RemoveAll();
- CStringArray *pArray = m_pParent->GetCurArray(m_pParent->m_SelectCategory);
- 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_AryOfImgPath->Add(spath);
- else
- m_AryOfImgPath->Add(str);
- }
- }
- if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
- m_nCurImgPos = 0;
- if (this->m_AryOfImgPath->GetSize() == 0)
- {
- m_bProcessing = 0;
- KillTimer(6);
- SetTimer(6, 100, NULL);
- }
- else
- {
- RunPicThread();
- LoadImage();
- }
- }
- m_bProcessing = 0;
- }
- }
- void ShowPic22::InitRc()
- {
- try
- {
- if (m_pCurShowImg == NULL)
- return;
- CRect rc;
- GetClientRect(rc);
- m_rcImgShow = rc;
- int width, height;
- if (m_pCurShowSmallImg)
- {
- width = m_pCurShowSmallImg->GetWidth();
- height = m_pCurShowSmallImg->GetHeight();
- }
- else
- {
- width = m_pCurShowImg->GetWidth();
- height = m_pCurShowImg->GetHeight();
- }
- //////////
- float fscale = (float)width / (float)height;
- float rcscale = ((float)m_rcImgShow.Width()) / ((float)m_rcImgShow.Height());
- int rcwid = m_rcImgShow.Width();
- int rchei = m_rcImgShow.Height();
- int dt = 0;
- if (rcscale < fscale)
- {
- dt = (rchei - rcwid / fscale) / 2;
- m_rcImgShow.top += dt;
- m_rcImgShow.bottom -= dt;
- }
- else
- {
- dt = (rcwid - rchei*fscale) / 2;
- m_rcImgShow.left += dt;
- m_rcImgShow.right -= dt;
- }
- m_rcImgShowBack = m_rcImgShow;
- }
- catch (...)
- {
- }
- }
- //---------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:Rotate1
- // 描述:旋转相片270度;
- // 参数:无
- // 返回:无
- //---------------------------------------------------------------
- void ShowPic22::Rotate1() // 逆时针旋转相片按钮;
- {
- if (m_bauto)return;
- if (m_bProcessing)return;
- try
- {
- if (m_pCurShowImg)
- {
- m_pCurShowImg->RotateFlip(Rotate270FlipNone);
- if (m_pCurShowSmallImg)
- m_pCurShowSmallImg->RotateFlip(Rotate270FlipNone);
- if (m_pImagetemp)
- m_pImagetemp->RotateFlip(Rotate270FlipNone);
- InitRc();
- Invalidate();
- }
- }
- catch (...)
- {
- }
- }
- //---------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:Rotate2
- // 描述:旋转相片90度;
- // 参数:无
- // 返回:无
- //---------------------------------------------------------------
- void ShowPic22::Rotate2() // 顺时针旋转相片按钮;
- {
- if (m_bauto)return;
- if (m_bProcessing)return;
- try
- {
- if (m_pCurShowImg)
- {
- m_pCurShowImg->RotateFlip(Rotate90FlipNone);
- if (m_pCurShowSmallImg)
- m_pCurShowSmallImg->RotateFlip(Rotate90FlipNone);
- if (m_pImagetemp)
- m_pImagetemp->RotateFlip(Rotate90FlipNone);
- InitRc();
- Invalidate();
- }
- }
- catch (...)
- {
- }
- }
- //---------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:Pre
- // 描述:上一张按钮
- // 参数:无
- // 返回:无
- //---------------------------------------------------------------
- void ShowPic22::Pre() // 上一张按钮;
- {
- if (m_bauto)return;
- if (m_bProcessing)return;
- m_bInit = 1;
- try
- {
- m_nCurImgPos--;
- if (m_nCurImgPos < 0)
- m_nCurImgPos = this->m_AryOfImgPath->GetSize() - 1;
- m_bChooseBig = 0;
- LoadImage();
- m_PreviewDlg.ShowPic(m_nCurImgPos);
- }
- catch (...)
- {
- }
- }
- //---------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:Next
- // 描述:下一张按钮
- // 参数:无
- // 返回:无
- //---------------------------------------------------------------
- void ShowPic22::Next() // 下一张按钮;
- {
- if (m_bauto)return;
- if (m_bProcessing)return;
- m_bInit = 1;
- try
- {
- m_nCurImgPos++;
- if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
- {
- m_nCurImgPos = 0;
- AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
- }
- m_bChooseBig = 0;
- LoadImage();
- m_PreviewDlg.ShowPic(m_nCurImgPos);
- }
- catch (...)
- {
- }
- }
- //------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:SetEffect
- // 描述:设置显示相片效果;
- // 参数:effect:效果类型;
- // 返回:无
- //------------------------------------------------------
- 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);
- if (nCtlColor == CTLCOLOR_STATIC)
- {
- pDC->SetBkMode(TRANSPARENT);
- pDC->SetTextColor(RGB(255, 255, 255));
- return (HBRUSH)::GetStockObject(NULL_BRUSH);
- }
- return hbr;
- }
- void ShowPic22::RunPicThread()
- {
- // 1.是否有播放相片路径;
- if (m_AryOfImgPath->GetSize() == 0)
- return;//2011-03-09
- TerminateThread();
- m_hThread = (HANDLE)_beginthreadex(NULL, 0, GenThumbImgThread, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
- m_bRunning = true;
- }
- //-------------------------------------------------------------------
- // Remark by Jeff
- // 函数:OnMouseWheel2
- // 描述:鼠标滚轮缩放图片
- // 参数:bZoomOut : TRUE 表示放大;FALSE表示缩小;
- // 返回:无
- //-------------------------------------------------------------------
- void ShowPic22::OnMouseWheel2(BOOL bZoomOut) // 鼠标滚轮缩放图片;
- {
- if (m_pCurShowImg == 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_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
- int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
- m_rcImgShow.left -= dtx;
- m_rcImgShow.right += dtx;
- m_rcImgShow.top -= dty;
- m_rcImgShow.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_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
- int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
- m_rcImgShow.left -= dtx;
- m_rcImgShow.right += dtx;
- m_rcImgShow.top -= dty;
- m_rcImgShow.bottom += dty;
- if (m_rcImgShowBack.Height() == m_rcScreen.Height())
- {
- if (m_rcImgShow.top < m_rcScreen.top && m_rcImgShow.bottom < m_rcScreen.bottom)
- {
- dtx = m_rcScreen.bottom - m_rcImgShow.bottom;
- m_rcImgShow.top += dtx;
- m_rcImgShow.bottom += dtx;
- }
- else if (m_rcImgShow.top >m_rcScreen.top && m_rcImgShow.bottom > m_rcScreen.bottom)
- {
- dtx = m_rcImgShow.top - m_rcScreen.top;
- m_rcImgShow.top -= dtx;
- m_rcImgShow.bottom -= dtx;
- }
- dtx = m_rcImgShow.Width();
- m_rcImgShow.left = (m_rcScreen.Width() - dtx) / 2;
- m_rcImgShow.right = m_rcImgShow.left + dtx;
- }
- if (m_rcImgShowBack.Width() == m_rcScreen.Width())
- {
- if (m_rcImgShow.left < m_rcScreen.left && m_rcImgShow.right < m_rcScreen.right)
- {
- dtx = m_rcScreen.right - m_rcImgShow.right;
- m_rcImgShow.left += dtx;
- m_rcImgShow.right += dtx;
- }
- else if (m_rcImgShow.left >m_rcScreen.left && m_rcImgShow.right > m_rcScreen.right)
- {
- dtx = m_rcImgShow.left - m_rcScreen.left;
- m_rcImgShow.left -= dtx;
- m_rcImgShow.right -= dtx;
- }
- dtx = m_rcImgShow.Height();
- m_rcImgShow.top = (m_rcScreen.Height() - dtx) / 2;
- m_rcImgShow.bottom = m_rcImgShow.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_bShowImgInfo)
- {
- CString str = m_AryOfImgPath->ElementAt(m_nCurImgPos);
- str = str.Right(str.GetLength() - str.ReverseFind(_T('\\')) - 1);
- str = str.Left(str.GetLength() - 4);
- str.TrimLeft(_T("m"));
- str = _T("编号:") + str + _T(" ");
- if (m_pParent)
- str += m_pParent->GetZSInfo(m_nCurImgPos);
- SetDlgItemText(IDC_STATIC2, str);
- }
- }
- //----------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:CutPhoto2
- // 描述:剪裁按钮对应的剪裁功能;
- // 参数:无
- // 返回:无
- // ----------------------------------------------------------------
- void ShowPic22::CutPhoto2()
- {
- if (m_pParent == NULL)return;
- CutPhoto dlg;
- CString path = m_AryOfImgPath->ElementAt(m_nCurImgPos);
- if (m_pPathArrayBigsize)path = m_pPathArrayBigsize->ElementAt(m_nCurImgPos);
- path = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- path = path.Left(path.Find("."));
- // path其实不是路径,只是文件名;如005
- dlg.m_strImgName = path;
- dlg.m_photowidth = m_pCurShowImg->GetWidth();
- dlg.m_photoheight = m_pCurShowImg->GetHeight();
- dlg.m_pImg = m_pCurShowSmallImg;
- dlg.m_strOrderNumber = m_pParent->m_strOrderNumber;
- dlg.DoModal();
- }
- //----------------------------------------------------------------
- // Remark by Jeff 2014.11.05
- // 函数:CutPhoto3
- // 描述:剪裁按钮;
- // 参数:无
- // 返回:无
- // ----------------------------------------------------------------
- void ShowPic22::CutPhoto3()
- {
- if (m_pParent == NULL)return;
- if (m_pParent->m_Runingmode)return;
- if (m_bShowEffect)return;
- if (m_bauto)
- {
- m_bauto = 0;
- KillTimer(1);
- m_dlg.TerminateThread();
- m_dlg.ShowWindow(SW_HIDE);
- }
- if (m_pCurShowImg)
- {
- m_bShowEffect = 1;
- CutPhoto2();
- m_bShowEffect = 0;
- }
- }
|