1、LIST CONTROL(report方式):
(1)类的方式
A.增加列
LVCOLUMN lv;
lv. mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH ;
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="编号";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =0;
lv.iOrder =0;
m_list->InsertColumn(0,&lv);
lv.pszText="名称";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =1;
lv.iOrder =1;
m_list->InsertColumn(1,&lv);
lv.pszText="简称";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =2;
lv.iOrder =2;
m_list->InsertColumn(2,&lv);
lv. mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH ;
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="编号";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =0;
lv.iOrder =0;
m_list->InsertColumn(0,&lv);
lv.pszText="名称";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =1;
lv.iOrder =1;
m_list->InsertColumn(1,&lv);
lv.pszText="简称";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =2;
lv.iOrder =2;
m_list->InsertColumn(2,&lv);
B.增加行
CListCtrl *proclist;
proclist=(CListCtrl *)GetDlgItem(IDC_PROCLIST);
int nItem = proclist->InsertItem(0,(char*)("vvvv"));
proclist->SetItem(nItem,1,LVIF_TEXT,(char*)("ffffff"),0,0,0,0);
proclist=(CListCtrl *)GetDlgItem(IDC_PROCLIST);
int nItem = proclist->InsertItem(0,(char*)("vvvv"));
proclist->SetItem(nItem,1,LVIF_TEXT,(char*)("ffffff"),0,0,0,0);
(2)非类的方式
A.增加列
LVCOLUMN lv;
lv. mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH;
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="第一项";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =0;
lv.iOrder =0;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTCOLUMN,0,(LPARAM)&lv);
lv. mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH ;
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="第二项";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =1;
lv.iOrder =1;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTCOLUMN,1,(LPARAM)&lv);
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="第一项";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =0;
lv.iOrder =0;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTCOLUMN,0,(LPARAM)&lv);
lv. mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH ;
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="第二项";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =1;
lv.iOrder =1;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTCOLUMN,1,(LPARAM)&lv);
lv. mask=LVCF_TEXT|LVCF_FMT|LVCF_WIDTH;
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="第三项";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =2;
lv.iOrder =2;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTCOLUMN,2,(LPARAM)&lv);
lv. fmt=LVCFMT_CENTER ;
lv.cx=100;
lv.pszText="第三项";
lv.cchTextMax=sizeof(lv.pszText);
lv.iSubItem =2;
lv.iOrder =2;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTCOLUMN,2,(LPARAM)&lv);
B.增加行
LVITEM procinfo;
procinfo.iItem=0;
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("aaaaa");
procinfo.iSubItem=0;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTITEM,0,(LPARAM)&procinfo);
procinfo.iItem=0;
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("aaaaa");
procinfo.iSubItem=0;
SendDlgItemMessage(IDC_PROCLIST,LVM_INSERTITEM,0,(LPARAM)&procinfo);
procinfo.iItem=0;
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("bbbbb");
procinfo.iSubItem=1;
SendDlgItemMessage(IDC_PROCLIST,LVM_SETITEMTEXT,0,(LPARAM)&procinfo);
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("bbbbb");
procinfo.iSubItem=1;
SendDlgItemMessage(IDC_PROCLIST,LVM_SETITEMTEXT,0,(LPARAM)&procinfo);
procinfo.iItem=0;
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("ccccccccc");
procinfo.iSubItem=2;
SendDlgItemMessage(IDC_PROCLIST,LVM_SETITEMTEXT,0,(LPARAM)&procinfo);
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("ccccccccc");
procinfo.iSubItem=2;
SendDlgItemMessage(IDC_PROCLIST,LVM_SETITEMTEXT,0,(LPARAM)&procinfo);
procinfo.iItem=0;
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("ddddddd");
procinfo.iSubItem=3;
SendDlgItemMessage(IDC_PROCLIST,LVM_SETITEMTEXT,0,(LPARAM)&procinfo);
procinfo.mask=LVIF_TEXT;
procinfo.pszText=(LPTSTR)("ddddddd");
procinfo.iSubItem=3;
SendDlgItemMessage(IDC_PROCLIST,LVM_SETITEMTEXT,0,(LPARAM)&procinfo);
2、LISTBOX:
(1)类的方式
CListBox *proclist;
proclist=(CListBox*)GetDlgItem(IDC_PROCLIST);
proclist->AddString("ssssssssssssss");
proclist=(CListBox*)GetDlgItem(IDC_PROCLIST);
proclist->AddString("ssssssssssssss");
(2)非类的方式
SendDlgItemMessage(IDC_PROCLIST,LB_ADDSTRING,0,(LPARAM)("ffffff"));
SendDlgItemMessage(IDC_PROCLIST,LB_ADDSTRING,0,(LPARAM)("ffffff"));