一、 在Windows应用法度中添加ListControl控件的几种办法
1、 在对话框中添加控件:
创建对话框应用法度,在资料视图中添加对话框。如下图所示,在控件对象条中选择ListControl控件添加到对话框中,并调剂控件尺寸。在ListControl控件的属性页中设置控件样式(Styles)和扩大样式等。为了显示具体数据信息,可以设置控件的显示风格为报表视图(Report)。
为了在对话框中应用控件,须要在ClassWizard中为对话框类添加控件成员变量,如下图所示:
相关代码如下:
// ListDialogDlg.h : header file
public:
CListCtrl m_cListCtrl;
......
// ListDialogDlg.cpp : implementation file
......
void CListDialogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListDialogDlg)
DDX_Control(pDX, IDC_LIST_CTRL, m_cListCtrl);
//}}AFX_DATA_MAP
}
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListDialogDlg)
DDX_Control(pDX, IDC_LIST_CTRL, m_cListCtrl);
//}}AFX_DATA_MAP
}
......
因为本例只为演示在对话框中添加ListControl控件,所以只在对话框初始化消息函数中添加了以下显示控件的示例代码(代码含义请参照MSDN文献):
BOOL CListDialogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
{
CDialog::OnInitDialog();
......
// TODO: Add extra initialization here
DWORD exstyle = m_cListCtrl.GetExtendedStyle();
m_cListCtrl.SetExtendedStyle(exstyle | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |LVS_EX_CHECKBOXES | WS_EX_STATICEDGE );
DWORD exstyle = m_cListCtrl.GetExtendedStyle();
m_cListCtrl.SetExtendedStyle(exstyle | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |LVS_EX_CHECKBOXES | WS_EX_STATICEDGE );
CRect rect;
m_cListCtrl.GetClientRect(&rect);
int nColInterval = rect.Width()/5;
m_cListCtrl.GetClientRect(&rect);
int nColInterval = rect.Width()/5;
m_cListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT,
nColInterval*3);
m_cListCtrl.InsertColumn(1, _T("Value"), LVCFMT_LEFT,
nColInterval);
m_cListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT,
rect.Width()-4*nColInterval);
nColInterval*3);
m_cListCtrl.InsertColumn(1, _T("Value"), LVCFMT_LEFT,
nColInterval);
m_cListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT,
rect.Width()-4*nColInterval);
m_cListCtrl.InsertItem(0,"name");
m_cListCtrl.SetItemText(0,1,"value");
m_cListCtrl.SetItemText(0,2,"time");
m_cListCtrl.SetItemText(0,1,"value");
m_cListCtrl.SetItemText(0,2,"time");
......
return TRUE; // return TRUE unless you set the focus to a control
return TRUE; // return TRUE unless you set the focus to a control
}
2、 在单文档视图中自行添加ListControl控件:
创建单文档应用法度,如下图所示为视图类添加CListCtrl对象成员变量:
如下图所示,在资料视图中打开String Table资料,在右键菜单中选择new
string,为将要创建的ListControl控件添加资料编号:
string,为将要创建的ListControl控件添加资料编号:
为创建和显示控件,在视图的初始化消息函数中添加如下代码:
void CAddListView::OnInitialUpdate()
{ CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
m_cListCtrl.Create( LVS_REPORT,CRect(0,0,800,600),this,IDC_LISTCTRL);
m_cListCtrl.ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SORTASCENDING);
//m_cListCtrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES);
{ CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
m_cListCtrl.Create( LVS_REPORT,CRect(0,0,800,600),this,IDC_LISTCTRL);
m_cListCtrl.ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SORTASCENDING);
//m_cListCtrl.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES);
m_cListCtrl.ShowWindow(SW_SHOW);
CRect rect;
m_cListCtrl.GetClientRect(&rect);
int nColInterval = rect.Width()/5;
m_cListCtrl.GetClientRect(&rect);
int nColInterval = rect.Width()/5;
m_cListCtrl.InsertColumn(0, _T("Item Name"), LVCFMT_LEFT,
nColInterval*3);
m_cListCtrl.InsertColumn(1, _T("Value"), LVCFMT_LEFT,
nColInterval);
m_cListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT,
rect.Width()-4*nColInterval);
nColInterval*3);
m_cListCtrl.InsertColumn(1, _T("Value"), LVCFMT_LEFT,
nColInterval);
m_cListCtrl.InsertColumn(2, _T("Time"), LVCFMT_LEFT,
rect.Width()-4*nColInterval);
m_cListCtrl.InsertItem(0,"name");
m_cListCtrl.SetItemText(0,1,"value");
m_cListCtrl.SetItemText(0,2,"time");
}
m_cListCtrl.SetItemText(0,1,"value");
m_cListCtrl.SetItemText(0,2,"time");
}
3、 在ListView视图中显示ListControl控件:
创建单文档应用法度,如下图所示,在选择窗口视图类型时,选择CListView视图:
在视图类的初始化消息函数中添加如下显示控件的代码:
void CTestlistView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
CDC* dc = GetDC();
TEXTMETRIC tm;
dc->GetTextMetrics(&tm);
GetListCtrl()excel listview控件.ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SORTASCENDING);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0, LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES|LVS_EX_TRACKSELECT);
GetListCtrl().InsertColumn(0,"Name",LVCFMT_LEFT,AveCharWidth,0);
GetListCtrl().InsertColumn(1,"Comment",LVCFMT_LEFT,AveCharWidth,1);
{
CListView::OnInitialUpdate();
CDC* dc = GetDC();
TEXTMETRIC tm;
dc->GetTextMetrics(&tm);
GetListCtrl()excel listview控件.ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SORTASCENDING);
GetListCtrl().SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0, LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES|LVS_EX_TRACKSELECT);
GetListCtrl().InsertColumn(0,"Name",LVCFMT_LEFT,AveCharWidth,0);
GetListCtrl().InsertColumn(1,"Comment",LVCFMT_LEFT,AveCharWidth,1);
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to
GetListCtrl().
}
GetListCtrl().
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论