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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Subclassing a CListCtrl derived class in CDialog

Subclassing a CListCtrl derived class in CDialog

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
3 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    b_girl
    wrote on last edited by
    #1

    Hello. I have a dialog that contains a list control. I have created my own CListCtrl derived class (let's just call it CMyListCtrl). I need to handle the WM_VSCROLL message, but this message is never being received by either my dialog or my list control, but there is a handler for it in both classes. I know I need to subclass my CMyListCtrl list within my dialog but I'm not completely sure how to do this. I used the class wizard to create a member variable for my list, m_myList, and I set the type of it as being CMyListCtrl. I have tried a variety of ways to subclass this list control. I have tried both where the list is initialized within my dialog, and also where it is initialized within CMyListCtrl. I have tried using: m_myList.SubclassDlgItem(IDC_MY_LIST, m_parent); and m_myList.SubclassWindow(m_parent->m_hWnd); both of these will compile and won't give any assertion errors, but the WM_VSCROLL message still isn't being received by my list control (or maybe it's not even being sent in the first place?) Does anyone have any ideas as to how I can fix this? :confused: Thank you.

    A 1 Reply Last reply
    0
    • B b_girl

      Hello. I have a dialog that contains a list control. I have created my own CListCtrl derived class (let's just call it CMyListCtrl). I need to handle the WM_VSCROLL message, but this message is never being received by either my dialog or my list control, but there is a handler for it in both classes. I know I need to subclass my CMyListCtrl list within my dialog but I'm not completely sure how to do this. I used the class wizard to create a member variable for my list, m_myList, and I set the type of it as being CMyListCtrl. I have tried a variety of ways to subclass this list control. I have tried both where the list is initialized within my dialog, and also where it is initialized within CMyListCtrl. I have tried using: m_myList.SubclassDlgItem(IDC_MY_LIST, m_parent); and m_myList.SubclassWindow(m_parent->m_hWnd); both of these will compile and won't give any assertion errors, but the WM_VSCROLL message still isn't being received by my list control (or maybe it's not even being sent in the first place?) Does anyone have any ideas as to how I can fix this? :confused: Thank you.

      A Offline
      A Offline
      Atlantys
      wrote on last edited by
      #2

      My assumption is that you want to handle the scroll message in the dialog, not the listctrl itself. If you're trying to handle it in your listctrl, then it's a different setup (similar though, as most of the code will go into the listctrl class instead of the dialog). Anything application-specific goes in the dialog handler, and anything control-specific would go in the control handler. In your dlg's DoDatExchange, you should have something like this

      void CMyDlg::DoDataExchange(CDataExchange* pDX)
      {
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CMyDlg)
      DDX_Control(pDX, IDC_LIST, m_List);
      ....
      }

      That is where it is sub-classed. No need to use Subclass* etc. You should also have this:

      BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
      //{{AFX_MSG_MAP(CMyDlg)
      ON_WM_VSCROLL()
      ...
      END_MESSAGE_MAP()

      This tells the system that this dialog handles the WM_SCROLL message. (this is what you forgot?) Then, you have this function to actually handle the scroll:

      void CMyDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
      {
      if (*(CSliderCtrl*)pScrollBar == m_List) {
      //do stuff
      }
      CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
      }

      Hope that fixes things. You should also have the function declaration in the .h file, of course. :-D If you're new to MFC, then you might want to use the "Add Windows Message Handler..." wizard (rclick on the dialog in the ClassView). It does all this for you automatically. The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices. [Roger Wright on stupid people] We're like private member functions [John Theal on R&D] We're figuring out the parent thing as we go though. Kinda like setting up Linux for the first time ya' know... [Nitron]

      B 1 Reply Last reply
      0
      • A Atlantys

        My assumption is that you want to handle the scroll message in the dialog, not the listctrl itself. If you're trying to handle it in your listctrl, then it's a different setup (similar though, as most of the code will go into the listctrl class instead of the dialog). Anything application-specific goes in the dialog handler, and anything control-specific would go in the control handler. In your dlg's DoDatExchange, you should have something like this

        void CMyDlg::DoDataExchange(CDataExchange* pDX)
        {
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CMyDlg)
        DDX_Control(pDX, IDC_LIST, m_List);
        ....
        }

        That is where it is sub-classed. No need to use Subclass* etc. You should also have this:

        BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
        //{{AFX_MSG_MAP(CMyDlg)
        ON_WM_VSCROLL()
        ...
        END_MESSAGE_MAP()

        This tells the system that this dialog handles the WM_SCROLL message. (this is what you forgot?) Then, you have this function to actually handle the scroll:

        void CMyDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
        {
        if (*(CSliderCtrl*)pScrollBar == m_List) {
        //do stuff
        }
        CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
        }

        Hope that fixes things. You should also have the function declaration in the .h file, of course. :-D If you're new to MFC, then you might want to use the "Add Windows Message Handler..." wizard (rclick on the dialog in the ClassView). It does all this for you automatically. The kindest thing you can do for a stupid person, and for the gene pool, is to let him expire of his own dumb choices. [Roger Wright on stupid people] We're like private member functions [John Theal on R&D] We're figuring out the parent thing as we go though. Kinda like setting up Linux for the first time ya' know... [Nitron]

        B Offline
        B Offline
        b_girl
        wrote on last edited by
        #3

        I wanted to handle the message in my listctrl. I have attempted to use the class wizard to create a message map for the WM_VSCROLL message, but that message isn't available for me to use. Then I tried to handle that message in my dialog class, and just make a function call to my listctrl. But that didn't work either. It seems that when the user clicks on the vertical scroll bar within the listctrl (you know the one that is just automatically created when the list gets to be long enough), no WM_VSCROLL message is sent anywhere. If I knew why I wasn't ever getting a WM_VSCROLL message, I'm sure I'd be able to fix this, but I don't know why I'm not getting it.

        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