Win32 SDK List view Control two important structural bodies

Source: Internet
Author: User

A list view control is a very common control, and when you need to display data as a report, a list control is usually the best choice, and many specialized data report controls are derived from it. Like a tree view, a list control can consist of multiple sub-items, which can be set to icon (large icon), SmallIcon (small icon), list, or report.

One, the list view control has two important data structures lvcolumn and Lvitem. Lvcolumn is used to define the structure of "columns" under the reporting method; Lvitem is used to define the structure of the "item". The definitions and descriptions of these two structures are as follows:

typedef struct _LVCOLUMN {

UINT Mask; Describes which members in this structure are valid

int FMT; Alignment of columns

int CX; Initial width of column

LPTSTR PszText; The title of the column

int Cchtextmax; The size of the buffer that the psztext points to

int ISubItem; The index value of the subkey associated with the column, starting with 0

int iImage; The index value of the specified image in the image list associated with the column

int iorder; Number of columns, 0 for the leftmost column

} lvcolumn, far lplvcolumn;

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

typedef struct _LVITEM {

UINT Mask; Describes which members in the LVITEM structure are valid

int IItem; Index value of item (can be treated as line number) starting from 0

int ISubItem; The index value of the subkey (which can be treated as a column number) starts at 0

UINT State; The State of the subkey

UINT Statemask; Status-effective shielding bit

LPTSTR PszText; The name of the item or subkey

int Cchtextmax; The buffer size pointed to by the Psztext

int iImage; Index value of the specified image in the associated image list

LPARAM LPARAM; Program-defined 32-bit parameters

int iindent; The unit that represents the image position indentation

} Lvitem, far lplvitem;

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

Second, the related operation. Because it is SDK programming, the manipulation of the control is done by sending SendMessage () to the control.

The related message in the ListView is:

1, Lvm_settextcolor and Lvm_settextbkcolor and Lvm_setbkcolor//message set the foreground and background color of the text, wParam the RGB values for the 0,lparam colors

2, Lvm_getnextitem//Find the selected row, corresponding Listview_getnextitem macro will SendMessage packaged as function action.

3, Lvm_setcolumnwidth//Set column width, corresponding to Listview_setcolumnwidth

4, Lvm_setextendedlistviewstyle//Set extension style such as: Lvs_ex_fullrowselect (select a whole line), Lvs_ex_gridlines (network line), Lvs_ex_ Checkboxes (select button), corresponding to Listview_setextendedlistviewstyle

5, Lvm_insertcolumn//Insert new column, corresponding Listview_insertcolumn,wparam for integer, specify column number, LParam as pointer to Lv_column structure

6, Lvm_setcolumn//Set column, same as parameter

7, Lvm_insertitem//Insert item (line), corresponding Listview_insertitem, join project or subproject, WParam for 0,lparam pointer to Lv_item structure

8, Lvm_setitem//Set subkey (each column in the row), corresponding to Listview_setitem, set the project or sub-item, same as parameter

9, Lvm_getitem//Get the project or sub-project, the parameters above

10, Lvm_getitemcount//Get the number of items, corresponding to Listview_getitemcount

11, Lvm_getnextitem get the next project or sub-project, can be used to get the cursor selection of the project

12, Lvm_deleteitem//delete items, corresponding Listview_deleteitem, delete items or sub-items, WParam to Integer, specify item index number, LParam to 0

13, Lvm_deleteallitems//delete all items, WParam and LParam are 0

Iii. extended styles for Listctrl controls

Lvs_ex_gridlines//Draw a table line

lvs_ex_subitemimages//List of child item icons

Lvs_ex_checkboxes//With check box

Lvs_ex_trackselect//Automatic line wrapping

lvs_ex_headerdragdrop//report header can be dragged and dragged

Lvs_ex_fullrowselect//Select Entire row

lvs_ex_oneclickactivate//Click Activate

lvs_ex_twoclickactivate//Double-click Activate

lvs_ex_flatsb//Flat scroll bar

Lvs_ex_regional

Lvs_ex_infotip

Lvs_ex_underlinehot

Lvs_ex_underlinecold

lvs_ex_multiworkareas//Multi-Work area

The ListView control belongs to one of the universal control controls, and is used when the SDK is programmed to use a common control

Must contain Comctl32.dll, so there is a header file in the code: commctrl.h Import Library: Comctl32.lib

You should call InitCommonControls () before using a generic control; initialize it

Take the ListView control as an example:

InitCommonControls ();

child window form using ListView

CreateWindowEx (0,//extended style wc_listview,//This is a system-defined macro, Wc_listview corresponds to "SysListView32" "123",//Window caption Ws_child | ws_visible | ws_clipsiblings | Ws_clipchildren | Lvs_report | Lvs_autoarrange | Lvs_showselalways | lvs_shareimagelists | Lvs_singlesel,//Window style (normal control style set here, extended style to be set separately) 0, 0,//window size 420,//width must be equal to all column width and, otherwise it will look empty column, hwnd,//parent window handle NULL, Menu handle HINSTANCE,//instance handle NULL//create parameter);

You can also use it as a child control in the dialog resource file

CONTROL "", Idc_listview, "SysListView32", Ws_border | Ws_tabstop | Lvs_report | Lvs_autoarrange | Lvs_showselalways | lvs_shareimagelists | Lvs_singlesel, 7,110,300,133


Win32 SDK List view Control two important structural bodies

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.