Solved

CListCtrl::DrawItem not called

Posted on 1998-06-16
10
2,280 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

8 Experts available now in Live!

Get 1:1 Help Now