ownerdraw clistctrl assert

Posted on 2006-05-04
Last Modified: 2013-11-20
I'm getting an Assesition error when I try to override the OwnerDrawn List Control.  Why would this be.  

// ---------------------
// -- CListCtrlStyled --
// ---------------------
class CListCtrlStyled : public CListCtrl
     // -- Construction --
     virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);


void CListCtrlStyled::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
    HDC hDC = ::GetDC(NULL);
    CFont* pFont = GetFont();
    HFONT hFontOld = (HFONT)SelectObject(hDC, pFont->GetSafeHandle());
    GetTextMetrics(hDC, &tm);
    lpMeasureItemStruct->itemHeight = tm.tmHeight + tm.tmExternalLeading + 1;
    SelectObject(hDC, hFontOld);
    ::ReleaseDC(NULL, hDC);

void CListCtrlStyled::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
Question by:cophi
    LVL 86

    Expert Comment

    >>I'm getting an Assesition error

    Where exactly?

    Author Comment

    Oh sorry in the CListCtrl DrawItem
    LVL 86

    Accepted Solution

    That's not surprising, since the code for that function is

    void CListCtrl::DrawItem(LPDRAWITEMSTRUCT)

    You should not call the base class implementation here, only provide your own implementation. As the docs state:

    "By default, this member function does nothing. Override this member function to implement drawing for an owner-draw CListCtrl object."

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now