Virtaul listview?

Dear All,

I know a control item which is called virtual listview is existed and I have read the article posted at the online library at microsoft.

My operating system is Window 98, the version of the following files

comctl32.dll is 4.72.3110.1
shell32.dll is 4.72.3110.6
shlwapi.dll is 4.72.3110.0

Also, I am using the professional edition of VC5.0 to develop my application.

How can I develop a virtual listview under this environment?
My project's view class is CFormView. I haev tried to add a listview at the resource editor but it doesn't contain the property LVS_OWNERDATA...Also, I cannot use the function SetItemCountEx(..).

Thanks!!!
hon67Asked:
Who is Participating?
 
pau_serraConnect With a Mentor Commented:
What version of Visual C++ do you have?
If you have Visual C++ 6.0 SP2 CListCtrl::SetItemCountEx will work, if not, you must use the following:

ListCtrl.SendMessage(LVM_SETITEMCOUNT, (WPARAM) NumOfItems, (LPARAM)/*LVSICF_NOINVALIDATEALL*/0);

If you are coding a CListView derived view, all you have to do is the following:

In the CMyListView::PreCreateWindow:

BOOL CMyListView::PreCreateWindow(CREATESTRUCT& cs)
{
      cs.style&=~LVS_TYPEMASK;
      cs.style = cs.style | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA;

      return CListView::PreCreateWindow(cs);
}

in the CMyListView::OnInitialUpdate, set the extended styles and the number of items:

void CMyListView::OnInitialUpdate()
{
      MyDoc* pDoc = GetDocument();

      CListView::OnInitialUpdate();

      if (!pDoc)
            return;

      CListCtrl& ListCtrl=GetListCtrl();

// first of all, create the columns
      ListCtrl.InsertColumn( 0, "Column #1", LVCFMT_LEFT, 250, 0 );
      ListCtrl.InsertColumn( 1, "Column #2", LVCFMT_LEFT, 250, 1 );

// Here your extended styles:
      DWORD dwExStyle = LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES | LVS_EX_SUBITEMIMAGES | LVS_EX_INFOTIP;
      ListCtrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LPARAM(dwExStyle));      

// and now, the number of itmes:
      // ListCtrl.SetItemCountEx( 0, /*LVSICF_NOINVALIDATEALL*/0 );
      ListCtrl.SendMessage(LVM_SETITEMCOUNT, (WPARAM) pDoc->GetNumOfItems(), (LPARAM)/*LVSICF_NOINVALIDATEALL*/0);
}

And finally define the reflected message LVN_GETDISPINFO. You can do this with VC++ with class wizard, if u have a previous version, try this:
in .h add:

      afx_msg void OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult);

in the protected block.

in .cpp add:
      ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetdispinfo)
in the message map,
and
      void CMyListView::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
      {
            LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
            // TODO: Add your control notification handler code here
            
            *pResult = 0;
      }
in the bottom of file

CMyListView::OnGetdispinfo if called for every column of every item when it has to be painted. The code for this function may look like this:

void CMyListView::OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult)
{
      LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;

      if ( pDispInfo->item.mask & LVIF_TEXT )
      {
            switch (pDispInfo->item.iSubItem)
            {
                  case 0:
                        _snprintf(pDispInfo->item.pszText, pDispInfo->item.cchTextMax, "Item %i", pDispInfo->item.iItem);
                        break;
                  default:
                        _snprintf(pDispInfo->item.pszText, pDispInfo->item.cchTextMax, "Item %i Col %i", pDispInfo->item.iItem, pDispInfo->item.iSubItem);
                        break;
            }
      }

      *pResult = 0;
}


that's all.

0
 
hon67Author Commented:
Dear pau_serra,

My project's view class is CFormView. How can I modify your code to implment the same thing?

At the function PreCrateWindow, I have tried to modify the following code from:

cs.style&=~LVS_TYPEMASK;
cs.style = cs.style | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_OWNERDATA;

to
CListCtrl m_list1;
DWORD ListStyle = LVS_REPORT;
m_list1.ModifyStyle(ListStyle,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_OWNERDATA,0);

and put this in the OnInitialUpdate(..) Function.

Others are same, however, I get an debug assertion error.......

How can I modify your code?

Thanks!!!
0
 
pau_serraCommented:
Ok hon67, here are the answer:

First of all, put a listctr in the dialog temaplate with ResourceEditor, and set onwer data in the 'more styles' tab.

(note from MS: Note Dynamically switching to and from the LVS_OWNERDATA style is not supported.)

Bind the resource with a CListCtrl using ClassWizard.

And all other is equal.

bye,

0
 
hon67Author Commented:
Hi pau_serra,

As I am using professional version of VC++5.0, there is no this option (LVS_OWNERDATA) at the more styles property page of the listview.

Is this mean that I cannot build a virtual listview in placing a listctrl from the resource editor?

Thanks!!!
0
 
pau_serraCommented:
Try this:

In the .rc file, search for the list control,  may look like this:

    CONTROL         "List1",IDC_LISTCTRL,"SysListView32", WS_BORDER | WS_TABSTOP,20,20,200,65

and set LVS_OWNERDATA manually:

    CONTROL         "List1",IDC_LISTCTRL,"SysListView32", LVS_OWNERDATA | WS_BORDER | WS_TABSTOP,20,20,200,65

Bye!
0
All Courses

From novice to tech pro — start learning today.