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. How to add Message for dynamically created control(CListCtrl)

How to add Message for dynamically created control(CListCtrl)

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
6 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 Offline
    S Offline
    shanmugarajaa
    wrote on last edited by
    #1

    I have created CListCtrl using Create()function. But I dont know to add Message like CLICK, DBILCLK for created control. Friends Kindly help me. Regards, S.Shanmugaraja

    _ 1 Reply Last reply
    0
    • S shanmugarajaa

      I have created CListCtrl using Create()function. But I dont know to add Message like CLICK, DBILCLK for created control. Friends Kindly help me. Regards, S.Shanmugaraja

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      Every dynamically created control have an ID, so use that ID and map your event like wizzard do for normal CListCtrl control ...

      _ 1 Reply Last reply
      0
      • _ _Flaviu

        Every dynamically created control have an ID, so use that ID and map your event like wizzard do for normal CListCtrl control ...

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Ok, let's do some code sample :

        // MyClass.h
        #define IDC_LIST 1001

        CListCtrl m_List;

        protected:
        //{{AFX_MSG(CMyClass)
        afx_msg void OnClickList(NMHDR* pNMHDR, LRESULT* pResult);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()

        // MyClass.cpp

        BEGIN_MESSAGE_MAP(CMyClass, CView)
        //{{AFX_MSG_MAP(CMyClass)
        ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
        //}}AFX_MSG_MAP

        int CMyClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
        {
        if(CView::OnCreate(lpCreateStruct) == -1)return -1;
        // TODO: Add your specialized creation code here
        DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | CS_DBLCLKS | LVS_REPORT;
        BOOL bResult = m_List.Create(dwStyle,CRect(0,0,0,0),this,IDC_LIST);
        return bResult ? 0 : -1;
        // return 0;
        }

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

        S 1 Reply Last reply
        0
        • _ _Flaviu

          Ok, let's do some code sample :

          // MyClass.h
          #define IDC_LIST 1001

          CListCtrl m_List;

          protected:
          //{{AFX_MSG(CMyClass)
          afx_msg void OnClickList(NMHDR* pNMHDR, LRESULT* pResult);
          //}}AFX_MSG
          DECLARE_MESSAGE_MAP()

          // MyClass.cpp

          BEGIN_MESSAGE_MAP(CMyClass, CView)
          //{{AFX_MSG_MAP(CMyClass)
          ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
          //}}AFX_MSG_MAP

          int CMyClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
          {
          if(CView::OnCreate(lpCreateStruct) == -1)return -1;
          // TODO: Add your specialized creation code here
          DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | CS_DBLCLKS | LVS_REPORT;
          BOOL bResult = m_List.Create(dwStyle,CRect(0,0,0,0),this,IDC_LIST);
          return bResult ? 0 : -1;
          // return 0;
          }

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

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

          Its working good. In my case control Id is dynamic generated.

          For Example:
          pmyListCtrl->Create( WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,CRect(10,10,300,200), this, ControlID);

          So how can i find controlID? and how to pass this ID into message Map?

          _ P 2 Replies Last reply
          0
          • S shanmugarajaa

            Its working good. In my case control Id is dynamic generated.

            For Example:
            pmyListCtrl->Create( WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,CRect(10,10,300,200), this, ControlID);

            So how can i find controlID? and how to pass this ID into message Map?

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            I don't know how you generate dynamic control ID ...

            1 Reply Last reply
            0
            • S shanmugarajaa

              Its working good. In my case control Id is dynamic generated.

              For Example:
              pmyListCtrl->Create( WS_CHILD|WS_VISIBLE|WS_BORDER|LVS_REPORT,CRect(10,10,300,200), this, ControlID);

              So how can i find controlID? and how to pass this ID into message Map?

              P Offline
              P Offline
              Parthi_Appu
              wrote on last edited by
              #6

              Simply you cannot have some random IDs for your control but you can have some range of IDs that can be used dynamically, Say from 1001(IDC_MYLIST_START) to 1101 (IDC_MYLIST_END) and use any of this IDs for you list control and make sure you did not have more than one list with the same ID in a given time. For this you have to use ON_NOTIFY_RANGE macro and your message map entry will look like,

              ON_NOTIFY_RANGE(NM_CLICK, IDC_MYLIST_START, IDC_MYLIST_END, OnMyListClick)

              And you message handler will be,

              VOID OnMyListClick(UINT id, NMHDR * pNotifyStruct, LRESULT * result)

              The variable "id" will have the list control ID which has been clicked.


              Do your Duty and Don't expect the Result

              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