Victor
Victor

Reputation: 14632

Create a ListView in MFC without having dialogs

I am trying to create a ListView in MFC C++ in my Child window. I have just finished reading this article on CodeProject. I recommend it to anyone who wants to create the control in a dialog or that has created it already and tries to learn more about it.

Here comes my question! I have to create the ListView control at ::OnCreate() of my ChildWindow. How can I do this?

Here is what I've tried so far:

int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    CListCtrl *CarsListView = new CListCtrl();
    CarsListView->SetView(LVS_REPORT);
    CarsListView->ShowWindow(SW_SHOW);

    return 0;
}

(code that is obviously not working...)

Upvotes: 0

Views: 895

Answers (1)

xMRi
xMRi

Reputation: 15375

  1. There is no Need to use new to create a list view object.
  2. Creating the object doesn't create the window. You Need to call CListView::Create

Maybe you should read a MFC tutorial...

Upvotes: 2

Related Questions