Improve company productivity with a Business Account.Sign Up

x
?
Solved

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

Posted on 2000-03-27
13
Medium Priority
?
586 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:Vinayak Kumbar
ID: 2660526
Hi,

After creating it, use

m_ListaMarcas.ShowWindow(SW_SHOW);

VinExpert
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2660576
HI skel,

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

ZOPPO
0
 

Author Comment

by:skel
ID: 2662334
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2662715
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
ID: 2665048
you might want to use CFormView instead of CView...
0
 

Accepted Solution

by:
mmg earned 300 total points
ID: 2667969
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
 

Author Comment

by:skel
ID: 2668927
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
ID: 2668936
Is it necesary to use ShowWindow? In what method I have to place it?

Thanks
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2675784
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
ID: 2675785
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
ID: 2675894
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
ID: 2675910
My application is SDI and m_ListaMarcas is a CListCtrl derived class

Skel
0
 
LVL 31

Expert Comment

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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…

608 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