CListCtrl control text call back problem
-
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 myOnGetDispInfo
function. The problem is that the callback doesn't seem to get call when already usingLPSTR_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
-
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 myOnGetDispInfo
function. The problem is that the callback doesn't seem to get call when already usingLPSTR_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
-
What change? You have to explicitly notify the list control upon a change. One example is LVM_INSERTITEM. Kuphryn
-
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. -
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
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 callOnGetDispInfo()
Why do I have to explicitly send message to the control again? Am I missing something? Thanks again -
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 myOnGetDispInfo
function. The problem is that the callback doesn't seem to get call when already usingLPSTR_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
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
-
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