Solved

CListView with a derived CListCtrl

Posted on 2004-09-24
5
524 Views
Last Modified: 2013-11-20
Hello all:

   I've created a CListCtrl derived class that has a lot of functionality.  Now I find myself in a situation where it would be handy to use a CListView but I don't want to lose all of what I programmed for the CListCtrl, is there a way to tell the CListView what its list control is?  The end result should be a CListView that is using my personal CListCtrl.

Thanks,
0
Comment
Question by:Catalepsy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12147014
Use a CView object and put CYourListCtrl as a member.
0
 
LVL 3

Author Comment

by:Catalepsy
ID: 12147116
  I'm trying to avoid that.  Although I've created the CView and was doing it that way before, I would prefer to use a CListView and tell it the CListCtrl it owns.

Thanks
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 50 total points
ID: 12147606
You can't do it because every function (just a few) in CListView refers to a CListCtrl object without any extra functionlity, so maybe your special event may be disabled.
But  you can try to make your own CMyListView, no need a big code.
Take a look to Microsoft CListView implementation:

#define WC_LISTVIEW             "SysListView"

_AFXCVIEW_INLINE CListView::CListView() : CCtrlView(WC_LISTVIEW, AFX_WS_DEFAULT_VIEW)
      { }
_AFXCVIEW_INLINE CListCtrl& CListView::GetListCtrl() const
                { return *(CListCtrl*)this; }

BEGIN_MESSAGE_MAP(CListView, CCtrlView)
      //{{AFX_MSG_MAP(CListView)
      ON_WM_NCDESTROY()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CListView::PreCreateWindow(CREATESTRUCT& cs)
{
      return CCtrlView::PreCreateWindow(cs);
}

void CListView::DrawItem(LPDRAWITEMSTRUCT)
{
      ASSERT(FALSE);
}

BOOL CListView::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam,
      LRESULT* pResult)
{
      if (message != WM_DRAWITEM)
            return CCtrlView::OnChildNotify(message, wParam, lParam, pResult);

      ASSERT(pResult == NULL);       // no return value expected
      UNUSED(pResult); // unused in release builds

      DrawItem((LPDRAWITEMSTRUCT)lParam);
      return TRUE;
}

void CListView::RemoveImageList(int nImageList)
{
      HIMAGELIST h = (HIMAGELIST)SendMessage(LVM_GETIMAGELIST,
            (WPARAM)nImageList);
      if (CImageList::FromHandlePermanent(h) != NULL)
            SendMessage(LVM_SETIMAGELIST, (WPARAM)nImageList, NULL);
}

void CListView::OnNcDestroy()
{
      RemoveImageList(LVSIL_NORMAL);
      RemoveImageList(LVSIL_SMALL);
      RemoveImageList(LVSIL_STATE);

      CCtrlView::OnNcDestroy();
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question