In this lesson, we'll learn how to create and work with List view controls.
Theory:
List view controls and tree views, rich text editing controls, are one of the common controls. You probably already know the list view control, but you don't know its exact name. A list view control can be used to display items well. In this respect it is the same as the list box, except that it is more performance-resilient.
There are two ways to create a list view control. The first and easiest way to do this is to use the resource Editor to create it. In this way just don't forget to add a call to the InitCommonControls function in your code (remember, call the function to simply load the DLL containing the generic control implicitly). Another method is to call the CreateWindowEx function, where you must specify the appropriate class name, for example: Syslistview32,wc_listview is not the correct class name
There are four ways to display data in a list view: Large icons, small icons, lists, and reporting methods. These methods and in the Resource manager species select View->large icons,small Icons, the List and the Details correspond. A variety of different display modes only show a different look. For example, you may have a lot of data, just don't want to show it all. The information provided by the report is the most complete, and much less so in other ways. You can select an initial display method when you first create a list view, and then you can call the Setwinodwlong function and set the GWL_STYLE flag to change the display
Now that we know how to create a list control, let's learn how to use them. We will focus mainly on the presentation of the report mode, because it demonstrates the most characteristic of list control. The steps for using list control are as follows:
Call the CreateWindowEx function to create a list control that specifies that its class name is SysListView32. You can also specify how the control will appear when it is first displayed.
Create and initialize an image list (if any) that displays items in a list control.
Inserting a column into a list control is necessary if it is displayed in a way that is reported.
Inserts a project and a self project into the control.
Column:
There are more than one column in the reporting mode. You can think of the data you put into a list control as a form: the data is sorted by row and column. There is at least one column in the control. It doesn't matter in other ways, because there is only one column in these displays.
The join column is implemented by sending a lvm_insertcolumn message to the list control.
Lvm_insertcolumn
WParam = Icol
LParam = pointer to lv_column type structure variable
Number of icol columns, numbering from 0 onwards.
Lv_column contains information about the columns that will be inserted. It is defined as follows:
Lv_column STRUCT
Imask DD?
FMT DD?
LX DD?
Psztext DD?
Cchtextmax DD?
Isubitem DD?
Iimage DD?
Iorder DD?
Lv_column ENDS
Field Name Meanings
Imask a set of flag bits that indicate that the member variables in the structure are valid. The member variables in the structure are not valid at the same time. At some point, only some of the member variables may be valid. The structure can be used for input and output. It is important to let Windows know that the member variables are valid. Possible signs are:
LVCF_FMT = FMT Valid
Lvcf_subitem = Isubitem Valid
Lvcf_text = psztext valid.
Lvcf_width = lx Valid
You can use several flags at once. For example, if you assign a text label (a column name) to a specified column, you must supply the column name in the psztext member variable, and then specify that the flag Lvcf_text tell the Windows member variable psztext that the value in is valid, otherwise Windows ignores the values in Psztext.
FMT Specifies the alignment of the project/subproject. The possible values are:
Lvcfmt_center = text Centered
Lvcfmt_left = text left-aligned
Lvcfmt_right = text right-aligned
An LX lx is the width, in pixels, of a column. You can then send message lvm_setcolumnwidth to change the width of the column.
Psztext the member variable is a pointer to the column name if it is used to set the property of the column. In the case of a query column name, the member variable points to a buffer large enough to receive the returned column name, which is the size of the buffer you must specify in the member Cchtextmax. If you are setting a column name, you can omit the variable because it points to a string of ASCII code, and Windows can parse the length of the ASCII string.
Cchtextmax Cchtextmax A small buffer that is pointed to by a member variable above the byte meter. The member variable is used only when you query the properties of the column. If the property of the column is set, the variable is ignored.
ISUBITEM Specifies the index number of the subproject that is connected to the column. The value of the member variable is used to identify and column the subprojects of the connected system. The use of this column best describes how to connect a column number to a subproject. To query the properties of a column, you can send a lvm_getcolumn message and specify the LVCF_SUBITEM flag in the member variable Imask, and the list control returns the Isubitem value that was set at the time of insertion in Isubitem. In order to use this method, you need to put the correct value in the member variable.
Iimage and Iorder are compatible with versions above IE3.0. I do not have this information at the moment.
After a list view control is created, you must insert at least one column into it. Of course, it's not necessary to insert a column if you're not going to use the reporting method. To insert a column, you define a lv_column-type struct variable, assign the correct value to its member variable, specify the column number, and then send a lvm_insertcolumn message to the list view control and pass the value of the struct variable.
Local Lvc:lv_column
MOV lvc.imask,lvcf_text+lvcf_width
MOV Lvc.psztext,offset Heading1
MOV lvc.lx,150
Invoke Sendmessage,hlist, Lvm_insertcolumn,0,addr LVC
The preceding code snippet shows the procedure. When a lvm_insertcolumn message is sent, he specifies the column's title bar text and its width.
Projects and subprojects
Items are the main content in a list view. You can see only items in the list view, except for the way the report is displayed. Subprojects are detailed information about the project. A project may have more than one related subproject. For example, a project is a filename, and its associated subprojects may have file attributes, size, creation date, and so on. In the view of the report mode, the leftmost column is the item, and the other columns are subprojects. From a database record perspective, a project resembles a primary key, and a subproject resembles a record.
At least your list view requires some items: subprojects are optional. If you want to provide more information to the user, you can connect the project to the project, and then put it in the list view and display it in a report format.
You can add an item to a list view by sending a lvm_insertitem message to it, and you also need to put a pointer to a variable that points to a lv_item struct to the lparam to the list view. The definition of Lv_item is as follows:
Lv_item STRUCT
Imask DD?
IItem DD?
Isubitem DD?
State DD?
Statemask DD?
Psztext DD?
Cchtextmax DD?
Iimage DD?
LParam DD?
Iindent DD?
Lv_item ENDS
Field Name Meanings
Imask a set of flag bits indicates that the values in those member variables in the structure are valid. Its meaning is basically the same as the corresponding member variable in the Lv_column type structure we mentioned above. For more detailed information, you can query the WIN32 API manual.
IItem the index number of the item represented by the struct. The index number is numbered starting from 0. This value is similar to the "line" of the form.
Isubitem the index number of the subproject that is connected to the item specified by the previous member variable. You can treat it as a "column" of the form. For example, if you want to insert an item into a newly created List view control, the value of IItem should be 0 (because the item is the first item), and Isubitem should be 0 (we want to insert the item into the first column). If you want to specify that a subproject is connected to the project, the IItem should be the index number of the item you want to connect to, and the value of Isubitem should be a value greater than 0, depending on the column you want to insert in the subproject. If your list view control has a total of 4 columns, the first column contains the items, and the remaining 3 columns are left to the subproject. If you want the item inserted in the fourth column, you should specify that the value is 3.
State This member variable contains a flag bit that reflects the status of the project. A change in state may be caused by the user's actions or by a program change. These states include whether the focus/high-brightness display/is selected (as Cut)/selected, and so on. It also includes a 1-based index to represent whether an overlay/status icon is used.
Statemask because the above member variable contains the status flag bit, the overlapping bitmap index number, and the index number of the status bitmap, we need to tell windows whether we need to set or query that value. This member variable is used to do the work.
Psztext when we want to set the properties of the project, it contains the address of the string for the ASCII code of the project name. When you query the properties of a project, the member variable is used to receive the name of the item returned by the query.
Cchtextmax only needs to use this value when you are querying the properties of the item, which contains the size of the last member variable.
The index number of the Iimage icon in the list view image chain.
LParam user-defined values that are used when you sort items. When you tell a list view to sort items, the list view will compare items in pairs. It will pass the value of the lparam of the two items to you so that you can make a comparison and list that one first. If you are not quite clear now, there is no department, we will talk about the sort of question later.