15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CListCtrl vs CListView

Gene Sewell -- genes@fast.net
Sunday, August 04, 1996

Hi all,

     Enviroment: VC++ 4.1 and Windows NT 3.51

I seem to have dug a hole for myself, and I'm hoping someone will be able to
point me to the way out....

I created a class "CCommonListView", derived from CListView, which
understand my database access methods, and could fill itself, support
clicks, etc.  I use this class, which is a view class, in quite a few parts
of my program.

Then, I decided I needed these smarts in a dialog box.  I decided to create
the dialog box with the dialog editor, placing a couple of CListCtrl objects
into the dialog.  I allowed the class wizard to generate a custom class for
the dialog, and then put two member variables of type "CCommonListView" into
the class description.  On WM_INITDIALOG, I subclassed the two CListCtrl
objects, and everything sort of worked.  

My first problem I discovered was that I got an assert during mouse
activation, in VIEWCORE:
  ASSERT(pParentFrame == pDesktopWnd || pDesktopWnd->IsChild(pParentFrame));

In my case, the pDesktopWnd is the dialog box, and pParentFrame is my main
frame window.

I also get a total crash on exit, when the framework does a 'delete this' at
the destruction of the view.

---
It finally dawned on me that the problem was that I was using a view where I
should have a window.  CListCtrl is derived from CWnd but CListView is
derived from CView.

What I think I want to do now is contruct a class derived from CListCtrl and
then somehow associate my CCommonListView class with this list control.
(There's a heck of a lot of code in CCommonListView!)

Can someone suggest an way to wire everything together?  At the end of all
of this, I would like one set of routines which understand all my database
stuff which I can use in both dialog boxes and MDI windows.  

Thanks

Gene
----
There are no facts, only interpretations.
	-- Friedrich Nietzsche
 




Terry Trippany -- terryt@str.com
Wednesday, August 07, 1996

Hi,

I'm not sure about the assert but I can suggest a way to tie all your database access together for 
all windows. It sounds to me like you have tied all your database access to a GUI widget. It would 
make more sense to separate the GUI from the data as much as possible. A better approach would be to 
create separate data manager object classes that provide services to the GUI on demand. These 
objects should not be mere containers of the data, they should provide services as well. The objects 
could be shared by many clients. There are many considerations here that do not pertain to MFC so it 
would be inappropriate to list them here. 

This approach necessitates a review of object modeling, I suggest Booch or Rumbaugh. There are many 
others as well. You can drop me some e-mail (terryt@str.com) if you would like more information.

CView is a direct descendant of CWnd by the way so you still have the CWnd methods available to you 
when you use the view.

Terry Trippany
"My opinion is just that"

*************************************
Terry Trippany
Senior Consultant
Strategic Technology Resources
Chicago, IL  

mailto:terryt@str.com
**************************************

Gene Sewell wrote:
> 
> Hi all,
> 
>      Enviroment: VC++ 4.1 and Windows NT 3.51
> 
> I seem to have dug a hole for myself, and I'm hoping someone will be able to
> point me to the way out....
> 
> I created a class "CCommonListView", derived from CListView, which
> understand my database access methods, and could fill itself, support
> clicks, etc.  I use this class, which is a view class, in quite a few parts
> of my program.
> 
> Then, I decided I needed these smarts in a dialog box.  I decided to create
> the dialog box with the dialog editor, placing a couple of CListCtrl objects
> into the dialog.  I allowed the class wizard to generate a custom class for
> the dialog, and then put two member variables of type "CCommonListView" into
> the class description.  On WM_INITDIALOG, I subclassed the two CListCtrl
> objects, and everything sort of worked.
> 
> My first problem I discovered was that I got an assert during mouse
> activation, in VIEWCORE:
>   ASSERT(pParentFrame == pDesktopWnd || pDesktopWnd->IsChild(pParentFrame));
> 
> In my case, the pDesktopWnd is the dialog box, and pParentFrame is my main
> frame window.
> 
> I also get a total crash on exit, when the framework does a 'delete this' at
> the destruction of the view.
> 
> ---
> It finally dawned on me that the problem was that I was using a view where I
> should have a window.  CListCtrl is derived from CWnd but CListView is
> derived from CView.
> 
> What I think I want to do now is contruct a class derived from CListCtrl and
> then somehow associate my CCommonListView class with this list control.
> (There's a heck of a lot of code in CCommonListView!)
> 
> Can someone suggest an way to wire everything together?  At the end of all
> of this, I would like one set of routines which understand all my database
> stuff which I can use in both dialog boxes and MDI windows.
> 
> Thanks
> 
> Gene
> ----
> There are no facts, only interpretations.
>         -- Friedrich Nietzsche
>




| Вернуться в корень Архива |