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. 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.
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. 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:
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:
BEGIN_MESSAGE_MAP(MyPreviewView, CPreviewView)
//...
ON_WM_MOUSEWHEEL()
//...
END_MESSAGE_MAP()
Feel free to ask for further clarification and/or explanation.