CListCtrl::DrawItem not called

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
ronanmAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
timopConnect With a Mentor Commented:
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
 
BelgaratCommented:
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
 
shaigCommented:
HAve you added the WS_ flag indicating that you wish to preform ownerdrawing?
see the Window styles and extended styles
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
ronanmAuthor Commented:
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
 
BelgaratCommented:
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
 
NullTerminatorCommented:
// 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
 
V245Commented:
Did you override OnPaint()?
0
 
ronanmAuthor Commented:
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
 
dkremerCommented:
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
 
ronanmAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.