CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2011
    Posts
    7

    call DrawItem(). OnPaint()

    I have a class named CMyListCtrl derived from CListCtrl using LVS_REPORT
    with multiple columns. It is owner draw and overrides both OnPaint() and
    DrawItem().but it dosen't work,only onpaint() function work,and the drawitem can't be called .why the drawitem and onpaint function aren't carried out at the same time and just execute onpaint?thank you to help me.
    Last edited by xiaohangge; September 21st, 2011 at 09:05 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: call DrawItem(). OnPaint()

    Quote Originally Posted by xiaohangge View Post
    ... it dosen't work,only onpaint() function work,and the drawitem can't be called .why?
    why?
    Because you did something wrong!
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2011
    Posts
    7

    Re: call DrawItem(). OnPaint()

    Quote Originally Posted by VictorN View Post
    why?
    Because you did something wrong!
    I set a breakpoint in drawitem,but there are nothing reaction.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: call DrawItem(). OnPaint()

    Quote Originally Posted by xiaohangge View Post
    I set a breakpoint in drawitem,but there are nothing reaction.
    We had already understood it after reading your OP.
    Victor Nijegorodov

  5. #5
    Join Date
    Sep 2011
    Posts
    7

    Re: call DrawItem(). OnPaint()

    Quote Originally Posted by VictorN View Post
    We had already understood it after reading your OP.
    do you have some answers?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: call DrawItem(). OnPaint()

    Well, you asked only one question. It was: "why?"
    And I already answered you in the post#2.

    However, if you want more help then you have to provide more useful info about your project, class, control, implementation, and so on... Maybe posting a small test project reproducing your problem would be useful...
    Victor Nijegorodov

  7. #7
    Join Date
    Sep 2011
    Posts
    7

    Re: call DrawItem(). OnPaint()

    .if i do not define onpaint,drawitem can be called.i refer to some information,and some say if the ower window has the onpaint fuction,the overrided drawitem would not be called.i do not know whether it is correct,and if it is correct,why is it so?

  8. #8
    Join Date
    Apr 2006
    Location
    Rhode Island
    Posts
    32

    Re: call DrawItem(). OnPaint()

    xiaohangge,

    I did a few Google searches and found an old CodeGuru forum question asking something similar (this is not a "why didn't you look this up first" post, I found it by accident).

    http://www.codeguru.com/forum/archiv.../t-327604.html

    But a big part of your problem may be that OnDraw() is called within OnPaint() and because you are not calling either the original OnPaint() or not just not calling OnDraw() within your override method.

    If you are completely controlling the OnPaint then call your ONDraw() but it would be wise to call the original OnPaint() within your method and let it call your OnDraw(). Whenever we override MFC methods we tend to call into the original either first or at the end just so the system handles most of the work and we can just do what we wanted...

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: call DrawItem(). OnPaint()

    If you mean that you implemented the OnPaint in your CMyListCtrl class then I should say that you don't need it at all.
    What you need to (and must if you are using owner draw list control) is override the virtual CListCtrl:rawItem in this CMyListCtrl class!
    Victor Nijegorodov

  10. #10
    Join Date
    Sep 2011
    Posts
    7

    Re: call DrawItem(). OnPaint()

    Quote Originally Posted by DemonPiggies View Post
    xiaohangge,

    I did a few Google searches and found an old CodeGuru forum question asking something similar (this is not a "why didn't you look this up first" post, I found it by accident).

    http://www.codeguru.com/forum/archiv.../t-327604.html

    But a big part of your problem may be that OnDraw() is called within OnPaint() and because you are not calling either the original OnPaint() or not just not calling OnDraw() within your override method.

    If you are completely controlling the OnPaint then call your ONDraw() but it would be wise to call the original OnPaint() within your method and let it call your OnDraw(). Whenever we override MFC methods we tend to call into the original either first or at the end just so the system handles most of the work and we can just do what we wanted...
    Thanks,but what i said is about drawitem and onpaint in clistctrl class,not ondraw and onpaint.

  11. #11
    Join Date
    Sep 2011
    Posts
    7

    Re: call DrawItem(). OnPaint()

    Quote Originally Posted by VictorN View Post
    If you mean that you implemented the OnPaint in your CMyListCtrl class then I should say that you don't need it at all.
    What you need to (and must if you are using owner draw list control) is override the virtual CListCtrl:rawItem in this CMyListCtrl class!
    thank you. Can you give me elaborate explanations which work is done in both functions-drawitem and onpaint -respectively.if I want to use both functions at the same time ,how to implment,

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: call DrawItem(). OnPaint()

    Victor Nijegorodov

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