• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

CListView with my CListCtrl object

I have a class derived from CListView and I want the embedded CListCtrl object to be of my own class derived from CListCtrl. How can I accomplish this?
0
MFCRich
Asked:
MFCRich
1 Solution
 
peterchen092700Commented:
You can't directly replace the List Control.

The safe way would be to create your own View class, and create the custom list control as child window of it.
(For some issues with this, see http://buerger.metropolis.de/bitbucket/howto/wndview.html, and sorry for the popup)


Reasons:
MFC does very dirty tricks here. It relies solely on the fact that bol CListCtrl and CListView inherit from CWnd, and that CListCtrl does not have more data members than CWnd, and the List Control does not override any method of CWnd except perhaps message handlers.

CListView::GetListCtrl() actually returns a reference to the CListView itself, cast to CListCtrl.
(be aware that there's no safe cast beetween them, and MFC heavily relies on implementational details of the classes here, and the code would break with "weird but ANSI-compliant" compilers).

Another option would be to dereive your own CMyListView class from CCtrlView, but you would have to find a way to register a Window Class (Win32) and tell MFC to associate it with your CMyListCtrl class - which I don't know how to do...

Peter
0
 
shilpa_JbCommented:
Hi,
U can have ur own view class derived from the CView and oncreate of this class create the ur own CListControl which is derive from CListCtrl.
that should help u.
For more help see for listcontrol examples under shell programming or under listcontrol section in www.codeguru.com.
-shilpa  
0
 
peterchen092700Commented:
shilpa_Jb: Isn't this exactly what I described in greater detail?

Peter puzzled
0
 
MRNMurthyCommented:
Hi,

I want some time.

From

MRN Murthy
0
 
MFCRichAuthor Commented:
I'm trying peterchen's suggestion so time may be short :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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