📄 previewex.cpp
字号:
// PreviewEx.cpp : implementation file
//
// Replaces MFC print preview toolbar with a prettier one
//
// Copyright (c) 1999 Robin J. Leatherbarrow, Erithacus Software Limited
//
// Use and distribute freely, except: don't remove my name from the
// source or documentation; mark your changes; don't alter
// or remove this notice.
// No warranty of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, etc.,
// and I'll try to keep a version up to date. I can be reached at:
// robin@erithacus.com
//
// Usage:
// 1. #include "PreviewEx.h" into your view class
// 2. Add PreviewEx.cpp and MappedBitmapButton.cpp to your project
// 3. Copy the above resources to your .RC file
// 4. Add the following message handler to your view class
// When called you get the improved print preview
//
//void CYourView::OnFileImprovedprintpreview()
//{
// // need to use CPreviewViewEx class
// CPrintPreviewState* pState = new CPrintPreviewState;
//
// if (!DoPrintPreview(IDD_PREVIEW, this, RUNTIME_CLASS(CPreviewViewEx), pState))
// {
// TRACE0("Error: OnFileImprovedprintpreview failed.\n");
// AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
// delete pState; // preview failed to initialize, delete State now
// }
//}
//
#include "stdafx.h"
#include "afxpriv.h"
#include "afxres.h"
#include "PreviewEx.h"
#include "resource.h"
IMPLEMENT_DYNCREATE(CPreviewViewEx, CPreviewView)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPreviewViewEx
CPreviewViewEx::CPreviewViewEx()
{
}
CPreviewViewEx::~CPreviewViewEx()
{
}
void CPreviewViewEx::OnDisplayPageNumber(UINT nPage, UINT nPagesDisplayed)
{
CPreviewView::OnDisplayPageNumber( nPage, nPagesDisplayed );
}
void CPreviewViewEx::OnPreviewPrint()
{
CPreviewView::OnPreviewPrint();
}
BEGIN_MESSAGE_MAP(CPreviewViewEx, CPreviewView)
//{{AFX_MSG_MAP(CPreviewViewEx)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_COMMAND(AFX_ID_PREVIEW_PRINT, OnPreviewPrint)
ON_UPDATE_COMMAND_UI(AFX_ID_PREVIEW_NUMPAGE, OnUpdateNumPageChange)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPreviewViewEx drawing
/////////////////////////////////////////////////////////////////////////////
// CPreviewViewEx diagnostics
#ifdef _DEBUG
void CPreviewViewEx::AssertValid() const
{
CPreviewView::AssertValid();
}
void CPreviewViewEx::Dump(CDumpContext& dc) const
{
CPreviewView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPreviewViewEx message handlers
void CPreviewViewEx::OnUpdateNumPageChange(CCmdUI* pCmdUI)
{
UINT nPages = m_nZoomState == ZOOM_OUT ? m_nPages : m_nZoomOutPages;
if (m_bOne) {
if (nPages == 1) {
// need to swap to show 2 pages
//m_onetwo.LoadBitmap( IDB_PREV_TWO );
m_bOne = false;
m_wndOnetwo.SetIcon((m_bOne)?m_hIconOne:m_hIconTwo, 16, 16);
m_wndOnetwo.Invalidate();
}
}
else {
if (nPages != 1) {
// need to swap to show 1 page
//m_onetwo.LoadBitmap( IDB_PREV_ONE );
m_bOne = true;
m_wndOnetwo.SetIcon((m_bOne)?m_hIconOne:m_hIconTwo, 16, 16);
m_wndOnetwo.Invalidate();
}
}
// enable it only if valid to display another page and not zoomed
//pCmdUI->Enable(m_nZoomState == ZOOM_OUT && m_nMaxPages != 1 &&
// (m_pPreviewInfo->GetMaxPage() > 1 || m_nPages > 1));
CPreviewView::OnUpdateNumPageChange(pCmdUI);
}
int CPreviewViewEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CPreviewView::OnCreate(lpCreateStruct) == -1)
return -1;
m_pToolBar->EnableToolTips( TRUE );
m_bOne = true;
m_wndPrint.SubclassDlgItem(AFX_ID_PREVIEW_PRINT,m_pToolBar);
m_wndNext.SubclassDlgItem(AFX_ID_PREVIEW_NEXT,m_pToolBar);
m_wndPrevious.SubclassDlgItem(AFX_ID_PREVIEW_PREV,m_pToolBar);
m_wndOnetwo.SubclassDlgItem(AFX_ID_PREVIEW_NUMPAGE,m_pToolBar);
m_wndZoomIn.SubclassDlgItem(AFX_ID_PREVIEW_ZOOMIN,m_pToolBar);
m_wndZoomOut.SubclassDlgItem(AFX_ID_PREVIEW_ZOOMOUT,m_pToolBar);
m_wndClose.SubclassDlgItem(AFX_ID_PREVIEW_CLOSE,m_pToolBar);
m_wndPrint.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, CFlatButton::FBS_HAS_ICON);
m_wndPrevious.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, CFlatButton::FBS_HAS_ICON);
m_wndNext.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, CFlatButton::FBS_HAS_ICON);
m_wndOnetwo.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, CFlatButton::FBS_HAS_ICON);
m_wndZoomIn.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, CFlatButton::FBS_HAS_ICON);
m_wndZoomOut.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, CFlatButton::FBS_HAS_ICON);
m_wndClose.ModifyFlag(CFlatButton::FBS_FOCUS|CFlatButton::FBS_BORDER, NULL);
CImageList imgList;
HINSTANCE hIns = AfxGetResourceHandle();
AfxSetResourceHandle(AfxGetInstanceHandle());
imgList.Create(IDB_PRIVIEW, 16, 1, RGB(255, 0, 255));
m_wndPrint.SetIcon(imgList.ExtractIcon(0), 16, 16);
m_wndPrevious.SetIcon(imgList.ExtractIcon(1), 16, 16);
m_wndNext.SetIcon(imgList.ExtractIcon(2), 16, 16);
m_wndZoomIn.SetIcon(imgList.ExtractIcon(5), 16, 16);
m_wndZoomOut.SetIcon(imgList.ExtractIcon(6), 16, 16);
m_hIconOne = imgList.ExtractIcon(3);
m_hIconTwo = imgList.ExtractIcon(4);
m_wndOnetwo.SetIcon(m_hIconOne, 16, 16);
AfxSetResourceHandle(hIns);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -