简体   繁体   English

MFC:如何启用通过鼠标滚轮换页打印预览?

[英]MFC: how to enable page change via mouse wheeling for print preview?

In print preview dialog, I would like to enable page change via mouse wheeling.在打印预览对话框中,我想通过鼠标滚动启用页面更改。 As I am still a beginner for MFC programming, I don't have code to start with.由于我还是 MFC 编程的初学者,我没有代码可以开始。 The closest question I've found is this one (for C#) but no clear answer yet: https://www.codeproject.com/Questions/555242/5bc-23-5dplusprintpreviewdialogplusandplusmousewhe .我发现的最接近的问题是这个(对于 C#),但还没有明确的答案: https://www.codeproject.com/Questions/555242/5bc-23-5dplusprintpreviewdialogplusandplusmousewhe

If you are using MFC's CPreviewView class, then you can derive a custom class from that, in which you can override the OnMouseWheel member.如果您使用的是 MFC 的CPreviewView class,那么您可以从中派生一个自定义的 class,您可以在其中覆盖OnMouseWheel成员。 In your override, you would call the OnVScroll handler to shift up or down, as though you had clicked on the up/down arrows of the scrollbar:在您的覆盖中,您将调用OnVScroll处理程序向上或向下移动,就像您单击了滚动条的向上/向下箭头一样:

BOOL MyPreviewView::OnMouseWheel(UINT /*flags*/, short delta, CPoint /*point*/)
{
    OnVScroll(UINT((delta < 0) ? SB_LINEDOWN : SB_LINEUP), 0, nullptr);
    return TRUE;
}

Also, you need to add ON_WM_MOUSEWHEEL() to your derived class' message-map:此外,您需要将ON_WM_MOUSEWHEEL()添加到派生类的消息映射中:

BEGIN_MESSAGE_MAP(MyPreviewView, CPreviewView)
    //...
    ON_WM_MOUSEWHEEL()
    //...
END_MESSAGE_MAP()

Feel free to ask for further clarification and/or explanation.随时要求进一步澄清和/或解释。

It is an addition to the existing answer of Adrian Mole's Answer这是对Adrian Mole's Answer现有答案的补充

If you are not using custom class already, this is the complete implementation of the class:如果您还没有使用自定义 class,这是 class 的完整实现:

MyPreviewViewEx.h我的PreviewViewEx.h

// CMyPreviewViewEx view

class CMyPreviewViewEx : public CPreviewViewEx
{
    DECLARE_DYNCREATE(CMyPreviewViewEx)

protected:
    CMyPreviewViewEx()              {}           // protected constructor used by dynamic creation
    virtual ~CMyPreviewViewEx()     {}

    DECLARE_MESSAGE_MAP()
public:
    afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
    static void MyPrintPreview(CView* pView);
};

MyPreviewViewEx.cpp我的PreviewViewEx.cpp

// CMyPreviewViewEx
IMPLEMENT_DYNCREATE(CMyPreviewViewEx, CPreviewViewEx)

BEGIN_MESSAGE_MAP(CMyPreviewViewEx, CPreviewViewEx)
    ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()


// CMyPreviewViewEx message handlers

BOOL CMyPreviewViewEx::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
    OnVScroll(UINT((zDelta < 0) ? SB_LINEDOWN : SB_LINEUP), 0, nullptr);
    return TRUE;
}

// Override AFXPrintPreview
void CMyPreviewViewEx::MyPrintPreview(CView* pView)
{
    ASSERT_VALID(pView);

    CPrintPreviewState *pState= new CPrintPreviewState;

    if (!pView->DoPrintPreview(IDD_AFXBAR_RES_PRINT_PREVIEW, pView, RUNTIME_CLASS(CMyPreviewViewEx), pState))
    {
        TRACE0("Error: OnFilePrintPreview failed.\n");
        AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
        delete pState;      // preview failed to initialize, delete State now
    }
}

In the view class, change as applicable在视图 class 中,根据需要进行更改

// AFXPrintPreview(pView);
CMyPreviewViewEx::MyPrintPreview(pView);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在基于对话框的 MFC 应用程序上启用滚动? - How to enable scrolling on Dialog Based MFC app? WPF - 如何在预览中模拟鼠标悬停 - WPF - How to simulate mouse over in preview 如何在MFC中的应用程序按钮中启用主要项目和按钮 - How to Enable Main Items & Button in Application Button in MFC 如何使用类型引用可为空或如何在 .NET Core 中预览时启用它 - How to use type reference nullable or how to enable it on preview in .NET Core 如何在没有母版页的情况下在 asp.net 中打印页面并更改页面的配色方案? - How can i print a page in asp.net without master page and to change color schemes of the page? 如何在VS 2013中更改预览中的程序名称? - How to change name of program on the preview in VS 2013? 如何更改MFC SDI无文档应用程序的标题/标题 - How to change the title/caption of MFC SDI documentless application 如何从asp.net中的表单预览页面上的数据 - how to preview data on page from a form in asp.net 如何在Visual Studio 2015中为TypeScript文件启用预览面板? - How do I enable the preview panel for TypeScript files in Visual Studio 2015? 我应该如何更改 MFC 应用程序工具栏中按钮的 IMAGE(与类型无关)? - How should I change the IMAGE(doesn't matter the type) of the button in the toolbar in MFC applications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM