⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picviewview.cpp

📁 Pocket PC上的图片浏览程序。开发工具:eVC。
💻 CPP
字号:
// PicViewView.cpp : implementation of the CPicViewView class
//

#include "stdafx.h"
#include "PicView.h"

#include "PicViewDoc.h"
#include "PicViewView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


//---------------------------------------------------------------------------
//
//	CPicViewView
//
//---------------------------------------------------------------------------


IMPLEMENT_DYNCREATE(CPicViewView, CScrollView)

BEGIN_MESSAGE_MAP(CPicViewView, CScrollView)
	//{{AFX_MSG_MAP(CPicViewView)
	ON_WM_CREATE()
	ON_WM_SETFOCUS()
	ON_WM_DESTROY()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_SIZE()
	ON_UPDATE_COMMAND_UI(ID_SHOW_TITLE, OnUpdateShowTitle)
	ON_COMMAND(ID_SHOW_TITLE, OnShowTitle)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//---------------------------------------------------------------------------
//
//	CPicViewView construction/destruction
//
//---------------------------------------------------------------------------


CPicViewView::CPicViewView()
:	m_bHorz	(TRUE),
	m_bVert	(TRUE)
{
}


CPicViewView::~CPicViewView()
{
}


BOOL CPicViewView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}


BOOL CPicViewView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}


// CPicViewView::ContextMenu
//
//		Displays the context menu
//
void CPicViewView::ContextMenu(CPoint point)
{
	CMenu	mnuCtxt;
	CMenu*	pMenu;
	CWnd*	pWnd;

	if(mnuCtxt.LoadMenu(IDR_MENU_CONTEXT))
	{
		pWnd = AfxGetMainWnd();

		pMenu = mnuCtxt.GetSubMenu(0);
		if(pMenu)
		{
			pMenu->TrackPopupMenu(TPM_LEFTALIGN,
				point.x, point.y, pWnd);
		}
	}
}


//---------------------------------------------------------------------------
//
//	CPicViewView drawing
//
//---------------------------------------------------------------------------


// CPicViewView::OnDraw
//
//		Draw the bitmap at the appropriate zoom
//
void CPicViewView::OnDraw(CDC* pDC)
{
	CPicViewDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	HBITMAP	hBmp;
	CDC		dcMem;

	hBmp = pDoc->GetBitmap();
	if(hBmp)
	{
		CPoint	pt;
		CRect	rcClient;

		GetClientRect(&rcClient);
		pt = GetScrollPosition();

		dcMem.CreateCompatibleDC(NULL);
		dcMem.SelectObject(hBmp);

		pDC->StretchBlt(rcClient.left, rcClient.top, 
						rcClient.right, rcClient.bottom, 
						&dcMem, 
						pDoc->ScaleScreen(pt.x), 
						pDoc->ScaleScreen(pt.y),
						pDoc->ScaleScreen(rcClient.right),
						pDoc->ScaleScreen(rcClient.bottom),
						SRCCOPY);
	}
}


// CPicViewView::ScrollTo
//
//		Scrolls the view to the new position.
//		This is MFC code without the scroll, in order to avoid
//		"jagged" scrolling.
//
void CPicViewView::ScrollTo(CPoint point)
{
    int xMax = GetScrollLimit(SB_HORZ);
    int yMax = GetScrollLimit(SB_VERT);

    if(point.x < 0)
        point.x = 0;
    else if(point.x > xMax)
        point.x = xMax;
    if(point.y < 0)
        point.y = 0;
    else if(point.y > yMax)
        point.y = yMax;

	if(m_bHorz)
		SetScrollPos(SB_HORZ, point.x);
	if(m_bVert)
		SetScrollPos(SB_VERT, point.y);
}


//---------------------------------------------------------------------------
//
//	CPicViewView updating
//
//---------------------------------------------------------------------------


// CPicViewView::OnInitialUpdate
//
//		Initializes the view
//
void CPicViewView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
}


