Solved

How to embed a CListCtrl into a CView in a Doc-View Arch

Posted on 2000-03-27
13
514 Views
Last Modified: 2013-11-20
Hi again....

I have a Doc-View architecture where a want to have a CListView as the child view, but I want to use a CListCtrl derived class because I want to manage some events and other functions of the CListCtrl embedded in the CListView class. It didn0t work, so I'm trying using CView instead of CListView and then to show my custom CListCtrl. This is my CView class:

int CVistaMarcas::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CView::OnCreate(lpCreateStruct) == -1)
            return -1;

      RECT rect;
      rect.bottom = rect.left = rect.right = rect.top = 0;
      m_ListaMarcas.Create(LVS_REPORT|LVS_AUTOARRANGE|LVS_SINGLESEL|LVS_NOSCROLL, rect, this, IDC_LISTAMARCAS);
      return 0;
}

void CVistaMarcas::OnSize(UINT nType, int cx, int cy)
{
      CView::OnSize(nType, cx, cy);
      
      CRect rect;
      GetWindowRect(&rect);
      m_ListaMarcas.MoveWindow(rect, FALSE);
      m_ListaMarcas.SetColumnWidth(0, 13*rect.Width()/100);
      m_ListaMarcas.SetColumnWidth(1, rect.Width()/5);
      m_ListaMarcas.SetColumnWidth(2, rect.Width()/5);
      m_ListaMarcas.SetColumnWidth(3, rect.Width()/5);
      m_ListaMarcas.SetColumnWidth(4, 27*rect.Width()/100);
}

void CVistaMarcas::OnInitialUpdate()
{
      CView::OnInitialUpdate();
      
      m_ListaMarcas.InsertColumn(0, "Nodo");
      m_ListaMarcas.InsertColumn(1, "Fecha");
      m_ListaMarcas.InsertColumn(2, "Hora");
      m_ListaMarcas.InsertColumn(3, "PIN");
      m_ListaMarcas.InsertColumn(4, "Movimiento");
}

void CVistaMarcas::OnSetFocus(CWnd* pOldWnd)
{
      CView::OnSetFocus(pOldWnd);
      
      m_ListaMarcas.SetFocus();      
}

Where m_ListaMarcas is my custom CListCtrl class.... How can I show m_ListaMarcas?

Thanks a lot in advance
Skel
0
Comment
Question by:skel
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
Hi,

After creating it, use

m_ListaMarcas.ShowWindow(SW_SHOW);

VinExpert
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
HI skel,

try to add WS_CHILD|WS_VISIBLE styles when creating...

ZOPPO
0
 

Author Comment

by:skel
Comment Utility
It didn't work.... neither m_ListaMarcas.ShowWindow(SW_SHOW) nor m_ListaMarcas.Create(LVS_REPORT|LVS_AUTOARRANGE|LVS_SINGLESEL|LVS_NOSCROLL|WS_CHILD|WS_VISIBLE, rect, this, IDC_LISTAMARCAS)

Do you suggest something else to test? are the other parameters correct? (rect, this and IDC_LISTAMARCAS)

Thanks
Skel
0
 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
Hi,

See here is the working code
In OnCreate(...)

m_cFileDetailsLV.Create(
            WS_VISIBLE | WS_CHILD | LVS_LIST | LVS_EDITLABELS |
                LVS_AUTOARRANGE | LVS_SHAREIMAGELISTS , // styles
            CRect(0,0,0,0),      // bounding rectangle,
            this, //parent
            ID_LISTVIEW); //id

In OnSize()

m_cFileDetailsLV.MoveWindow(0, 25, cx, cy);

And in OnInitialUpdate(...) I am also inserting the columns, And it is working fine. But, there is a list control object on the view which is placed using resource editor. I think U can try that way.

VinExpert
0
 
LVL 4

Expert Comment

by:captainkirk
Comment Utility
you might want to use CFormView instead of CView...
0
 

Accepted Solution

by:
mmg earned 100 total points
Comment Utility
CRect rect;
GetClientRect(&rect); //Set the control's initialize size

m_ListaMarcas.Create(WS_VISIBLE | WS_CHILD|LVS_REPORT|LVS_AUTOARRANGE|LVS_SINGLESEL|LVS_NOSCROLL, rect, this, IDC_LISTAMARCAS);
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:skel
Comment Utility
Hi... hmm.. it continue not working..... that CListCtrl isn't shown.... I'm wondering whether it is possible to display a CListCtrl in a CView... and I don't want to use CFormView instead because that way an ugly black frame is shown, or when I create the CFormView in resource editor at least..

In my case, I assigned to IDC_LISTAMARCAS a value of 1001 which isn't used by any other resource

Any further help will be greately appreciated


Skel
0
 

Author Comment

by:skel
Comment Utility
Is it necesary to use ShowWindow? In what method I have to place it?

Thanks
0
 
LVL 3

Expert Comment

by:SamHobbs
Comment Utility
It is certainly possible to use CListCtrl in a CView. Did my reply to your CodeGuru post help? As I said there, I have a program that puts a CListCtrl in a CView. Here is the relevant portion of my view's OnCreate:


      RECT Rect=CFrameWnd::rectDefault;
      DWORD dwStyle, dwCommonStyles=WS_CHILD|WS_VISIBLE|WS_BORDER;
if (CView::OnCreate(lpCreateStruct) == -1)
      return -1;
dwStyle = dwCommonStyles | LVS_REPORT | LVS_SORTASCENDING;
if (!m_Container.Create(dwStyle, Rect, this, IDC_FIELDS))
      return -1;


One thing that is important to uderstand is that a CListView is essentially a CListCtrl. If you look at the source MFC for CListView you will see that there is not much of it. Were you using CListView::GetListCtrl? Did you generate your application using AppWizard and with CListView specified for a view?

0
 
LVL 3

Expert Comment

by:SamHobbs
Comment Utility
I wish they woudl do something about the formatting of code in thsi web site. My code was formatted better before being mangled by this web site.
0
 

Author Comment

by:skel
Comment Utility
I have discovered the following.....

In the CVistaMarcas OnInitialUpdate I insert data to the CListCtrl and that data appears on the screen.... so the CListCtrl is there but the Column headers isn't displayed... do I have a missing style?

I'm using CView instead of CListView...

Thanks
Skel
0
 

Author Comment

by:skel
Comment Utility
My application is SDI and m_ListaMarcas is a CListCtrl derived class

Skel
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
Perhaps it would help if you add to the view's styles the WS_CLIPCHILDREN style...
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

6 Experts available now in Live!

Get 1:1 Help Now