由MFC生成的单文档程序,如果继承了CListView类来显示图的话,默认是style 为 LVS_ICON,如果想改为LVS_REPORT,有以下两种方法:
1.在CXXXView类中添加OnCreate(...)消息响应函数,代码如下
int CXXXView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
lpCreateStruct->style |= LVS_REPORT | LVS_SHOWSELALWAYS;
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
2.修改CXXXView类中虚函数Create(...),代码如下
BOOL CXXX2View::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
dwStyle |= LVS_REPORT | LVS_SHOWSELALWAYS | LVS_EX_GRIDLINES;
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
但此时生成的List没有GRIDLINES,且无法被选中,接下来我们需要让我们的CLisView显示GRIDLINES,并能被选中,在CXXX2View::OnInitialUpdate()中添加代码如下:
void CXXXView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
CListCtrl& lc = GetListCtrl();
lc.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);LVS_ICON
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
}