Link to home
Start Free TrialLog in
Avatar of ronanm
ronanm

asked on

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
Avatar of Belgarat
Belgarat

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)

HAve you added the WS_ flag indicating that you wish to preform ownerdrawing?
see the Window styles and extended styles
Avatar of ronanm

ASKER

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!
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 ?
// 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 */ }
Did you override OnPaint()?
Avatar of ronanm

ASKER

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!
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 :)

Avatar of ronanm

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of timop
timop

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial