?
Solved

CListView with a derived CListCtrl

Posted on 2004-09-24
5
Medium Priority
?
536 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 200 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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