Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Mouse Wheel scrolling support for MFC application.

Mouse Wheel scrolling support for MFC application.

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
8 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13871530
    wrote on last edited by
    #1

    Hi sir, i am working on MFC VC++ and i am very new to MFC application development. kindly please help me. our application tool have a vertical scrollbar. it's working with the dragging.but not working with the mouse wheel. kindly please let me know what kind of code support have to give for mouse wheel. i am using the below classes for creating the frame window. 1.class CMainFrame : public CFrameWndEx { ....... CMainFrame(); // main SDI frame window ........... } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!CreateToolBar()) { TRACE0("Failed to create Ribbon bar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) ) { TRACE0("Failed to create status bar\n"); return -1; // fail to create }

    m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_STATUS, csStatus, TRUE), csStatus);
    m_wndStatusBar.AddSeparator();
    m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_VER, csVersion, TRUE), csVersion);
    m_wndStatusBar.AddSeparator();
    m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_MEMORY, csMemory, TRUE), csMemory);
    m_wndStatusBar.AddSeparator();
    m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_SECURITY, csSecurity, TRUE), csSecurity);

    theApp.SetMainFrame(this);
    

    }

    kindly please let me know how to handle the mouse wheel messages and what are steps have to follow to enable this.

    J 1 Reply Last reply
    0
    • U User 13871530

      Hi sir, i am working on MFC VC++ and i am very new to MFC application development. kindly please help me. our application tool have a vertical scrollbar. it's working with the dragging.but not working with the mouse wheel. kindly please let me know what kind of code support have to give for mouse wheel. i am using the below classes for creating the frame window. 1.class CMainFrame : public CFrameWndEx { ....... CMainFrame(); // main SDI frame window ........... } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (!CreateToolBar()) { TRACE0("Failed to create Ribbon bar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) ) { TRACE0("Failed to create status bar\n"); return -1; // fail to create }

      m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_STATUS, csStatus, TRUE), csStatus);
      m_wndStatusBar.AddSeparator();
      m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_VER, csVersion, TRUE), csVersion);
      m_wndStatusBar.AddSeparator();
      m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_MEMORY, csMemory, TRUE), csMemory);
      m_wndStatusBar.AddSeparator();
      m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_SECURITY, csSecurity, TRUE), csSecurity);

      theApp.SetMainFrame(this);
      

      }

      kindly please let me know how to handle the mouse wheel messages and what are steps have to follow to enable this.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      The wheel scrolling has to be performed by the window which content should be scrolled by handling the WM_MOUSEWHEEL message | Microsoft Docs[^]. If that window is CWnd based, just override the OnMouseWheel() function. I can not give more information because you did not give any information about your window. With frame based MFC applications, that are usually the CView derived classes.

      U 1 Reply Last reply
      0
      • J Jochen Arndt

        The wheel scrolling has to be performed by the window which content should be scrolled by handling the WM_MOUSEWHEEL message | Microsoft Docs[^]. If that window is CWnd based, just override the OnMouseWheel() function. I can not give more information because you did not give any information about your window. With frame based MFC applications, that are usually the CView derived classes.

        U Offline
        U Offline
        User 13871530
        wrote on last edited by
        #3

        hi sir, i wrote the code below, the code is hitting whenever my mouse wheel scrolling. but the vertical scroll bar not moving.could you please give me your input please. Header file: class CMainFrame : public CFrameWndEx { protected: // create from serialization only CMainFrame(); DECLARE_DYNCREATE(CMainFrame) public: afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); }; source file : IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx) ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CMainFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point) { TRACE0("in CMainFrame:: OnMouseWheel function"); return CWnd :: OnMouseWheel(fFlags, zDelta, point); } here CMainFrame is derived from CFrameWndEx, CFrameWndEx id derived from the CFrameWnd, CFrameWnd class is derived from the CWnd. could you please help me if did any wrong.

        V 1 Reply Last reply
        0
        • U User 13871530

          hi sir, i wrote the code below, the code is hitting whenever my mouse wheel scrolling. but the vertical scroll bar not moving.could you please give me your input please. Header file: class CMainFrame : public CFrameWndEx { protected: // create from serialization only CMainFrame(); DECLARE_DYNCREATE(CMainFrame) public: afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); }; source file : IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx) ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CMainFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point) { TRACE0("in CMainFrame:: OnMouseWheel function"); return CWnd :: OnMouseWheel(fFlags, zDelta, point); } here CMainFrame is derived from CFrameWndEx, CFrameWndEx id derived from the CFrameWnd, CFrameWnd class is derived from the CWnd. could you please help me if did any wrong.

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Member 13903818 wrote:

          here CMainFrame is derived from CFrameWndEx, CFrameWndEx id derived from the CFrameWnd, CFrameWnd class is derived from the CWnd.

          But do your application also have one or more Views (CView/CScrollView/CForView/... derived classes)?

          U 1 Reply Last reply
          0
          • V Victor Nijegorodov

            Member 13903818 wrote:

            here CMainFrame is derived from CFrameWndEx, CFrameWndEx id derived from the CFrameWnd, CFrameWnd class is derived from the CWnd.

            But do your application also have one or more Views (CView/CScrollView/CForView/... derived classes)?

            U Offline
            U Offline
            User 13871530
            wrote on last edited by
            #5

            yes ..... (class CFormView : public CScrollView class CScrollView : public CView) in our application we are deriving the class from the CView like below. class CCommonEDM_AVitarView : public CView in above derived call i have handled the OnMouseWheel function. but it's not hitting the code while scrolling the mouse wheel. code : Header file: class CCommonEDM_AVitarView : public CView { protected: // create from serialization only CCommonEDM_AVitarView(); DECLARE_DYNCREATE(CCommonEDM_AVitarView) public: afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); }; source file : IMPLEMENT_DYNCREATE(CCommonEDM_AVitarView, CView) BEGIN_MESSAGE_MAP(CCommonEDM_AVitarView, CView) ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CCommonEDM_AVitarView::OnMouseWheel(UINT fFlags, short zDelta, CPoint point) { TRACE0("in CCommonEDM_AVitarView:: OnMouseWheel function"); return CView :: OnMouseWheel(fFlags, zDelta, point); } i am not understanding how internal child windows are working with mouse wheel scrolling. but main window is not working..

            J 1 Reply Last reply
            0
            • U User 13871530

              yes ..... (class CFormView : public CScrollView class CScrollView : public CView) in our application we are deriving the class from the CView like below. class CCommonEDM_AVitarView : public CView in above derived call i have handled the OnMouseWheel function. but it's not hitting the code while scrolling the mouse wheel. code : Header file: class CCommonEDM_AVitarView : public CView { protected: // create from serialization only CCommonEDM_AVitarView(); DECLARE_DYNCREATE(CCommonEDM_AVitarView) public: afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); }; source file : IMPLEMENT_DYNCREATE(CCommonEDM_AVitarView, CView) BEGIN_MESSAGE_MAP(CCommonEDM_AVitarView, CView) ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CCommonEDM_AVitarView::OnMouseWheel(UINT fFlags, short zDelta, CPoint point) { TRACE0("in CCommonEDM_AVitarView:: OnMouseWheel function"); return CView :: OnMouseWheel(fFlags, zDelta, point); } i am not understanding how internal child windows are working with mouse wheel scrolling. but main window is not working..

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              The MFC document - view concept is a little bit complicated regarding the parent and child windows and their interaction. But the message is sent to the control / window that has the focus. If your view contains controls then one of them probably has the focus and gets the message. It is still unclear to which window your scroll bars belong. If they are for the view: why is your view not CScrollView based? If your view contains a single control: handle the message there.

              U 1 Reply Last reply
              0
              • J Jochen Arndt

                The MFC document - view concept is a little bit complicated regarding the parent and child windows and their interaction. But the message is sent to the control / window that has the focus. If your view contains controls then one of them probably has the focus and gets the message. It is still unclear to which window your scroll bars belong. If they are for the view: why is your view not CScrollView based? If your view contains a single control: handle the message there.

                U Offline
                U Offline
                User 13871530
                wrote on last edited by
                #7

                Hello sir, i have written the below code for my each child frame. this class is derived from the CScrollView. my mouse wheel is working fine for each individual window class. but i am trying to implement same support from my main window class.but mouse wheel is not working. could you please give me your valuable inputs. My intention is instead of writing mouse wheel code for all the child class. if i implement mouse wheel function for my main frame. i would have been worth to all child classes. my individual window class code : mouse while is working with below code with below class.. Header file: class CAboutView : public CFormView { ----------- afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); } Source file : BEGIN_MESSAGE_MAP(CAboutView, CFormView) //ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CAboutView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { return DoMouseWheel(nFlags, zDelta, pt); } This is my main frame: with the below code my mouse wheel not working. Header file : class CMainFrame : public CFrameWndEx { ----------- afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); } Source file : BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx) ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CMainFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point) { CScrollView *wnd = NULL; BOOL mValue; mValue = wnd->DoMouseWheel(fFlags, zDelta, point); return mValue; }

                J 1 Reply Last reply
                0
                • U User 13871530

                  Hello sir, i have written the below code for my each child frame. this class is derived from the CScrollView. my mouse wheel is working fine for each individual window class. but i am trying to implement same support from my main window class.but mouse wheel is not working. could you please give me your valuable inputs. My intention is instead of writing mouse wheel code for all the child class. if i implement mouse wheel function for my main frame. i would have been worth to all child classes. my individual window class code : mouse while is working with below code with below class.. Header file: class CAboutView : public CFormView { ----------- afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); } Source file : BEGIN_MESSAGE_MAP(CAboutView, CFormView) //ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CAboutView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { return DoMouseWheel(nFlags, zDelta, pt); } This is my main frame: with the below code my mouse wheel not working. Header file : class CMainFrame : public CFrameWndEx { ----------- afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); } Source file : BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx) ON_WM_MOUSEWHEEL() END_MESSAGE_MAP() BOOL CMainFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point) { CScrollView *wnd = NULL; BOOL mValue; mValue = wnd->DoMouseWheel(fFlags, zDelta, point); return mValue; }

                  J Offline
                  J Offline
                  Jochen Arndt
                  wrote on last edited by
                  #8

                  It is still unclear for which window you want to handle the scrolling. If it is working in the views, all should be fine. Because the views show the content which might be scrolled. The frame windows are parents of the views providing the frame and the caption bar. They did not know about the content of the client area (the view) and can therefore not know how to scroll the content. I suggest to read about about the MFC document view architecture. Some links: Document-View Architecture[^] Multiple Document Types, Views, and Frame Windows[^] Frame Windows[^] Relationships Among MFC Objects[^]

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups