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. WM_LBUTTONDOWN not working with CListCtrl class!!

WM_LBUTTONDOWN not working with CListCtrl class!!

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiohelpquestion
22 Posts 3 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.
  • S SanjaySMK

    Hello, I have some code which has a dialog box and a list control placed on it, and I handled the WM_LBUTTONDOWN message on it, which perfectly executed when the code was compiled in Visual C++ 6.0. But the same code, when ported to VS 2005, does not respond to this message at all, although the code compiles and links fine in VS 2005. I tried to handle the notification message, NM_CLICK also, on the List Control which is on the dialog box, but to no avail. What must be the problem? Please suggest the remedy. Thanks,

    Software Developer Sanjay Khapre

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #3

    Where are you handling (or trying to handle) these messages....in the dialog class or a CListCtrl-derived class? Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    S 1 Reply Last reply
    0
    • M Mark Salsbery

      Where are you handling (or trying to handle) these messages....in the dialog class or a CListCtrl-derived class? Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S Offline
      S Offline
      SanjaySMK
      wrote on last edited by
      #4

      I am handling WM_LBUTTONDOWN message in a CListCtrl-derived class, but not getting why it's not working. When this project was in Visual C++ 6.0, it was running fine, but now that I have converted this to Visual C++ 2005, it is failing to run, although it compiles fine, and creates the DLL.

      Software Developer Sanjay Khapre

      M 1 Reply Last reply
      0
      • S SanjaySMK

        I am handling WM_LBUTTONDOWN message in a CListCtrl-derived class, but not getting why it's not working. When this project was in Visual C++ 6.0, it was running fine, but now that I have converted this to Visual C++ 2005, it is failing to run, although it compiles fine, and creates the DLL.

        Software Developer Sanjay Khapre

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #5

        This works for me - all the message/notification handlers get called:

        //
        // ReflectedListCtrl.h
        //

        #pragma once

        class CReflectedListCtrl : public CListCtrl
        {
        DECLARE_DYNAMIC(CReflectedListCtrl)

        public:
        CReflectedListCtrl();
        virtual ~CReflectedListCtrl();

        protected:
        DECLARE_MESSAGE_MAP()
        public:
        afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
        afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
        afx_msg void OnNMRClick(NMHDR *pNMHDR, LRESULT *pResult);
        };

        //
        // ReflectedListCtrl.cpp
        //

        #include "stdafx.h"
        #include "MyApp.h"
        #include "ReflectedListCtrl.h"

        // CReflectedListCtrl

        IMPLEMENT_DYNAMIC(CReflectedListCtrl, CListCtrl)

        CReflectedListCtrl::CReflectedListCtrl()
        {
        }

        CReflectedListCtrl::~CReflectedListCtrl()
        {
        }

        BEGIN_MESSAGE_MAP(CReflectedListCtrl, CListCtrl)
        ON_WM_LBUTTONDOWN()
        ON_NOTIFY_REFLECT(NM_CLICK, &CReflectedListCtrl::OnNMClick)
        ON_NOTIFY_REFLECT(NM_RCLICK, &CReflectedListCtrl::OnNMRClick)
        END_MESSAGE_MAP()

        // CReflectedListCtrl message handlers

        void CReflectedListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
        {
        CListCtrl::OnLButtonDown(nFlags, point);
        }

        void CReflectedListCtrl::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
        {
        // TODO: Add your control notification handler code here
        *pResult = 0;
        }

        void CReflectedListCtrl::OnNMRClick(NMHDR *pNMHDR, LRESULT *pResult)
        {
        // TODO: Add your control notification handler code here
        *pResult = 0;
        }

        What are you doing different? If the message handlers don't get called, does the constructor ever get called? Is the control being created successfully? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S 1 Reply Last reply
        0
        • M Mark Salsbery

          This works for me - all the message/notification handlers get called:

          //
          // ReflectedListCtrl.h
          //

          #pragma once

          class CReflectedListCtrl : public CListCtrl
          {
          DECLARE_DYNAMIC(CReflectedListCtrl)

          public:
          CReflectedListCtrl();
          virtual ~CReflectedListCtrl();

          protected:
          DECLARE_MESSAGE_MAP()
          public:
          afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
          afx_msg void OnNMClick(NMHDR *pNMHDR, LRESULT *pResult);
          afx_msg void OnNMRClick(NMHDR *pNMHDR, LRESULT *pResult);
          };

          //
          // ReflectedListCtrl.cpp
          //

          #include "stdafx.h"
          #include "MyApp.h"
          #include "ReflectedListCtrl.h"

          // CReflectedListCtrl

          IMPLEMENT_DYNAMIC(CReflectedListCtrl, CListCtrl)

          CReflectedListCtrl::CReflectedListCtrl()
          {
          }

          CReflectedListCtrl::~CReflectedListCtrl()
          {
          }

          BEGIN_MESSAGE_MAP(CReflectedListCtrl, CListCtrl)
          ON_WM_LBUTTONDOWN()
          ON_NOTIFY_REFLECT(NM_CLICK, &CReflectedListCtrl::OnNMClick)
          ON_NOTIFY_REFLECT(NM_RCLICK, &CReflectedListCtrl::OnNMRClick)
          END_MESSAGE_MAP()

          // CReflectedListCtrl message handlers

          void CReflectedListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
          {
          CListCtrl::OnLButtonDown(nFlags, point);
          }

          void CReflectedListCtrl::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
          {
          // TODO: Add your control notification handler code here
          *pResult = 0;
          }

          void CReflectedListCtrl::OnNMRClick(NMHDR *pNMHDR, LRESULT *pResult)
          {
          // TODO: Add your control notification handler code here
          *pResult = 0;
          }

          What are you doing different? If the message handlers don't get called, does the constructor ever get called? Is the control being created successfully? Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          S Offline
          S Offline
          SanjaySMK
          wrote on last edited by
          #6

          Yes Mark, Thanks a ton for the code snippet. I have the same code snippet, and as you asked, the required no. of CListCtrl-derived class objects are also getting created successfully, but still the events, WM_LBUTTONDOWN and WM_LBUTTONDBLCLK for those objects are not getting invoked in Visual C++ 2005! I am puzzled, why is this happening! Warm regards,

          Software Developer Sanjay Khapre

          M 1 Reply Last reply
          0
          • S SanjaySMK

            Yes Mark, Thanks a ton for the code snippet. I have the same code snippet, and as you asked, the required no. of CListCtrl-derived class objects are also getting created successfully, but still the events, WM_LBUTTONDOWN and WM_LBUTTONDBLCLK for those objects are not getting invoked in Visual C++ 2005! I am puzzled, why is this happening! Warm regards,

            Software Developer Sanjay Khapre

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #7

            SanjaySMK wrote:

            the required no. of CListCtrl-derived class objects are also getting created successfully

            Are you sure? How are you verifying that? What code are you using to create your custom control class? If the controls are in a dialog, how are you associating your custom control class with a control on the dialog? I tested on a dialog by adding this member to the dialog class

            CReflectedListCtrl m_ListCtrl;

            and associating it with a ListView control on the dialog resource by adding this to the dialog class' DoDataExchange()

            DDX_Control(pDX, IDC_LIST1, m_ListCtrl);

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            S 1 Reply Last reply
            0
            • M Mark Salsbery

              SanjaySMK wrote:

              the required no. of CListCtrl-derived class objects are also getting created successfully

              Are you sure? How are you verifying that? What code are you using to create your custom control class? If the controls are in a dialog, how are you associating your custom control class with a control on the dialog? I tested on a dialog by adding this member to the dialog class

              CReflectedListCtrl m_ListCtrl;

              and associating it with a ListView control on the dialog resource by adding this to the dialog class' DoDataExchange()

              DDX_Control(pDX, IDC_LIST1, m_ListCtrl);

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              S Offline
              S Offline
              SanjaySMK
              wrote on last edited by
              #8

              I called a message box from within the constructor of CListCtrl-derived class for which I declared two objects in its parent dialog class, and on both of their construction, I get this message box twice. That's how I ensured.

              Software Developer Sanjay Khapre

              M 1 Reply Last reply
              0
              • S SanjaySMK

                I called a message box from within the constructor of CListCtrl-derived class for which I declared two objects in its parent dialog class, and on both of their construction, I get this message box twice. That's how I ensured.

                Software Developer Sanjay Khapre

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #9

                That covers the C++ object....you also need the HWND object. Again, how are you associating the control with the C++ object?

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                S 1 Reply Last reply
                0
                • M Mark Salsbery

                  That covers the C++ object....you also need the HWND object. Again, how are you associating the control with the C++ object?

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  S Offline
                  S Offline
                  SanjaySMK
                  wrote on last edited by
                  #10

                  I am subclassing both CListCtrl-derived class and the Combo box objects.

                  Software Developer Sanjay Khapre

                  M 1 Reply Last reply
                  0
                  • S SanjaySMK

                    I am subclassing both CListCtrl-derived class and the Combo box objects.

                    Software Developer Sanjay Khapre

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #11

                    Still not answering my question however :)

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    S 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      Still not answering my question however :)

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      S Offline
                      S Offline
                      SanjaySMK
                      wrote on last edited by
                      #12

                      Sorry if I haven't answered your last question. The thing is, that subclassing is used in case of CListCtrl-derived class, the reason why I don't see its varible entries inside DoDataExchange, hence the problem. That means the requirement is that of making LBUTTONDOWN and LBUTTONDBLCLK work with subclassed windows of CListCtrl-derived class. Can you help me out with this? Thanks in advance.

                      Software Developer Sanjay Khapre

                      M 1 Reply Last reply
                      0
                      • S SanjaySMK

                        Sorry if I haven't answered your last question. The thing is, that subclassing is used in case of CListCtrl-derived class, the reason why I don't see its varible entries inside DoDataExchange, hence the problem. That means the requirement is that of making LBUTTONDOWN and LBUTTONDBLCLK work with subclassed windows of CListCtrl-derived class. Can you help me out with this? Thanks in advance.

                        Software Developer Sanjay Khapre

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #13

                        You have to add the entries to DoDataExchange if they are not there. If the listview controls are in the dialog resource, you can use the wizard to add a control variable. It will add an entry like DDX_Control(pDX, IDC_LIST1, m_ListCtrl); Change m_ListCtrl's type to your derived type in the header file. Then the control will be subclassed. From my previous working sample code:

                        // In the dialog class
                        CReflectedListCtrl m_ListCtrl;

                        // The dialog class' DoDataExchange() override
                        void CMyDialog::DoDataExchange(CDataExchange* pDX)
                        {
                        CDialog::DoDataExchange(pDX);
                        DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
                        }

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        modified on Wednesday, January 7, 2009 2:40 AM

                        S 1 Reply Last reply
                        0
                        • M Mark Salsbery

                          You have to add the entries to DoDataExchange if they are not there. If the listview controls are in the dialog resource, you can use the wizard to add a control variable. It will add an entry like DDX_Control(pDX, IDC_LIST1, m_ListCtrl); Change m_ListCtrl's type to your derived type in the header file. Then the control will be subclassed. From my previous working sample code:

                          // In the dialog class
                          CReflectedListCtrl m_ListCtrl;

                          // The dialog class' DoDataExchange() override
                          void CMyDialog::DoDataExchange(CDataExchange* pDX)
                          {
                          CDialog::DoDataExchange(pDX);
                          DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
                          }

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          modified on Wednesday, January 7, 2009 2:40 AM

                          S Offline
                          S Offline
                          SanjaySMK
                          wrote on last edited by
                          #14

                          In which case CWnd::SubclassWindow(HWND DocumentList) fails? Even though, the variable HWND DocumentList which I am using as its parameter is locally declared and initialized where I am calling SubclassWindow, still SubclassWindow is failing(Debug Assertion Failure!). What is its remedy? Could u please suggest? DocumentList parameter is declared and initialized some lines before calling SubclassWindow, as following: HWND DocumentList = CreateDocumentList(parenthandle, rect.left, rect.top, rect.Width(), rect.Height(), someflag) ; Line 1 Line 2 Line 3 SubclassWindow(DocumentList) ; // which fails here, why?

                          Software Developer Sanjay Khapre

                          modified on Thursday, January 8, 2009 5:24 AM

                          S M 2 Replies Last reply
                          0
                          • S SanjaySMK

                            In which case CWnd::SubclassWindow(HWND DocumentList) fails? Even though, the variable HWND DocumentList which I am using as its parameter is locally declared and initialized where I am calling SubclassWindow, still SubclassWindow is failing(Debug Assertion Failure!). What is its remedy? Could u please suggest? DocumentList parameter is declared and initialized some lines before calling SubclassWindow, as following: HWND DocumentList = CreateDocumentList(parenthandle, rect.left, rect.top, rect.Width(), rect.Height(), someflag) ; Line 1 Line 2 Line 3 SubclassWindow(DocumentList) ; // which fails here, why?

                            Software Developer Sanjay Khapre

                            modified on Thursday, January 8, 2009 5:24 AM

                            S Offline
                            S Offline
                            SanjaySMK
                            wrote on last edited by
                            #15

                            I got the answer of why SubclassWindow was failing, it was because I had DDX_Control entries inside DoDataExchange function, which shouldn't be there, otherwise the parameter to SubclassWindow will always be attached to the parent dialog box, which doesn't fit its criterion. But now after that, the messages WM_LBUTTONDOWN and WM_LBUTTONDBLCLK should run, which are not running. That means my question is, after calling CWnd::SubclassWindow function, why these two messages do not respond at all?Please suggest some remedy.

                            Software Developer Sanjay Khapre

                            modified on Thursday, January 8, 2009 9:34 AM

                            M 1 Reply Last reply
                            0
                            • S SanjaySMK

                              I got the answer of why SubclassWindow was failing, it was because I had DDX_Control entries inside DoDataExchange function, which shouldn't be there, otherwise the parameter to SubclassWindow will always be attached to the parent dialog box, which doesn't fit its criterion. But now after that, the messages WM_LBUTTONDOWN and WM_LBUTTONDBLCLK should run, which are not running. That means my question is, after calling CWnd::SubclassWindow function, why these two messages do not respond at all?Please suggest some remedy.

                              Software Developer Sanjay Khapre

                              modified on Thursday, January 8, 2009 9:34 AM

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #16

                              Why are you calling SubclassWindow? If you're using MFC you very rarely need to explicitly call it. Mark

                              Mark Salsbery Microsoft MVP - Visual C++ :java:

                              1 Reply Last reply
                              0
                              • S SanjaySMK

                                In which case CWnd::SubclassWindow(HWND DocumentList) fails? Even though, the variable HWND DocumentList which I am using as its parameter is locally declared and initialized where I am calling SubclassWindow, still SubclassWindow is failing(Debug Assertion Failure!). What is its remedy? Could u please suggest? DocumentList parameter is declared and initialized some lines before calling SubclassWindow, as following: HWND DocumentList = CreateDocumentList(parenthandle, rect.left, rect.top, rect.Width(), rect.Height(), someflag) ; Line 1 Line 2 Line 3 SubclassWindow(DocumentList) ; // which fails here, why?

                                Software Developer Sanjay Khapre

                                modified on Thursday, January 8, 2009 5:24 AM

                                M Offline
                                M Offline
                                Mark Salsbery
                                wrote on last edited by
                                #17

                                Where is this code called from? You really need to provide a context. If SubclassWindow is the CWnd SubclassWindow method, then what's the class you are calling it from?

                                SanjaySMK wrote:

                                which fails here, why?

                                Why don't you step into the function with the debugger and find out? :)

                                Mark Salsbery Microsoft MVP - Visual C++ :java:

                                S 1 Reply Last reply
                                0
                                • M Mark Salsbery

                                  Where is this code called from? You really need to provide a context. If SubclassWindow is the CWnd SubclassWindow method, then what's the class you are calling it from?

                                  SanjaySMK wrote:

                                  which fails here, why?

                                  Why don't you step into the function with the debugger and find out? :)

                                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                                  S Offline
                                  S Offline
                                  SanjaySMK
                                  wrote on last edited by
                                  #18

                                  I have a method in CListCtrl-derived class, from where I am calling CWnd::SubclassWindow, and after calling that, WM_LBUTTONDOWN and WM_LBUTTONDBLCLK do not get called at all.

                                  Software Developer Sanjay Khapre

                                  M 1 Reply Last reply
                                  0
                                  • S SanjaySMK

                                    I have a method in CListCtrl-derived class, from where I am calling CWnd::SubclassWindow, and after calling that, WM_LBUTTONDOWN and WM_LBUTTONDBLCLK do not get called at all.

                                    Software Developer Sanjay Khapre

                                    M Offline
                                    M Offline
                                    Mark Salsbery
                                    wrote on last edited by
                                    #19

                                    You still haven't answered WHY you are calling SubclassWindow. Where do the CListCtrl derived objects come from? Show some code.

                                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                                    S 1 Reply Last reply
                                    0
                                    • M Mark Salsbery

                                      You still haven't answered WHY you are calling SubclassWindow. Where do the CListCtrl derived objects come from? Show some code.

                                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                                      S Offline
                                      S Offline
                                      SanjaySMK
                                      wrote on last edited by
                                      #20

                                      CListCtrl derived objects come from the parent class, i.e. the dialog class, I call one member function of CListCtrl-derived class, SubClassMyList, in which I am calling SubclassWindow(HWND) function, after which mouse events don't work on this derived class. Sorry, I was away for some days, hence couldn't update you quickly.

                                      Software Developer Sanjay Khapre

                                      M 1 Reply Last reply
                                      0
                                      • S SanjaySMK

                                        CListCtrl derived objects come from the parent class, i.e. the dialog class, I call one member function of CListCtrl-derived class, SubClassMyList, in which I am calling SubclassWindow(HWND) function, after which mouse events don't work on this derived class. Sorry, I was away for some days, hence couldn't update you quickly.

                                        Software Developer Sanjay Khapre

                                        M Offline
                                        M Offline
                                        Mark Salsbery
                                        wrote on last edited by
                                        #21

                                        SanjaySMK wrote:

                                        in which I am calling SubclassWindow(HWND) function

                                        I don't know how many times I've asked why... All my MFC controls for the past decade have got mouse messages just fine without calling subclassWindow...

                                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                                        S 1 Reply Last reply
                                        0
                                        • M Mark Salsbery

                                          SanjaySMK wrote:

                                          in which I am calling SubclassWindow(HWND) function

                                          I don't know how many times I've asked why... All my MFC controls for the past decade have got mouse messages just fine without calling subclassWindow...

                                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                                          S Offline
                                          S Offline
                                          SanjaySMK
                                          wrote on last edited by
                                          #22

                                          Dear Mark, First of all, I am very sorry if I have tested your patience, although unknowingly and unintentionally. I have some big code of my project, which was running fine in Visual C++ 6.0(in which it was first written), but which I now needed to convert to Visual C++ 2005. After everything I have explained till date, since the functionality(mouse events) after conversion is not running in VC 2005, I created my own MFC application in VC 2005, in which, like the project code, I tried using CWnd's SubclassWindow(HWND). Since this functionality was running in VC 6.0, I need to keep and also make it run in VC 2005. Hence the inclusion of SubclassWindow also in my code(the sample application which I am trying these things in). I hope I am very much clear this time. Could you please help?

                                          Software Developer Sanjay Khapre

                                          modified on Friday, January 16, 2009 12:45 AM

                                          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