CMFCTaskPane-Highlighting/DeHighlighting task text on clicking the task

abc abc 346 Reputation points
2020-12-24T12:42:10.267+00:00

Hi,

In CMFCTaskPane, I want to change the text color of the task in blue when click on the task text.
I am able to change task color using BOOL SetTaskTextColor(int nGroup, int nTask, COLORREF color, COLORREF colorHot = (COLORREF)-1); but when I clicking another task I need to dehighlight previously selected task.I dont know how to do it. please help me

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,757 questions
No comments
{count} votes

Accepted answer
  1. RLWA32 30,131 Reputation points
    2020-12-24T15:43:49.84+00:00

    For example, using the MFC TaskPanes sample at TasksPane to set clicked task text to green

    Add to the bottom of CTaskPane class in TaskPane.h -

    protected:
        BOOL CreateTreeControl();
        BOOL CreateEditControl();
    
        int  m_prevGroup{ -1 }; //Added by RLWA32
        int  m_prevTask{ -1 };  //Added by RLWA32
        COLORREF m_prevClr;  //Added by RLWA32
    
    // Implementation
    public:
        virtual ~CTaskPane();
        virtual void OnClickTask(int nGroupNumber, int nTaskNumber, UINT uiCommandID, DWORD_PTR dwUserData);  //Added by RLWA32
    
    protected:
        afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    
        DECLARE_MESSAGE_MAP()
    };
    

    Add OnClickTask override to TaskPane.cpp -

    void CTaskPane::OnClickTask(int nGroupNumber, int nTaskNumber, UINT uiCommandID, DWORD_PTR dwUserData)
    {
        if (nGroupNumber != m_prevGroup || nTaskNumber != m_prevTask)
        {
            if (m_prevGroup != -1 && m_prevTask != -1)
                SetTaskTextColor(m_prevGroup, m_prevTask, m_prevClr);
        }
    
        m_prevGroup = nGroupNumber;
        m_prevTask = nTaskNumber;
        m_prevClr = GetTask(nGroupNumber, nTaskNumber)->m_clrText;
    
        SetTaskTextColor(nGroupNumber, nTaskNumber, RGB(0, 255, 0));
    
        CMFCTasksPane::OnClickTask(nGroupNumber, nTaskNumber, uiCommandID, dwUserData);
    }
    

0 additional answers

Sort by: Most helpful