Listbox Control

Hi,

I'm using MFC. I have a Listbox to display any updated info from a process.
I want to have a function to call and add/update the entry in the Listbox (IDC_LIST1)

void UpdateListBox(CString Str1, CString Str2, CString3)
{

// How can I include the m_ListBox Control here in this function, in order to use AddString(..)
// Or you have better approach ?
}

Thanks. :rolleyes:
[441 byte] By [Dimension] at [2007-11-19 6:41:19]
# 1 Re: Listbox Control
Make UpdateListBox() member of the class that contains m_ListBox.
Or make it a friend function of the class that contains m_ListBox.
Or pass the reference of m_ListBox to UpdateListBox().
Ejaz at 2007-11-11 0:30:14 >
# 2 Re: Listbox Control
I would prefer: pass the reference of m_ListBox to UpdateListBox().

Can you show me how to do it ?
Dimension at 2007-11-11 0:31:14 >
# 3 Re: Listbox Control
Okie, as you prefer.

void UpdateListBox(const CString& Str1, const CString& Str2, const CString3& , CListBox& lbx)
{
// Any processing required, goes here

// Update the list box
lbx.AddString( str1 );
lbx.AddString( str2 );
lbx.AddString( str3 );
}


Furthermore, although its off-topic, but its better to pass objects as constant reference (if you just want to read them), so that you can save multiple object creation and destruction overhead. I guess this was also discussed in FAQs, do have a look at it.
Ejaz at 2007-11-11 0:32:14 >
# 4 Re: Listbox Control
Thanks you.

One more thing, Where can I change the:
- Listbox Background Color
- Listbox Text Font Color
- Listbox Text Font

Regards.
Dimension at 2007-11-11 0:33:23 >
# 5 Re: Listbox Control
Take a look at CListBox ( http://www.dev-archive.com/Cpp/controls/listbox/) section, its full of such stuff. Also, have a look at CListBox Changing Font and Colors ( http://www.codersource.net/mfc_clistbox_font.html) for basic introduction.
Ejaz at 2007-11-11 0:34:22 >
# 6 Re: Listbox Control
I still not too sure.
I would like to set my Listbox Bg Color, Text Font and Text Color during application launched, during Initialization I mean.

is it doing it in OnInitDialog function ?
m_ListBox.SetTextColor(...)
m_ListBox.SetTextFont(...)
m_ListBox.SetBKColor(...)

?
Dimension at 2007-11-11 0:35:24 >
# 7 Re: Listbox Control
My Listbox is Vertica Stroll.

How many entry maximum can it hold ? How can I control that by using counter..so that It will not reach a VERY maximum entries ?
Dimension at 2007-11-11 0:36:19 >
# 8 Re: Listbox Control
Did you look at the links above? They have everything that you need to know about colouring :) About the maximum limit, although the number of items is restricted, the total size of the items in a list box is limited only by available memory. At win95/98, its 32,767 items. For details, have a look at CListBox::InitStorage (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_clistbox.3a3a.initstorage.asp)
Ejaz at 2007-11-11 0:37:22 >
# 9 Re: Listbox Control
Hi,

From the listbox, I want to double click any entry, and will pop up a window with the details. How can I remember the old entry ? Do u have any good example?

Thanks.
Dimension at 2007-11-11 0:38:22 >
# 10 Re: Listbox Control
In the LBN_DBLCLK message handler, use the equivalent of the following.

void CMyDialog::OnDblclkList()
{
// TODO: Add your control notification handler code here

int nIndex = m_list.GetCurSel();

if (LB_ERR != nIndex)
{
CString strText;
m_list.GetText( nIndex , strText );
AfxMessageBox( strText );
}
}
Ejaz at 2007-11-11 0:39:23 >