Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been away from MFC for way too long and have a newbie question regarding callbacks.

I'm trying to make a variation of the CListCtrl listbox that asks if a line is valid, then turns the line red if it isn't. A callback or function pointer would be perfect, but I'm having trouble making it work.

This is basically what I'm trying to do:

C++
class CListCtrl2 : public CListCtrl
{
public:
    bool (*DataIsValidCheck)(void *data);     // a remote function 
protected:
    void DrawItem(void *data);
}
void CListCtrl2::DrawItem(void *data)
{
    bool showNormal=false;
    if(DataIsValidCheck!=NULL)                // if its set, then call it
       showNormal=DataIsValidCheck(data);
    if(showNormal)
       textcolor=black;
    else
       textcolor=red;
    ...
}

class MyWindow : public CDialog
{
public:
    bool CheckItemValidity(void *data);       // parent window with ability to validate item
protected:
    CListCtrl2	ListCtrl;                     // the list control 
}
MyWindow::MyWindow()
{
    ListCtrl2.DataIsValidCheck = this->CheckItemValidity;
}
bool MyWindow::CheckItemValidity(void *itemData)
{
   if(...)
      return true;
   else
      return false;
}


What is the right way to do this call in MFC C++?
Thanks for any help!
Posted

You will probably need to add a notification handler(s) as described here[^], and react to particular status changes within the control.
 
Share this answer
 
Thanks Richard - that got me in the right direction.
I ended up using ON_NOTIFY_REFLECT (NM_CUSTOMDRAW, OnCustomDraw)
to then send the calling window a user message that verifies the data
(rookie stuff :/ )
 
Share this answer
 
Comments
Richard MacCutchan 6-Oct-11 12:01pm    
It's all rookie stuff when you know the answer. Anyway, happy to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900