CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 33
  1. #16
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    class IEHeaderCtrl : public CHeaderCtrl { // Construction public: IEHeaderCtrl(); // Generated message map functions protected: afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    DECLARE_MESSAGE_MAP()
    }

    Code for IEHeaderCtrl.cpp

    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP

    void IEHeaderCtrl::
    DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { HDITEM hdi; CBrush brush(RGB(255, 0, 0)); CString csBuffer; CRect rectFrame(lpDrawItemStruct->rcItem); ZeroMemory(&hdi, sizeof(HDITEM)); hdi.mask = HDI_TEXT; LPTSTR pBuf = csBuffer.GetBufferSetLength(MAX_PATH); hdi.mask = HDI_TEXT; hdi.pszText = pBuf; hdi.cchTextMax = MAX_PATH; GetItem(lpDrawItemStruct->itemID, &hdi); csBuffer.ReleaseBuffer(); CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); pDC->FillRect(rectFrame, &brush); pDC->SetTextColor(RGB(255, 255, 255)); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); brush.Detach();
    }

    /*code for Myformview.cpp where my listctrl is embedded:*/

    void MyFormView :: OnInitiUpdate()
    {
    IEHeaderCtrl m_HeaderCtrl;
    CHeaderCtrl* pHeader = NULL; pHeader=m_List.GetHeaderCtrl(); VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd)); HDITEM hdItem; hdItem.mask = HDI_FORMAT;
    }
    Can you read what you have posted?
    I can't.

    Please, post good readable, formatted code snippet. Use Code tags.
    Victor Nijegorodov

  2. #17
    Join Date
    Oct 2019
    Posts
    82

    Re: Coloring header row of CListCtrl C++

    Code:
     
    class IEHeaderCtrl : public CHeaderCtrl 
    { 
    public:
        IEHeaderCtrl();
    
    protected:
        afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 
    
        DECLARE_MESSAGE_MAP()
    }
    Code for IEHeaderCtrl.cpp
    Code:
    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP
    
    void IEHeaderCtrl::DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    { 
        HDITEM hdi; 
        CBrush brush(RGB(255, 0, 0)); 
        CString csBuffer;
        CRect rectFrame(lpDrawItemStruct->rcItem);
        ZeroMemory(&hdi, sizeof(HDITEM));
    
        hdi.mask = HDI_TEXT;
    
        LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH); 
    
        hdi.mask = HDI_TEXT;
        hdi.pszText = pBuf; 
        hdi.cchTextMax = MAX_PATH;
        GetItem(lpDrawItemStruct->itemID, &hdi);
        csBuffer.ReleaseBuffer(); 
    
        CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); 
    
        pDC->FillRect(rectFrame, &brush); 
        pDC->SetTextColor(RGB(255, 255, 255));
        pDC->SetBkMode(TRANSPARENT); 
        pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
        brush.Detach(); 
    }
    code for Myformview.cpp where my listctrl is embedded:

    Code:
    void MyFormView :: OnInitiUpdate()
    { 
        IEHeaderCtrl m_HeaderCtrl;
        CHeaderCtrl* pHeader = NULL;
    
        pHeader=m_List.GetHeaderCtrl();
        VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));	
    
        HDITEM hdItem;
     
        hdItem.mask = HDI_FORMAT; 
    }
    Last edited by 2kaud; October 10th, 2019 at 07:50 AM. Reason: Formatting

  3. #18
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    Code:
     
    
    class IEHeaderCtrl : public CHeaderCtrl 
    { 
    public: IEHeaderCtrl(); 
    protected: afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 
    DECLARE_MESSAGE_MAP()
    }
    Code for IEHeaderCtrl.cpp
    Code:
    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP
    
    void IEHeaderCtrl:: 
    DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    { 
    HDITEM hdi; 
    CBrush brush(RGB(255, 0, 0)); 
    CString csBuffer;
    CRect rectFrame(lpDrawItemStruct->rcItem); ZeroMemory(&hdi, sizeof(HDITEM));
    hdi.mask = HDI_TEXT;
    LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH); 
    hdi.mask = HDI_TEXT;
    hdi.pszText = pBuf; 
    hdi.cchTextMax = MAX_PATH; GetItem(lpDrawItemStruct->itemID, &hdi); csBuffer.ReleaseBuffer(); 
    CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); 
    pDC->FillRect(rectFrame, &brush); 
    pDC->SetTextColor(RGB(255, 255, 255));
    pDC->SetBkMode(TRANSPARENT); 
    pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); brush.Detach(); 
    }
    Please, post your real code that compiles! not just a pseudo code.
    And use the proper code indentations!
    Victor Nijegorodov

  4. #19
    Join Date
    Oct 2019
    Posts
    82

    Re: Coloring header row of CListCtrl C++

    This is a real code and compiling at my end..

  5. #20
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    This is a real code and compiling at my end..
    Then where and how is this method
    Code:
    void IEHeaderCtrl:: 
    DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    declared?
    Victor Nijegorodov

  6. #21
    Join Date
    Oct 2019
    Posts
    82

    Re: Coloring header row of CListCtrl C++

    See this, although already posted above..

    Code:
    class IEHeaderCtrl : public CHeaderCtrl 
    { 
    public:
        IEHeaderCtrl(); 
    
    protected: 
        afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 
        DECLARE_MESSAGE_MAP()
    }
    Last edited by 2kaud; October 10th, 2019 at 07:46 AM. Reason: Formatting

  7. #22
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    See this, although already posted above..

    Code:
    class IEHeaderCtrl : public CHeaderCtrl 
    { 
    public: IEHeaderCtrl(); 
    protected: 
    afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 
    DECLARE_MESSAGE_MAP()
    }
    Well, there is
    Code:
    ...
    afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 
    ...
    , not the
    Code:
    DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    Victor Nijegorodov

  8. #23
    Join Date
    Oct 2019
    Posts
    82

    Re: Coloring header row of CListCtrl C++

    Not getting what else you want.see the code below(already posted) which is having definition of DrawItem

    Code:
    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP
    
    void IEHeaderCtrl::DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    { 
        HDITEM hdi; 
        CBrush brush(RGB(255, 0, 0)); 
        CString csBuffer;
        CRect rectFrame(lpDrawItemStruct->rcItem);
    
        ZeroMemory(&hdi, sizeof(HDITEM));
        hdi.mask = HDI_TEXT;
    
        LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH); 
    
        hdi.mask = HDI_TEXT;
        hdi.pszText = pBuf; 
        hdi.cchTextMax = MAX_PATH;
        GetItem(lpDrawItemStruct->itemID, &hdi);
        csBuffer.ReleaseBuffer(); 
    
        CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); 
    
        pDC->FillRect(rectFrame, &brush); 
        pDC->SetTextColor(RGB(255, 255, 255));
        pDC->SetBkMode(TRANSPARENT); 
        pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
        brush.Detach(); 
    }
    Last edited by 2kaud; October 10th, 2019 at 07:51 AM. Reason: Formatting

  9. #24
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    Not getting what else you want.see the code below(already posted) which is having definition of DrawItem

    Code:
    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP
    
    void IEHeaderCtrl:: 
    DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    { 
       ...
    }
    There is no "definition of DrawItem".
    There is a definition of DawItem.
    Victor Nijegorodov

  10. #25
    Join Date
    Oct 2019
    Posts
    82

    Re: Coloring header row of CListCtrl C++

    Oohhh Victor.i spelled it wrong here but at my wnd its DrawItem only
    .Sorry ,plz assume it as DrawItem and tell the solution

  11. #26
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    Oohhh Victor.i spelled it wrong here but at my wnd its DrawItem only
    .Sorry ,plz assume it as DrawItem and tell the solution
    Again: post your real code.
    Why don't you want just copy/paste the code from your IDE?
    Why do you ignore code indentation (or you remove it before sending a post?)
    Victor Nijegorodov

  12. #27
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Coloring header row of CListCtrl C++

    Code tags and formatting please. That mess is unreadable.

  13. #28
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by GCDEF View Post
    Code tags and formatting please. That mess is unreadable.
    [Code formatted]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  14. #29
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: Coloring header row of CListCtrl C++

    Quote Originally Posted by Beginner_MFC View Post
    Not getting what else you want.see the code below(already posted) which is having definition of DrawItem

    Code:
    BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
    END_MESSAGE_MAP
    
    void IEHeaderCtrl::DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    { 
        HDITEM hdi; 
        CBrush brush(RGB(255, 0, 0)); 
        CString csBuffer;
        CRect rectFrame(lpDrawItemStruct->rcItem);
    
        ZeroMemory(&hdi, sizeof(HDITEM));
        hdi.mask = HDI_TEXT;
    
        LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH); 
    
        hdi.mask = HDI_TEXT;
        hdi.pszText = pBuf; 
        hdi.cchTextMax = MAX_PATH;
        GetItem(lpDrawItemStruct->itemID, &hdi);
        csBuffer.ReleaseBuffer(); 
    
        CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); 
    
        pDC->FillRect(rectFrame, &brush); 
        pDC->SetTextColor(RGB(255, 255, 255));
        pDC->SetBkMode(TRANSPARENT); 
        pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
        brush.Detach(); 
    }
    Did you debug your code? Is this DawItem (or DrawItem) called?

    And BTW, do you set the ownerdraw flag to the header control items? See the Owner-Drawn Header Controls section in MSDN
    Victor Nijegorodov

  15. #30
    Join Date
    Oct 2019
    Posts
    82

    Re: Coloring header row of CListCtrl C++

    Resolved..Thankyou

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured