-
December 15th, 2009, 05:31 PM
#1
Overriding CListCtrl in CListView
I have my own CListCtrl class and want to use it in my CListView derived class. What is best way to do this? Thanks in advance.
-
December 15th, 2009, 07:39 PM
#2
Re: Overriding CListCtrl in CListView
Instead of a CListView view, why not use a CFormView view, put your control in it and size the control to the CFormView?
-
December 15th, 2009, 08:05 PM
#3
Re: Overriding CListCtrl in CListView
Instead of a CListView view, why not use a CFormView view, put your control in it and size the control to the CFormView?
Who said anything about size ?
What is best way to do this?
Like you derive any other class.
-
December 15th, 2009, 10:00 PM
#4
Re: Overriding CListCtrl in CListView
Originally Posted by Arjay
Instead of a CListView view, why not use a CFormView view, put your control in it and size the control to the CFormView?
Originally when I posted a problem I was having I had a CMDIChildWnd that just contained a CListCtrl inside and everyone said to use CListView so that's what I'm attempting now. I guess since everyone told me to do it this way on here originally that's why I did it this way. If I was just going to use CFormView and resize it I may as well keep my original code that resized it to the CMDIChildWnd cause it worked. Although using CFormView may be better than just putting it in the CMDIChildWnd since it follows the doc/view model better.
Basic answer I guess cause people on here told me to use CListView.
Originally Posted by Skizmo
Who said anything about size ?
Like you derive any other class.
Yeah but I want to derive from the CListCtrl that is in the CListView. Do I use SubclassWindow()? I already have the CListCtrl class done and it works just want to use that in my CListView class. Thanks both of you and eager to hear more before I move forward.
-
December 15th, 2009, 10:51 PM
#5
Re: Overriding CListCtrl in CListView
Originally Posted by Skizmo
Who said anything about size ?
Presumably the OP would want the CListCtrl to resize when the view resized, right?
-
December 16th, 2009, 01:52 AM
#6
Re: Overriding CListCtrl in CListView
Or may be the following...
OP might be a little confused over the functionality provided by CListView class and CListCtrl.
Here is some detailed explanation, and if wrong please correct me...
Using CListCtrl in a CFormView and sizing it with the parent container that is the CFormView dervied class is one approach. In this, all the notifications to the list control and its items would be send through the CFormView which happens to be the parent. Any interaction with the document class and its variables, has to be via CFormView derived class. Contrarily, CListView is an independent View class, that directly interacts with the document class. So the notifications can be sent directly to the underlying listctrl object and class level interaction with document class members is possible via document class pointer.
CListCtrl is inherited from CWnd class where as CListView is derived from CCtrlView. The view word here makes the difference and emphasizes that the class holds the data to be displayed in a view in an SDI / MDI application.
CListCtrl is instantiated and directly can access its items and sub items. A CListView gets a reference to the control object which is a List Control and Invalidates the view or the document data using this control.
Last time I worked with both of them was in VS 2005. If I am not wrong, both approaches above would offer you similar functionality if you can work around them. I am not sure, but some of the styles present in the CListCtrl class are not available to CListView. Some notification handlers are different, update functions are different and most importantly paint intervals and device contexts are different.
Again, as I said, this is what I have known so far....and hope that helps
Regards,
Bhushan
-
December 17th, 2009, 08:22 AM
#7
Re: Overriding CListCtrl in CListView
Have a look at how MFC 'transformed' a CListCtrl into a CListView
then use the same principle to transform your CMyListCtrl into a CMyListView.
the same principle can be applied to turn any control type into a view type (with some reservations).
-
December 17th, 2009, 03:14 PM
#8
Re: Overriding CListCtrl in CListView
Will look into that. Time to pull out the MFC Internals book and go through MFC code as well. Thanks.
-
December 17th, 2009, 04:36 PM
#9
Re: Overriding CListCtrl in CListView
Originally Posted by left1none
Originally when I posted a problem I was having I had a CMDIChildWnd that just contained a CListCtrl inside and everyone said to use CListView so that's what I'm attempting now. I guess since everyone told me to do it this way on here originally that's why I did it this way. If I was just going to use CFormView and resize it I may as well keep my original code that resized it to the CMDIChildWnd cause it worked. Although using CFormView may be better than just putting it in the CMDIChildWnd since it follows the doc/view model better.
It may have sort of looked like it worked, but if you want to take full advantage of the doc/view architecture, you should use some kind of view class. CMDIChildWnd has a specific purpose as do views and it's best not to mix them up. If you don't need doc/view, perhaps a dialog based app would be more appropriate.
-
December 17th, 2009, 05:31 PM
#10
Re: Overriding CListCtrl in CListView
Originally Posted by OReubens
Have a look at how MFC 'transformed' a CListCtrl into a CListView
then use the same principle to transform your CMyListCtrl into a CMyListView.
the same principle can be applied to turn any control type into a view type (with some reservations).
Ok looked into it and it seems easy enough but what do I put for WC_LISTVIEW. I mean I don't know my CListCtrl derived window class name.
Code:
_AFXCVIEW_INLINE CListView::CListView()
: CCtrlView(WC_LISTVIEW, AFX_WS_DEFAULT_VIEW)
{ }
-
December 18th, 2009, 05:02 AM
#11
Re: Overriding CListCtrl in CListView
Originally Posted by left1none
I don't know my CListCtrl derived window class name.
The class name of a derived class is the same as the base class.
Victor Nijegorodov
-
December 18th, 2009, 02:00 PM
#12
Re: Overriding CListCtrl in CListView
Originally Posted by VictorN
The class name of a derived class is the same as the base class.
I came to the same conclusion because I called AfxMessageBox() to display the classname in my custom CListCtrl and it came up as "SysListView" which I knew was the CListCtrl in MFC.
So if I use that for a class name then how do I make sure when I derive from CCtrlView that it uses my CListCtrl derived class instead of the standard CListCtrl? I'm guessing it's this line
Code:
_AFXCVIEW_INLINE CListCtrl& CListView::GetListCtrl() const
{ return *(CListCtrl*)this; }
But I don't see where CCtrlView calls this method anywhere in the MFC source code.
So are you saying to just override CCtrlView, pass "WC_LISTVIEW" in the constructor and just override GetListCtrl to return my CEnhancedListCtrl and it'll use my CListCtrl in my derived view?
-
December 18th, 2009, 02:45 PM
#13
Re: Overriding CListCtrl in CListView
Actually just tried what I mentioned in previous post and it just created a CListView not with my derived class. hmmmm.
Jack
-
December 18th, 2009, 02:55 PM
#14
Re: Overriding CListCtrl in CListView
I would still love to know how to do this but I found a work around. I took out all my OnCustomDraw() and OnEraseBkgd() code out and put it in my CListView and it works. But if anyone figures out how to turn a custom control class into a view I would love to figure that out for the future. Thanks.
-
December 21st, 2009, 04:13 AM
#15
Re: Overriding CListCtrl in CListView
Originally Posted by left1none
I came to the same conclusion because I called AfxMessageBox() to display the classname in my custom CListCtrl and it came up as "SysListView" which I knew was the CListCtrl in MFC.
So if I use that for a class name then how do I make sure when I derive from CCtrlView that it uses my CListCtrl derived class instead of the standard CListCtrl? I'm guessing it's this line
Code:
_AFXCVIEW_INLINE CListCtrl& CListView::GetListCtrl() const
{ return *(CListCtrl*)this; }
Exactly!
So if your derivred class were called CMyListCtrl then this GetListCtrl() method should look like:
Code:
_AFXCVIEW_INLINE CMyListCtrl& CListView::GetListCtrl() const
{ return *(CMyListCtrl*)this; }
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|