Solved

CListCtrl::DrawItem not called

Posted on 1998-06-16
10
2,406 Views
Last Modified: 2013-11-20
Hi,
I have subclassed the CListCtrl and set the LVS_OWNERDRAWFIXED style bit to make the control owner drawn
But my DrawItem() function is never called. I have tried all the obvious stuff -
Added a ListCtrl to a dialog and set the flag in its style dialog, added a member variable of my ClistCtrlEx to the dialog etc.
I have tried creating the control dynamically and setting the flags LVS_OWNERDRAWFIXED and LVS_ICON in the call to Create().
One thing that may be a problem is that DevStudio does not provide DrawItem as an available overridable virtual
function so I added it manually though I dont see it being a problem???
Thanks in advance
Ronan
0
Comment
Question by:ronanm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:Belgarat
ID: 1318034
Hmm... my DevStudio documentation shows that there is virtual DrawItem function in the CListCtrl class. It is called every time WM_DRAWITEM message is reflected to the control (see %dev%\vc\mfc\src\winctrl2.cpp)

0
 
LVL 3

Expert Comment

by:shaig
ID: 1318035
HAve you added the WS_ flag indicating that you wish to preform ownerdrawing?
see the Window styles and extended styles
0
 

Author Comment

by:ronanm
ID: 1318036
Shaig,
What is this WS_flag you speak of?
According to all documentation and usenet postings I have seen the flag to set is LVS_OWNERDRAWFIXED.

Belgarat,
Yep I know all abou the DrawItem virtual function, as I said I have implemented it in my CListCtrlEx class but it never gets called. I have followed an example from www.codeguru.com that says override the message but DevStudio does not support this (only this one virtual function)so I had to do it manually, it creats an OnDrawItem that takes different parameters and yep this isn't called either.

I also have a sample from a book called VC++ How Too by Scott Stanfield, which subclasses a regular listbox. My code is identicle to his which works. But still no calls to DrawItem???

Finally there was a posting on usenett that said that I had to call SubclassDlgItem in my dialogs InitInstance but that crashes every time. If I put the same call into the regular listbox sample it works??

Believe me I have tried the obvious stuff this is a tough one for a real expert, somebody must have done this before, lots of questions on usenet about this one but very few answers and I have tried them all!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Belgarat
ID: 1318037
Sorry for my ignorance, but in what class do you define the DrawItem virtual function ? Do you attach instance of that class to the ListCtrl control ?
0
 
LVL 3

Expert Comment

by:NullTerminator
ID: 1318038
// in the dialog file
// make sure to subclass the control
// either setup a DDX_Control with class wizard or
// call subclassWindow
// MAKE SURE THAT THE LIST CONTROL  MEMBER VARIABLE IN THE
// HEADER FOR YOUR DIALOG CLASS IS OF YOUR TYPE.

// check the header file
DECLARE_DYNAMIC (CMyListCtrl)
void DrawItem(LPDRAWITEMSTRUCT lpDIS);

// be sure in implementation
IMPLEMENT_DYNAMIC (CMyListCtrl, CListCtrl)

// make sure DrawItem is a member function of your class!
void CMyListControl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{ /* yada yada yada */ }
0
 
LVL 1

Expert Comment

by:V245
ID: 1318039
Did you override OnPaint()?
0
 

Author Comment

by:ronanm
ID: 1318040
Well the latest on this seems to be that you can not have an owner drawn listCtrl unless you use the report mode. The callbacks won't work in Icon mode!
This is rediculously hard! Every time I turn my computer on, there it is a listCtrl in Icon mode with a bitmap as its background i.e. the desktop. I have used spy to examine it, it is not owner drawn, it is not transparent therefore there must be some way of doing this without completely re-writing the listview control!
0
 
LVL 1

Expert Comment

by:dkremer
ID: 1318041
Hi.
Check out www.codeguru.com - the ListView section - it has numerous samples of owner drawn list controls.
I think it'll answer all your questions, and more :)

0
 

Author Comment

by:ronanm
ID: 1318042
Well, thanks for the input Guys/Girls??? the answer actually is to override the WM_ERASEBKGROUND message and paint the bitmap there, unfortunately this means that draging icons around etc means loads of code to re-paint as they move etc. It is all too much for my purpose so I will let this drop and try a new approach.
0
 
LVL 1

Accepted Solution

by:
timop earned 200 total points
ID: 1318043
The flag LVS_OWNERDRAWFIXED enables to paint items in report view, therefore you must create the control with the flags LVS_OWNERDRAWFIXED | LVS_REPORT
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 46
Prevent this page from creating additional dialogs. 3 717
countEvens challenge 2 113
Window placement 17 95
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

756 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