📄 viewimageview.cpp
字号:
// ViewImageView.cpp : implementation of the CViewImageView class
//
#include "stdafx.h"
#include "ViewImage.h"
#include "MainFrm.h"
#include "Dib.h"
#include "ViewImageDoc.h"
#include "ViewImageView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewImageView
IMPLEMENT_DYNCREATE(CViewImageView, CScrollView)
BEGIN_MESSAGE_MAP(CViewImageView, CScrollView)
//{{AFX_MSG_MAP(CViewImageView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
ON_MESSAGE(WM_REALIZEPAL, OnRealizePal)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewImageView construction/destruction
CViewImageView::CViewImageView()
{
// TODO: add construction code here
}
CViewImageView::~CViewImageView()
{
}
BOOL CViewImageView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CViewImageView drawing
void CViewImageView::OnDraw(CDC* pDC)
{
CViewImageDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (! pDoc->m_pDib->IsEmpty())
pDoc->m_pDib->Display(pDC, 0, 0);
}
void CViewImageView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CViewImageDoc* pDoc = GetDocument();
CSize sizeTotal(pDoc->m_pDib->GetWidth(), pDoc->m_pDib->GetHeight());
SetScrollSizes(MM_TEXT, sizeTotal);
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
ASSERT_KINDOF(CMainFrame, pAppFrame);
CRect rc;
pAppFrame->GetClientRect(&rc);
if (rc.Width() >= sizeTotal.cx && rc.Height() >= sizeTotal.cy &&
(sizeTotal.cx>0 || sizeTotal.cy>0))
ResizeParentToFit(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CViewImageView printing
BOOL CViewImageView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CViewImageView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CViewImageView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CViewImageView diagnostics
#ifdef _DEBUG
void CViewImageView::AssertValid() const
{
CScrollView::AssertValid();
}
void CViewImageView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CViewImageDoc* CViewImageView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewImageDoc)));
return (CViewImageDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewImageView message handlers
LRESULT CViewImageView::OnRealizePal(WPARAM wParam, LPARAM lParam)
{
ASSERT(wParam != NULL);
CViewImageDoc* pDoc = GetDocument();
if (pDoc->m_pDib->IsEmpty())
return 0L; // must be a new document
CPalette* pPal = pDoc->m_pDib->GetPalette();
if (pPal != NULL)
{
CWnd* pAppFrame = AfxGetApp()->m_pMainWnd;
CClientDC appDC(pAppFrame);
// All views but one should be a background palette.
// wParam contains a handle to the active view, so the SelectPalette
// bForceBackground flag is FALSE only if wParam == m_hWnd (this view)
CPalette* oldPalette = appDC.SelectPalette(pPal, ((HWND)wParam) != m_hWnd);
if (oldPalette != NULL)
{
UINT nColorsChanged = appDC.RealizePalette();
if (nColorsChanged > 0)
GetDocument()->UpdateAllViews(NULL);
appDC.SelectPalette(oldPalette, TRUE);
}
else
{
TRACE0("\tSelectPalette failed!\n");
}
}
return 0L;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -