The development of the host computer is based on some methods of using the LisControlt control in MFC

The development of the host computer is based on some methods of using the LisControlt control in MFC

1. First find the LisControlt control under the toolbar and add a new creation, you can change the ID in the properties, and then remember to select the report property in the View bar of the properties, because we are creating a list

2. Next, our list box is created, as shown in the figure:

Insert picture description here
2. Next click on the list control we created, right click, and then click Add Variable, then enter the name of the control variable in the list box, as shown in the figure,
Insert picture description here
Insert picture description here
then click OK, we can also go to the dialog box Check whether the associated variable is created in the header file, as shown in the figure
Insert picture description here
, so that all the attributes of our list box are set, and then post the code
3. Add other attribute settings of the list box in the initialization dialog function:

BOOL CHMList::OnInitDialog()
{
    
    
	CDialog::OnInitDialog();
	//对话框在屏幕最大化显示
	int cx,cy; 
	CRect rcTemp; 
	cx = GetSystemMetrics(SM_CXSCREEN); 
	cy = GetSystemMetrics(SM_CYSCREEN); 
	rcTemp.BottomRight() = CPoint(cx, cy); 
	rcTemp.TopLeft() = CPoint(0, 0); 
	MoveWindow(&rcTemp);


	// 获取编程语言列表视图控件的位置和大小   
	m_list.GetClientRect(&m_ListRect);   
	// 为列表视图控件添加全行选中和栅格风格   
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);  

	// 为列表视图控件添加列   
	m_list.InsertColumn(0, _T("压机号"), LVCFMT_CENTER, m_ListRect.Width()/18, 0);   
	m_list.InsertColumn(1, _T("时间"), LVCFMT_CENTER, m_ListRect.Width()/6, 1);   
	m_list.InsertColumn(2, _T("当前总数值"), LVCFMT_CENTER, m_ListRect.Width()/12, 2);
	m_list.InsertColumn(3, _T("注塑杠设定值"), LVCFMT_CENTER, m_ListRect.Width()/10, 3);
	m_list.InsertColumn(4, _T("注塑杆当前值"), LVCFMT_CENTER, m_ListRect.Width()/10, 4);
	m_list.InsertColumn(5, _T("浇口设定值"), LVCFMT_CENTER, m_ListRect.Width()/12, 5);
	m_list.InsertColumn(6, _T("浇口当前值"), LVCFMT_CENTER, m_ListRect.Width()/12, 6);
	m_list.InsertColumn(7, _T("模盒设定值"), LVCFMT_CENTER, m_ListRect.Width()/12, 7);
	m_list.InsertColumn(8, _T("模盒当前值"), LVCFMT_CENTER, m_ListRect.Width()/12, 8);
	m_list.InsertColumn(9, _T("选项1设定值"), LVCFMT_CENTER, m_ListRect.Width()/11, 9);
	m_list.InsertColumn(10, _T("选项1当前值"), LVCFMT_CENTER, m_ListRect.Width()/11, 10);
	m_list.InsertColumn(11, _T("选项2设定值"), LVCFMT_CENTER, m_ListRect.Width()/11, 11);
	m_list.InsertColumn(12, _T("选项2当前值"), LVCFMT_CENTER, m_ListRect.Width()/11, 12);
	m_list.InsertColumn(13, _T("选项3设定值"), LVCFMT_CENTER, m_ListRect.Width()/11, 13);
	m_list.InsertColumn(14, _T("选项3当前值"), LVCFMT_CENTER, m_ListRect.Width()/11, 14);
	m_list.InsertColumn(15, _T("冲流道设定值"), LVCFMT_CENTER, m_ListRect.Width()/11, 15);
	m_list.InsertColumn(16, _T("冲流道当前值"), LVCFMT_CENTER, m_ListRect.Width()/11, 16);

	m_list.SetBkColor(RGB(185,185,237)); //设置背景颜色		
	m_list.SetTextBkColor(RGB(185,185,237)); //设置文本背景颜色
	m_list.SetTextColor(RGB(0, 0, 0)); //设置文本颜色

	SetTimer(1,1000,NULL);
	return TRUE;
}

The effect is shown in the figure:
Insert picture description here
Mainly talk about the attribute settings
of the inserted column. Example: m_list.InsertColumn(0, _T("press number"), LVCFMT_CENTER, m_ListRect.Width()/18, 0);
Parameter 1: indicates that it is a list The first column;
Parameter 2: Indicates the column name;
Parameter 3: Indicates that the column name is in the middle of the text box;
Parameter 4: Indicates that the width of the text box is 1/18 of the entire list box, this parameter can be based on the width you want Change
parameter 5: default 0;
there are comments in the rest of the code

Next, the second article explains how to use the ADO recordset to access the database and read all the data to the list when the database is Access.

Guess you like

Origin blog.csdn.net/weiwei_lol/article/details/109271320