(1) List of list controls Control and List control & view mainly used to display a set of data records in various ways to perform various operations, "View" under the resource manager in Windows 98/95 "Big Icon | Small Icon | List | Detailed Resources" is a very good typical application. The records in the list may include a plurality of data items, or may include a size icon indicating the data content to indicate various attributes of data records. The list control provides the basic method for the Windows list function, and the list of view functions using the list can perform a variety of operations, and obtain a reference to the list-dependent list control by calling the member getListCtr (getListCtrl & ctrllist = getListCtrl. )), You can perform various operations as the list control. Operating a list of basic methods for: Creating list controls; create list of images required for list control; add table columns and entries to the list; for a variety of controls, mainly include find, sort, delete, display Ways, arrangements, and various message processing functions, etc .; finally undo list control. For a list control, its most commonly used display control mode is: large icon mode (LVS_ICON), small icon mode (lvs_liston), list display mode (LVS_LIST), and detailed information (ie report LVS_REPORT) display mode. This can be implemented by setting its display mode properties. To control the style of the window where the list is located, you can implement the functionality getWindowlong and SetWindowl, to control the alignment of the list icon, can be implemented by setting the list window, LVS_ALIGNTOP or LVS_ALIGNLEFT, (2) List Controlled Object Structure 1, list Controlling Method CLISTCTRL & ListCtrl Defines the Structure of List Objects CREATE Creation List Control and Bind Object List Control CListCtrl :: Create The call format is as follows: Bool Create (DWord DWStyle, Const Rect, CWnd * PparentWnd, uint NID); parameter DWStyle The style used to determine the list control; RECT is used to determine the size and position of the list control; PParentWnd is used to determine the parent window controlled by the list, which is usually a dialog; NID is used to determine the identity of the list control.
The style of the list control can be a combination of the following value: LVS_alignleft is used to determine the size icon of the entry to display the left alignment; LVS_ALIGNTOP is used to determine the size of the entry to display; LVS_AUTOARRANGE is used to determine the size of the entry The icon is displayed automatically; the LVS_EDITLABELS setting entry text can be edited, the parent window must have a LVN_ENDLABELEDIT style; LVS_ICON is used to determine the display mode of the large icon; LVS_LIST is used to determine the list mode display; LVS_nocolumnheader is used to determine how to determine when detail The list header is not displayed; LVS_NOLabelwrap is used to determine the text item of the icon in a single line; lvs_noscroll is used to block the scroll bar; LVS_NOSORTHEADER is used to determine that the list head cannot be used as a button function; LVS_OWNERDRAWFIXED allows the self-painted window when it is a detailed list; LVS_Report To determine the display method in detail; LVS_SHAREIMAGELISTS is used to determine a list of shared images; LVS_SHOWSELALWAYS is used to determine the selected entry mode; LVS_SINGLESEL is used to determine if there is only one selected; lvs_smallicon is used to determine Small icon display method; LVS_SORTASCENDING is used to determine the description of the entry text; LVS_SORTDESCENDING is used to determine the description of the description text when the entry is sorted; 2. Attributes control of the list control of the list control Class includes the background color GetBkColor, setting list control, set the list control, the list of images, the list of images, the list of images, settings list, the list of lists, the number of list items GetItemcount, get list control GetItem, get the list Item related data GETITEMDATA, settings table item properties setItem, settings related to the entries setItemData, get the associated next entry GetNextItem, set list control text Color setTextColor, get list control text background color GetTextBkcolor, set The maximum number of entry setItemcount and the number of selected entry are GetSelectedCount, etc. 3, the list of operation method list controls the list control includes inserting a new entry INSERTITETEM, deleting a table entry deleteItem, the location of the list hittest, the redrawing entry RedrawItems, insert a list of INSERTCOLUMN, Delete a table column deleteColumn, edit a table item text EditLabel and redraw a read key DrawItem. (3) The list of data structures controlled by the list includes two very important data structures LV_Item and LV_Column.
LV_Item is used to define a list of list controls, and LV_COLUMN is used to define a list of list controls, and its definition format is: typedef struct _lv_item {uint mask; // Structural member mask IIITEM; // Test Item Int isubitem; // Sub-item index marks uint state; // entry status uint statemask; // Status Validity mask bit LPTSTSTSTSTSTEXTEXT; / / Table Name text int cchtextMax; // Table Name The maximum length IImage; // Terminal icon Index number lParam lparam; // 32-bit number} lv_item; typef struct _lv_column {uint maask; // structure member valid mask INT fmt; // table column Alignment INT CX ; // Table column of pixel width lptstr psztext; // table list of headname int cchtextMax; // table name text length int isubitem; // is associated with table columns 引 索}}} lv_column; FMT can take a lower value: LVCFMT_Center table column alignment LVCFMT_LEFT table column left alignment (4) list control application skills given the specific instance demonstration list control and application skills of the previous header control and image list. The steps are as follows: 1. "File-> New-> Projects-> MFC AppWizard (EXE)" establishes a project named VCLIST, selecting a dialog based application during the establishment process; the default in the dialog box Control delete and set the Language field in all dialog properties to Chinese (PRC) to support the application to support Chinese; 2. Create two icons IDi_gj and IDi_xs to indicate the selection and non-selective state of the icon, for each The icons should be established 32x32 and 16x16 sizes to ensure the needs of the program; 3. Design the combo box (Group box) in the dialog window, set four wireless buttons (Radio) "big icons | small icons | List | Data, simultaneous setting, delete, and turn off three control buttons (button), and set size appropriate list control (List Ctrl) in the dialog, the corresponding identifier is as follows: Control Name Title Name List Control IDC_ListCtrl combination box mode IDC_STATIC wireless button large icon IDC_STDICON small icon IDC_SMLICON list IDC_LIST data IDC_REPORT button Sort IDC_SORT Delete IDC_DEL Close IDOK 4, when setting the wireless button, it is necessary to note that only the large icon's Group property is selected, and other wireless The status of the button is the default value. 5, select the list control control, select "View-> ClassWizard-> Memory Variables", and use IDC_ ListCtr to introduce member variables, the variable type is: Variable Name Variable Type M_ListCtrl Control ClistCtr, using "Messages Map" for each wireless button And the command button to increase the control function.
6, then add the following code in the included file and code file: (1) Add data structure and define typef struct tagsps {// definition structure char SZPM [10]; // Product Name INT LX; // 0-gj 1-xs char SZSL [10]; // Quantity Char Szdj [10]; // Price Char Szje [10]; // Gold} SPS; Int Callback Comparefunc (LParam Lparam1, LParam LParam2, LParam lparamsort); (2) Increasing the initialization data and program definition in the beginning of vclistdlg.cpp // Add data structure to initialize SPS SPS SPS [] = {// Information {"Red plum", 0, "1000", " 30 "," 30000 "}, {" Huangmei ", 0," 1000 "," 29 "," 29000 "}, {" Greenme ", 0," 1000 "," 28 "," 28000 "}, { "Qingmei", 0, "1000", "27", "27000"}, {"Baimei", 0, "1000", "31", "31000"}, {"Hongmei", 1, "1000" , "30", "30000"}, {"Huangmei", 1, "1000", "29"}, {"Greenme", 1, "1000", "28", "28000"} "{" Green Mime ", 1," 1000 "," 27 "," 27000 "}," Baimei ", 1," 1000 "," 31 "," 31000 "}}; CIMAGELIST CIL1, CIL2; / / Size Image list (3) adds a header, image and list control establishment code BOOL CVCLISTDLG :: OnNInitdialog () {cdialog :: OnInitDialog (); //......// Other code // Todo: Add Extra Initialization Here Adds the code LV_Item Lvitem; LV_COLUMN LVCOL; INT i, IPOS, IIIX; CVClistApp * PAPP = (CVClistApp *) AFXGetApp (); // Create an image list Cil1.create (32, 32, true, 2 , 2); Cil1.add (PAPP-> Loadicon); Cil1.Add (Papp-> Loadico n (IDi_xs)); cil2.create (16, 16, true, 2, 2); cil2.add (PAPP-> Loadicon); cil2.add (PAPP-> Loadicon (IDI_XS)); // Setting image list m_ListCtrl.SetImageList (& Cil1, LVSIL_NORMAL); m_ListCtrl.SetImageList (& Cil2, LVSIL_SMALL); // add to the table column list lvcol.mask = LVCF_FMT control | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; lvcol.fmt = LVCFMT_CENTER; // = 0; lvcol.psztext = "Name";
Lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); lvcol.psztext = "quantity"; lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); Lvcol.psztext = "unit price"; lvcol.isubitem = i; lvcol.cx = 70; M_ListCtrl.insertColumn (i , & lvcol); lvcol.psztext = "amount"; lvcol.isubitem = i; lvcol.cx = 70; m_listctrl .EnsertColumn (i , & lvcol); // Add item IIITEMNUM = SizeOf (SPS) / sizeof (SPS) to list control; for (i = 0; i = 0; i -) {istate = m_listctrl.getItemState I, lvis_selected; if (istate! = 0) m_listctrl.deleteItem (i);}} (6) Implementation list control of the sorting function has a special feature, when displayed in detail, the top of the list can When used as a button, this can be controlled by the list of style when the list is created. When the mouse point hits the list name, the list control sends an LNV_COLUMNCLICK message to its parent window. Use the LNV_ColumnClick message corresponding to the list control IDC_ListCtrl in the class-oriented to add the corresponding processing function, and can be arranged in a particular order. Its function is used to see the program, where ISORT is sorted back column index number, (pfnlvcompare) Comparefunc is a specific sorted callback function, that is, the sorting process implemented by the mouse click is a dedicated sort of third-party development. The function is implemented, the sort function is just the specific comparison operation of the implementation entry, and the entire sorting process is implemented by the SortItems property by continuously calling this function. The normal sorting process is an ascending mode. By switching the parameter values in the sort function, you can replace the sequence arrangement, and the PARAM1 is changed to the PARAM2. The first two parameters of this callback function are the index number of the table item in the table, and the third parameter is sorted.