Solved

CListView with a derived CListCtrl

Posted on 2004-09-24
5
512 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 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