[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 941
  • Last Modified:

CHeaderCtrl

I would like to use a header in my CScrollView.  First, I derived a class from CHeaderCtrl, and
overrided the CHeaderCtrl::DrawItem.  Then I in my view class, I declared an object of
that derived class called "header:"  In my view's OnInitialUpdate, I make the following
calls:

int status = header.Create(HDS_HORZ | CCS_TOP | WS_VISIBLE, rect, CWnd::GetParent(), 1);
HD_ITEM hd;
hd.pszText = "Item #";
hd.cchTextMax = 7;
hd.mask = HDI_TEXT;
HD_ITEM *hd_ptr = &hd;
header.InsertItem(0, hd_ptr);
DRAWITEMSTRUCT ds;
ds.itemAction = ODA_DRAWENTIRE;
DRAWITEMSTRUCT *d_ptr = &ds;
header.DrawItem(d_ptr);

Yet, all I get in the view is a grey rectangle.  What do I need to put in my override of the
DrawItem function to make this work? If this is not the problem, then what is?

Thanks in Advance!!
0
mulshine
Asked:
mulshine
  • 2
1 Solution
 
chensuCommented:
CWnd::GetParent() returns the parent window of the view. You should use this. You also need to apply WS_CHILD style.

int status = header.Create(HDS_HORZ | CCS_TOP | WS_VISIBLE | WS_CHILD, rect, this, 1);

You should have the fmt member set to the HDF_OWNERDRAW value.
hd.fmt = HDF_OWNERDRAW;

And DrawItem() will be called by the framework. You should not call it. You just override it and do what you want to do.
0
 
chensuCommented:
hd.mask = HDI_TEXT | HDI_FORMAT;
hd.fmt = HDF_OWNERDRAW | HDF_STRING;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now