Solved

CListView with a derived CListCtrl

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 196
unix example issues 18 99
Problem to open Excel file 15 178
Bartender label printing - switch on and off graphics 3 54
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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