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. CListCtrl control text call back problem

CListCtrl control text call back problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++testingbeta-testinghelpquestion
7 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.
  • J Offline
    J Offline
    J B 0
    wrote on last edited by
    #1

    Hi guys, I have a CListCtrl control inserted to my dialog app (MFC). I needed to customise the text display on the control and from Michael's suggestion (Thanks, Mr. Dunn!), I tried using LVN_GETDISPINFO message, which calls my OnGetDispInfo function. The problem is that the callback doesn't seem to get call when already using LPSTR_TEXTCALLBACK. The message map is created as below:

    	ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
    

    and the callback function is decalred in my CMyDlg class.

    	afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
    

    I add items to the control (m_TaskList) using the way below:

    	m_TaskList.InsertItem(LVIF_TEXT|LVIF_STATE, itemCount, LPSTR_TEXTCALLBACK, LVIS_SELECTED, LVIS_SELECTED, 0, 0);
    

    and the following callback function is never called,

    void CMyDlg::OnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
    {
    	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
    
    	if (pDispInfo->item.mask & LVIF_TEXT)
    		pDispInfo->item.pszText = _T("Testing");	
    	*pResult = 0;
    }
    

    Can anyone spot where I have done wrong? Thanks alot

    V C 2 Replies Last reply
    0
    • J J B 0

      Hi guys, I have a CListCtrl control inserted to my dialog app (MFC). I needed to customise the text display on the control and from Michael's suggestion (Thanks, Mr. Dunn!), I tried using LVN_GETDISPINFO message, which calls my OnGetDispInfo function. The problem is that the callback doesn't seem to get call when already using LPSTR_TEXTCALLBACK. The message map is created as below:

      	ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
      

      and the callback function is decalred in my CMyDlg class.

      	afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
      

      I add items to the control (m_TaskList) using the way below:

      	m_TaskList.InsertItem(LVIF_TEXT|LVIF_STATE, itemCount, LPSTR_TEXTCALLBACK, LVIS_SELECTED, LVIS_SELECTED, 0, 0);
      

      and the following callback function is never called,

      void CMyDlg::OnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
      {
      	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
      
      	if (pDispInfo->item.mask & LVIF_TEXT)
      		pDispInfo->item.pszText = _T("Testing");	
      	*pResult = 0;
      }
      

      Can anyone spot where I have done wrong? Thanks alot

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      What change? You have to explicitly notify the list control upon a change. One example is LVM_INSERTITEM. Kuphryn

      J 1 Reply Last reply
      0
      • V valikac

        What change? You have to explicitly notify the list control upon a change. One example is LVM_INSERTITEM. Kuphryn

        J Offline
        J Offline
        J B 0
        wrote on last edited by
        #3

        Thanks for the reply Kuphryn, I'm not quite sure if I understand what you mean. In MFC, when I'm calling InsertItem() on the CListCtrl control, it euqally means sending the notification LVM_INSERTITEM to the control. Doesn't it?:confused: Thanks again.

        V 1 Reply Last reply
        0
        • J J B 0

          Thanks for the reply Kuphryn, I'm not quite sure if I understand what you mean. In MFC, when I'm calling InsertItem() on the CListCtrl control, it euqally means sending the notification LVM_INSERTITEM to the control. Doesn't it?:confused: Thanks again.

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          You're not receiving the LVN_GETDISPINFO message, correct? I'm saying that you have to update the list control via sending its a message if you want to to make the change. Kuphryn

          J 1 Reply Last reply
          0
          • V valikac

            You're not receiving the LVN_GETDISPINFO message, correct? I'm saying that you have to update the list control via sending its a message if you want to to make the change. Kuphryn

            J Offline
            J Offline
            J B 0
            wrote on last edited by
            #5

            Doesn't the call

            m_TaskList.InsertItem(LVIF_TEXT|LVIF_STATE, itemCount, LPSTR_TEXTCALLBACK, LVIS_SELECTED, LVIS_SELECTED, 0, 0);
            

            mean sending a message (LVM_INSERTITEM) to the control and update it according to specified information? LPSTR_TEXTCALLBACK tells the control the text is a callback item, so will call OnGetDispInfo() Why do I have to explicitly send message to the control again? Am I missing something? Thanks again

            1 Reply Last reply
            0
            • J J B 0

              Hi guys, I have a CListCtrl control inserted to my dialog app (MFC). I needed to customise the text display on the control and from Michael's suggestion (Thanks, Mr. Dunn!), I tried using LVN_GETDISPINFO message, which calls my OnGetDispInfo function. The problem is that the callback doesn't seem to get call when already using LPSTR_TEXTCALLBACK. The message map is created as below:

              	ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
              

              and the callback function is decalred in my CMyDlg class.

              	afx_msg void OnGetDispInfo(NMHDR* pNMHDR, LRESULT* pResult);
              

              I add items to the control (m_TaskList) using the way below:

              	m_TaskList.InsertItem(LVIF_TEXT|LVIF_STATE, itemCount, LPSTR_TEXTCALLBACK, LVIS_SELECTED, LVIS_SELECTED, 0, 0);
              

              and the following callback function is never called,

              void CMyDlg::OnGetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
              {
              	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
              
              	if (pDispInfo->item.mask & LVIF_TEXT)
              		pDispInfo->item.pszText = _T("Testing");	
              	*pResult = 0;
              }
              

              Can anyone spot where I have done wrong? Thanks alot

              C Offline
              C Offline
              Chris Richardson
              wrote on last edited by
              #6

              Don't use ON_NOTIFY_REFLECT. That macro would be used if you were trying to do this in a class that was derived from CListCtrl. Since you are catching this message in a dialog (I suppose, based on the name CMyDlg), use ON_NOTIFY. Good luck, Chris Richardson

              J 1 Reply Last reply
              0
              • C Chris Richardson

                Don't use ON_NOTIFY_REFLECT. That macro would be used if you were trying to do this in a class that was derived from CListCtrl. Since you are catching this message in a dialog (I suppose, based on the name CMyDlg), use ON_NOTIFY. Good luck, Chris Richardson

                J Offline
                J Offline
                J B 0
                wrote on last edited by
                #7

                Thanks Chris, that works for me :-D

                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