Tips for using clistbox & cchecklistbox

Source: Internet
Author: User

Introduction to clistbox and cchecklistbox
Clistbox
Used to output a series of texts, each of which occupies one line.

Cchecklistbox
Cchecklistbox is derived from clistbox and has all functions of clistbox. The only difference from clistbox is that a check box is added before each line ). To use cchecklistbox, you must go to the resource view (resourceview ).
(1) style-> owner draw-> select fixed
(2) Select has strings
(3) add member variables
Method 1: Use the Class Wizard (classwizard) to add the member variable clistbox m_listbox; and then manually change it to cchecklistbox m_listbox;
Method 2: Use the subclassdlgitem or subclasswindow function to subclass the control.
Cchecklistbox m_checklistbox;
M_checklistbox.subclassdlgitem (idc_listbox1, this );

--------------------------------------------------------------------------------

1. ListBox styles Introduction

In the styles of ListBox, there are four options: single, multiple, extended and none.

Single: allows you to select an item each time.
Multiple: multiple items can be selected at a time.
Extended: you can press shift/CTRL to select multiple rows.
None: select an item without highlighting it. Only the focus of this item is displayed (the item has a rectangle box ).

 

--------------------------------------------------------------------------------

2. Change the style of ListBox at runtime

The style cannot be changed during running. Only the original style can be destroyed, and a new ListBox can be created. Alternatively, you can create two listboxes to hide one of them.

--------------------------------------------------------------------------------

3. Set the horizontal scroll bar of ListBox
Int dx = 0;
Csize SZ;
CDC * PDC = m_listbox.getdc ();
Cstring STR;
For (Int J = 0; j <m_listbox.getcount (); j ++)
{
M_listbox.gettext (J, STR );
SZ = PDC-> gettextextent (STR );

If (SZ. CX> dx)
DX = Sz. CX;
}

M_listbox.releasedc (PDC );
M_listbox.sethorizontalextent (dx );

 

--------------------------------------------------------------------------------

4. Import all files and directories in the folder to ListBox

Tchar szpath [max_path] = {"C ://"};
Int nreslt = dlgdirlist (szpath, idc_listbox1, 0,
Ddl_readwrite | ddl_readonly |
Ddl_system | ddl_archive | ddl_directory );

 

--------------------------------------------------------------------------------

5. When data is added to the ListBox, it is automatically rolled to the end.
// Automatically scroll to the end and select the last row
M_listbox.setcursel (m_listbox.getcount ()-1 );

// Automatically scroll to the end
M_listbox.setcaretindex (m_listbox.getcount ()-1, false );
Or
M_listbox.settopindex (m_listbox.getcount ()-1 );
--------------------------------------------------------------------------------

6. Use of setitemdataptr () and getitemdataptr ()
Setitemdataptr () is to associate a 32-bit pointer with an item in the list box. It can be obtained by calling getitemdataptr () after setting. Therefore, we can connect the data in the list box externally.
In practical application, for example, if the item in the list box is a person's name, we can create a data structure to store the person's gender, address, phone number, and other information, establish contact with item. When an item is obtained, we also obtain information about the person.

Example:
Struct _ person_info {
Cstring strsex;
Cstring straddress;
Cstring strphonenumber;
} Personinfo;

Personinfo * PI;

Int nindex = m_listbox.addstring (_ T ("small 3 "));
M_ppersoninfo = new personinfo ();
Pi-> strsex = _ T ("male ");
Pi-> straddress = _ T ("XXX City ");
Pi-> strphonenumber = _ T ("1234567678 ");
M_listbox.setitemdataptr (nindex, (lpvoid) PI );

// Obtain
Personinfo * Pi = NULL;
Pi = (personinfo *) m_listbox.getitemdataptr (nindex );

--------------------------------------------------------------------------------

7. Color string ListBox
Http://www.codeguru.com/cpp/controls/listbox/colorlistboxes/article.php/c1611/
Http://www.codeproject.com/combobox/xlistbox.asp

--------------------------------------------------------------------------------

8. Transparent background ListBox
Http://www.codeguru.com/cpp/controls/listbox/colorlistboxes/article.php/c10413/

--------------------------------------------------------------------------------

9. Drag and Drop In ListBox
(1) drag and drop in a ListBox
Http://www.codeguru.com/cpp/controls/listbox/dragdrop/article.php/c11061/
Http://www.codeguru.com/cpp/controls/listbox/dragdrop/article.php/c4747/

(2) drag and drop between two listboxes
Http://msdn.microsoft.com/msdnmag/issues/04/10/CQA/
Http://www.codeguru.com/cpp/controls/listbox/dragdrop/article.php/c11069/

 

--------------------------------------------------------------------------------

10. clistboxst is a very good class.
Http://www.codeguru.com/cpp/controls/listbox/article.php/c4753/

--------------------------------------------------------------------------------

11. Similar to the VB attribute selection window
Http://www.codeguru.com/cpp/controls/listbox/article.php/c1607/
Http://www.codeproject.com/combobox/Property_List.asp

--------------------------------------------------------------------------------

12. The directory setting window is similar to that of VC tools> Options> directories.

Http://www.codeguru.com/cpp/controls/listbox/article.php/c1613/

--------------------------------------------------------------------------------

13. ListBox with icon
Http://www.codeguru.com/cpp/controls/listbox/article.php/c4749/
Http://www.codeguru.com/cpp/controls/listbox/article.php/c4753/

--------------------------------------------------------------------------------

14. ListBox with checkbox
Http://www.codeproject.com/combobox/CCheckListBoxUsage.asp

--------------------------------------------------------------------------------

15. You can edit the ListBox of an item.
Http://www.codeproject.com/combobox/lbed.asp

--------------------------------------------------------------------------------

16. ListBox of disable item
Http://www.codeproject.com/combobox/disableditemslistbox.asp

--------------------------------------------------------------------------------

17. A self-painted ListBox

Q113189:
Listdlg.exe implements a list box full of dialog boxes
Http://support.microsoft.com/kb/113189/en-us

 

Related Article

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.