Owner-draw headers for a CListCtrl-derived class?
Peter Drayton -- peter@ten.net
Wednesday, October 16, 1996
Environment: VC++4.2, Win 95
I want to create an owner-draw multi-column list control. I have created a
CListCtrl-derived class (CListCtrlEx) that allows me to easily override the
text color, background color, etc. I have two problems/issues that I have
not yet resolved and would really appreciate some pointers:
1) How do I override the header control to make it also owner-draw? I want
to alter the font and background color and (optionally) add icons to the
headers.
2) I want to make it as brain-dead as possible to use my new class. My
original approach was to have the user add a ListView control to the dialog
resource and then add a member variable of type CListCtrl to the dialog
using ClassWizard. The member definition in the dialog header file is then
changed from declaring a CListCtrl to a CListCtrlEx variable. The downside
of this is that when the Windows control is first dynamically subclassed by
the MFC call to DDX_Control in DoDataExchange() the Windows control is
already created. What I really wanted to do is override something like
PreCreateWindow to make sure that the correct style flags are set for the
control (force it to Report mode and Owner-draw). I know that this works
for a CListView-derived class as PreCreateWindow is called for
CView-derived classes. How can I do this with a CListCtrl-derived class?
TIA
Regards,
Peter Drayton
Jim Barry -- Jim.Barry@ilp.com
Friday, October 18, 1996
[Mini-digest: 4 responses]
On 16 October 1996 23:26, Peter Drayton[SMTP:peter@ten.net] wrote:
> Environment: VC++4.2, Win 95
>
> I want to create an owner-draw multi-column list control. I have
created a
> CListCtrl-derived class (CListCtrlEx) that allows me to easily override
the
> text color, background color, etc. I have two problems/issues that I
have
> not yet resolved and would really appreciate some pointers:
>
> 1) How do I override the header control to make it also owner-draw? I
want
> to alter the font and background color and (optionally) add icons to
the
> headers.
>
> 2) I want to make it as brain-dead as possible to use my new class. My
> original approach was to have the user add a ListView control to the
dialog
> resource and then add a member variable of type CListCtrl to the dialog
> using ClassWizard. The member definition in the dialog header file is
then
> changed from declaring a CListCtrl to a CListCtrlEx variable. The
downside
> of this is that when the Windows control is first dynamically
subclassed by
> the MFC call to DDX_Control in DoDataExchange() the Windows control is
> already created. What I really wanted to do is override something like
> PreCreateWindow to make sure that the correct style flags are set for
the
> control (force it to Report mode and Owner-draw). I know that this
works
> for a CListView-derived class as PreCreateWindow is called for
> CView-derived classes. How can I do this with a CListCtrl-derived
class?
Don't know about number one, but I just had a similar problem with number
two. There is a virtual function called PreSubclassWindow which gets
called just before the control is subclassed by DDX_Control. Voila!
Cheers,
- Jim
-----From: Si Cruse
>From the method you describe here PreCreateWindow will not be called as you are
effectively subclassing the window. You need to use PreSubclassWindow!
--
...A closed mouth gathers no foot...
_____________________________________________________________
Si Cruse
Front Office IT Development, Credit Suisse Financial Products
1 Cabot Square, London E14 4QJ
Phone: +44 171 516 2948 Fax: +44 171 516 2688
mailto:scruse@csfp.co.uk http://www.cruse.demon.co.uk
-----From: cugr1@gd.swissptt.ch (Cunningham Graham, IT34)
You could do a couple of things to modify the style of the list control. =
=
In your OnInitDialog you could use ModifyStyle() ModifyStyleEx() on the =
list control. Or the other way is to override the Create for the control.
To get the pointer to the header control I would simply use =
GetNextWindow(). Note I havent actually done this so it might not be the =
right way to go.
-----From: "Randy Taylor"
Environment VC4.2, MFC 4.2
> From: Peter Drayton
> 1) How do I override the header control to make it also owner-draw? I
want
> to alter the font and background color and (optionally) add icons to the
> headers.
Derive a class from CHeaderCtrl.
Add a hander for the WM_DRAWITEM message your CHeaderCtrl derivative.
The ID of the Header when the list is in LVS_REPORT mode is zero,
so use MyListCtrl::GetDlgItem(0) to get the header window.
Call MyHeader.SubclassWindow() from a function called
MyListCtrl::RegisterHeader()
when you know that the listview is in LVS_REPORT mode.
> 2) I want to make it as brain-dead as possible to use my new class. My
> original approach was to have the user add a ListView control to the
dialog
> resource and then add a member variable of type CListCtrl to the dialog
> using ClassWizard. The member definition in the dialog header file is
then
> changed from declaring a CListCtrl to a CListCtrlEx variable. The
downside
> of this is that when the Windows control is first dynamically subclassed
by
> the MFC call to DDX_Control in DoDataExchange() the Windows control is
> already created. What I really wanted to do is override something like
> PreCreateWindow to make sure that the correct style flags are set for the
> control (force it to Report mode and Owner-draw). I know that this works
> for a CListView-derived class as PreCreateWindow is called for
> CView-derived classes. How can I do this with a CListCtrl-derived class?
Use PreCreateWindow, just like before.
randy_taylor@ebt.com
| Вернуться в корень Архива
|