المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Setting the item count for a CListBox 'No Data' control



C++ Programming
08-26-2009, 08:05 PM
Hi All,

My target platform is Windows Mobile 6.5.

I've created a 'virtual' CListBox with the styles LBS_NODATA, LBS_OWNERDRAWFIXED set and styles LBS_SORT, LBS_HASSTRINGS unset. I have a vector of 'owner data' and have implemented the DrawItem() function for the owner draw side.

My problem comes when trying to set the count of items that are in the 'virtual' CListBox.

SendMessage() for LB_SETCOUNT does not return an error yet neither does it actually modify the CListBox's count. I am able to force the count to increase via iterating AddString(NULL) for the number of items in the list, but that breaks the whole concept of a 'virtual' list.

I'm after the *****alent of CListCtrl's SetItemCountEx().


#define LB_SETCOUNT 0x1A7

BOOL CTestDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_data.reserve(5000);

for (int i=0;i < 5000; ++i)
{
CString fmt;
fmt.Format(L"Item %04d",i);
m_data.push_back(fmt);

/* This will force m_listbox.GetCount() to the correct number but results in the huge lag which I
* am trying to avoid by being 'no data' and 'owner draw'.
*
* m_listbox.AddString(NULL);
*/
}

LRESULT result;
result = m_listbox.SendMessage(LB_SETCOUNT,
(WPARAM)(int)5000,
(LPARAM)0);

int cnt = m_listbox.GetCount();

m_listbox.SetItemHeight(0, 25);

m_listbox.Invalidate();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}