WTL, wtlmfc

Source: Internet
Author: User

WTL, wtlmfc

When the average CListCtrl value exceeds 10000, it is difficult to drag the scroll bar ..

Virtual List Controls, Virtual List, I think it is a List display method ..

Normal list: All list data is loaded and displayed.

Virtual list: load only the data to be displayed. (when you receive the LVN_GETDISPINFO message, the list is refreshed and only the part to be displayed is refreshed ).

Obviously, when there is a large amount of data, who is the best ..

Compared with MFC, I prefer lightweight WTL. Let's use WTL as an example ..

1. Create a WTL project:


2. Drag out the List Control:

I set its ID to IDC_LIST_LOVE, View to Report, and Owner Data to True.


3. Use CListViewCtrl of WTL to associate the list IDC_LIST_LOVE and insert the column:

I have set a member variable m_lvcLove for CListViewCtrl.

// Set virtual listm_lvcLove.Attach (GetDlgItem (IDC_LIST_LOVE); m_lvcLove.AddColumn (_ T ("Vows"), 0); m_lvcLove.AddColumn (_ T ("previous events"), 1 );

4. Associate LVN_GETDISPINFO message, list ID, and response function in the message macro:

NOTIFY_HANDLER(IDC_LIST_LOVE, LVN_GETDISPINFO, OnGetDispInfo)

5. Complete the response function:

Here pItem is the cell of the list control. If you want to display the cells in the list, you can perform operations on pItem and how pItem is displayed on the list, it is not written in the code.

PItem-> mask is the identifier of the displayed content, specifying the icon, text, or other

PItem-> iItem is the row number of the List Control (starting from 0)

PItem-> iSubItem is the column number of the List Control (starting from 0)

LRESULT CMainDlg::OnGetDispInfo(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/){NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pnmh);LV_ITEM* pItem = &(pDispInfo)->item;int nItem = pItem->iItem;if (pItem->mask & LVIF_TEXT) //valid text buffer?{switch (pItem->iSubItem){case 0: //fill in main textlstrcpy(pItem->pszText, m_vtLove[nItem].strSaying);break;case 1: //fill in sub item 1 textlstrcpy(pItem->pszText, m_vtLove[nItem].strHistory);break;}}return 0;}

6. Actively Trigger List Update (SetItemCount is critical, which triggers LVN_GETDISPINFO messages ):

I used the Add Data button to Add 1000 pieces of Data each time.

LRESULT CMainDlg::OnAddData(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/){int nBase = m_vtLove.size();for (int i = 0; i < ADD_COUNT_ONE_TIME; ++i){CString strHistory;strHistory.Format(_T("%d days"), nBase + i);m_vtLove.push_back(LOVEITEM(_T("I love you"), strHistory));}m_lvcLove.SetItemCount(m_vtLove.size());return 0;}

7. Check the effect:

I clicked 10 times, added 10000 pieces of data, and pulled the scroll bar randomly. It was not stuck at all ..


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.