Wizard process
Select "File"-"New"-"Project" in VS:
select MFC-MFC application, then we create a single-document MFC standard type application.
Press the default value next all the way to the last page:
MFC automatically generated four classes for us, and their inheritance relationship is as follows:
Class View
Effect picture:
Steps:
Select "File"-"New"-"Project" in VS:
Continue to the next step until it is completed
Common property settings: view -> Report (report mode)
Steps to
create a form:
add variables to list Control
Generate the ClistFrame class and add in its initialization code OnInitDialog():
BOOL ClistFrameDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
!!!!!!!!!!!!!!!所加代码这里!!!!!!!!!!!!!!!!!!!!!
//列表控件使用
//标题所需字段
CString head[]={
TEXT("姓名"),TEXT("年龄"),TEXT("性别")};
CString name[]={
TEXT("李白"),TEXT("鲁班"),TEXT("韩信"),
TEXT("亚索"),TEXT("达摩"),TEXT("小明")};
//插入列标题
m_list.InsertColumn(0,head[0],LVCFMT_LEFT, 100);
m_list.InsertColumn(1,head[1],LVCFMT_LEFT, 100);
m_list.InsertColumn(2,head[2],LVCFMT_LEFT, 100);
//插入正文内容
for(int i=0;i<6;i++){
// CString str;
// str.Format(TEXT("张三_%d"),i);
// str.Format(TEXT("name[i]_%d"),i);
//确定行数
m_list.InsertItem(i,name[i]);
//设置列内容
int j=0;
int age=23;
m_list.SetItemText(i,++j,TEXT("23"));//怎么设置int
m_list.SetItemText(i,++j,TEXT("男"));
}
//设置风格样式
//LVS_EX_GRIDLINES 网格
//LVS_EX_FULLROWSELECT 选中整行
m_list.SetExtendedStyle(m_list.GetExtendedStyle()
| LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}