Solved

CListView with a derived CListCtrl

Posted on 2004-09-24
5
504 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
  • 2
5 Comments
 
LVL 55

Expert Comment

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

Author Comment

by:Catalepsy
Comment Utility
  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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now