123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowPicStatic2.h"
- #include "PreviewDlg.h"
- #ifdef _DEBUG
- //#define new DEBUG_NEW //wangwenbin modify 2014-04-27
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- Bitmap *g_pImgStaBuf=NULL;
- ShowPicStatic2::ShowPicStatic2()
- {
- m_pImageBk=NULL;
- m_nFrameMode=-1;
- m_bStretch=1;
- if(g_pImgStaBuf==NULL)g_pImgStaBuf=new Bitmap(1500, 1500, PixelFormat24bppRGB);
- }
- ShowPicStatic2::~ShowPicStatic2()
- {
- ReleaseData();
- }
- BEGIN_MESSAGE_MAP(ShowPicStatic2, CStatic)
- ON_WM_PAINT()
- ON_WM_SETCURSOR()
- ON_WM_ERASEBKGND()
- END_MESSAGE_MAP()
- void ShowPicStatic2::OnPaint()
- {
- CPaintDC dc(this);
- try
- {
- CRect rc;
- GetClientRect(&rc);
- Graphics bufgraph(g_pImgStaBuf);
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(((PreviewDlg*)GetParent())->g_pBlackBrush, destinationRect);
- /* if(m_nFrameMode==1)//蓝框蓝边
- {
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(g_pBlueBrush2, destinationRect);
- rc.DeflateRect (1,1);
- Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(g_pBlueBrush, destinationRect2);
- }
- else if(m_nFrameMode==2)//蓝框黑边
- {
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(g_pBlackBrush, destinationRect);
- rc.DeflateRect (1,1);
- Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(g_pBlueBrush, destinationRect2);
- }
- else if(m_nFrameMode==3)//白框灰边
- {
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(g_pWhiteBrush2, destinationRect);
- rc.DeflateRect (2,2);
- Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(g_pWhiteBrush, destinationRect2);
- }*/
-
- if(m_nFrameMode==100)//蓝框红边,代表选中状态
- {
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(((PreviewDlg*)GetParent())->g_pRedBrush, destinationRect);
- rc.DeflateRect (1,1);
- Rect destinationRect2(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.FillRectangle(((PreviewDlg*)GetParent())->g_pBlackBrush, destinationRect2);
- }
- if(m_pImageBk)
- {
- int width=m_pImageBk->GetWidth();
- int height=m_pImageBk->GetHeight();
- if(m_bStretch)
- RectFitDes(width, height, rc);
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- bufgraph.DrawImage(m_pImageBk, destinationRect, 0,0,width,height,UnitPixel);
- }
- {
- Graphics dcgraph(dc.GetSafeHdc());
- GetClientRect(&rc);
- Rect destinationRect(rc.left , rc.top , rc.Width (), rc.Height ());
- dcgraph.DrawImage(g_pImgStaBuf, destinationRect, 0,0,rc.Width (), rc.Height (),UnitPixel);
- }
- }
- catch(...)
- {
- }
- }
- void ShowPicStatic2::ReleaseData()
- {
- try
- {
- if(m_pImageBk)
- {
- delete m_pImageBk;
- m_pImageBk=NULL;
- }
- }
- catch(...)
- {
- }
- }
- BOOL ShowPicStatic2::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- void ShowPicStatic2::SetPicPath(CString pathname)
- {
- try
- {
- ReleaseData();
- if(!::PathFileExists (pathname))
- {
- Invalidate();
- return;
- }
- pathname.MakeLower ();
- if(pathname.Right (3)=="jpg")
- {
- LoadImageFromBuf(&m_pImageBk, pathname);
- }
-
- Invalidate();
- }
- catch(...)
- {
- }
- }
- extern HCURSOR g_cursorhand;
- BOOL ShowPicStatic2::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- ::SetCursor(g_cursorhand);
- return TRUE;
- }
|