// CPicViewView::OnUpdate
//
//		Updates the view
//
void CPicViewView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	CSize			sizeTotal;
	CPicViewDoc*	pDoc = GetDocument();

	ASSERT_VALID(pDoc);

	if(pDoc->GetBitmap())
	{
		sizeTotal.cx = pDoc->GetZoomWidth();
		sizeTotal.cy = pDoc->GetZoomHeight();

		SetScrollSizes(MM_TEXT, sizeTotal);

		InvalidateRect(NULL, FALSE);

		m_wndTitleBar.SetTitle(pDoc->GetTitle());
	}
}


//---------------------------------------------------------------------------
//
//	CPicViewView diagnostics
//
//---------------------------------------------------------------------------


#ifdef _DEBUG


void CPicViewView::AssertValid() const
{
	CScrollView::AssertValid();
}


void CPicViewView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}


CPicViewDoc* CPicViewView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPicViewDoc)));
	return (CPicViewDoc*)m_pDocument;
}


#endif //_DEBUG


//---------------------------------------------------------------------------
//
//	CPicViewView message handlers
//
//---------------------------------------------------------------------------


// CPicViewView::OnCreate
//
//		The view has been created
//
int CPicViewView::OnCreate(LPCREATESTRUCT lpCreateStruct )
{
	int iResult = CView::OnCreate(lpCreateStruct);

	if(iResult == 0)
	{
		ShowDoneButton(TRUE);

		m_wndTitleBar.Create(GetParent());
	}

	return iResult;
}


void CPicViewView::OnSetFocus(CWnd* pOldWnd)
{
	CView::OnSetFocus(pOldWnd);
	//::SHSipPreference(m_hWnd, SIP_UP);
}


void CPicViewView::OnDestroy()
{
	if(IsWindow(m_wndTitleBar))
		m_wndTitleBar.DestroyWindow();

	CView::OnDestroy();
}


// CPicViewView::OnLButtonDown
//
//		Handles the stylus tap
//
void CPicViewView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	SHRGINFO	shrgi = {0};

	m_ptOrig = point;	// Store the initial point.

	//
	// Handle tap-and-hold
	//
	shrgi.cbSize		= sizeof(SHRGINFO);
	shrgi.hwndClient	= m_hWnd;
	shrgi.ptDown.x		= point.x;
	shrgi.ptDown.y		= point.y;
	shrgi.dwFlags		= SHRG_RETURNCMD;

	if(GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi))
	{
		ContextMenu(point);
	}
	else
	{
		Default();
	}
}


// CPicViewView::OnMouseMove
//
//		The user is dragging the view.
//		Scroll it accordingly, simulating the "tap-and-scroll"
//
void CPicViewView::OnMouseMove(UINT nFlags, CPoint point) 
{
	CPoint	ptDelta,
			ptScroll,
			pt;

	ptDelta		= m_ptOrig - point;
	m_ptOrig	= point;

	pt = GetScrollPosition();
	pt += ptDelta;

	ScrollTo(pt);
	InvalidateRect(NULL, FALSE);
	UpdateWindow();

	CScrollView::OnMouseMove(nFlags, point);
}


// CPicViewView::OnSize
//
//		The window was resized
//
void CPicViewView::OnSize(UINT nType, int cx, int cy) 
{
	CRect			rc;
	CPicViewDoc*	pDoc = GetDocument();

	ASSERT_VALID(pDoc);

	CScrollView::OnSize(nType, cx, cy);

	GetClientRect(&rc);

	m_bHorz = pDoc->GetZoomWidth()  > rc.Width();
	m_bVert = pDoc->GetZoomHeight() > rc.Height();
}


void CPicViewView::OnUpdateShowTitle(CCmdUI* pCmdUI) 
{
	pCmdUI->SetCheck(IsWindow(m_wndTitleBar));
}


void CPicViewView::OnShowTitle() 
{
	CFrameWnd*	pFrame = (CFrameWnd*)GetParent();

	if(IsWindow(m_wndTitleBar))
		m_wndTitleBar.DestroyWindow();
	else
		m_wndTitleBar.Create(pFrame);

	pFrame->RecalcLayout();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -