Solved

CListCtrl::DrawItem not called

Posted on 1998-06-16
10
2,306 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

11 Experts available now in Live!

Get 1:1 Help Now