单文档,在CListView的OnInitialUpdate中插入ITEM 不显示?

gbcin 2012-08-22 01:46:46
昨天把这儿问题发到微软的网站上,结果无人回答,555~~~~
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/56ef84ae-74ac-429c-a96e-90589a481f55
这个问题困扰我几天了。
求教下国内的各位大虾。。。

我有个单文档的程序。

用CFixedSplitter::CreateStatic and CFixedSplitter::CreateView把试图分割成了3份。

其中一份试图,我用的是派生自CListView的自定义类“CViewLog”。

现在的问题是我在CViewLog::OnInitialUpdate使用下面的代码,给CListCtrl添加item,程序运行后item不显示。

然后我建了个基于对话框的工程,放了个list control,在按钮里面用下面的代码,就可以显示item。

这个listview是我用来显示程序操作日志的,最终是希望在document类里面给listview添加item。

多谢。。。

There's a SDI application.

I split it into 3 views with CFixedSplitter::CreateStatic and CFixedSplitter::CreateView in OnCreateClient of CMainFrame.

One of these 3 views would show logs of this application.
Thus, I defined a Class named "CViewLog" with "CListView" as its parent.

In CViewLog::OnInitialUpdate, I put following code.

The problem of this code is that no item will be shown after launching application.
But the test code(See my comment) indicates the item is inserted and set successfully.

Then I created a dialog based project in VS where following code works well.
I did a search online and found this thread with almost the same issue:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/7dcab41b-d176-401e-be06-6a5d57973940
I tried the solution but still not working.

What I want is to insert item to CViewLog's CListCtrl from the document class.
Appreciate your help. Thanks.
/*****************************************************************/
void CViewLog::OnInitialUpdate(void)
{
// create image list and add column header to listCtrl
DWORD lStyle = 0;
CString csTemp;
int nRow = 0;

m_ImList.Create(16,16,TRUE,2,1);
m_ImList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
m_ImList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));

CListCtrl& cList = (CListCtrl&)GetListCtrl();
cList.SetImageList(&m_ImList, TVSIL_NORMAL);

lStyle = GetWindowLong(cList.m_hWnd, GWL_STYLE);
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_REPORT;
SetWindowLong(cList.m_hWnd, GWL_STYLE, lStyle);

cList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);

cList.InsertColumn(0,"Date", LVCFMT_IMAGE| LVCFMT_LEFT,100,0);
cList.InsertColumn(1,"Time", LVCFMT_LEFT,100,0);
cList.InsertColumn(2,"Event", LVCFMT_LEFT,740,0);
cList.DeleteAllItems();



nRow = cList.InsertItem(0,"asdf");
cList.SetItem(nRow, 1, TVIF_TEXT, "1234", 0, 0, 0, 0);
cList.SetItem(nRow, 2, TVIF_TEXT, "1234", 0, 0, 0, 0);

//test code
nRow = cList.GetItemCount();
csTemp = cList.GetItemText(0,1);

CListView::OnInitialUpdate();

}
...全文
233 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gbcin 2012-08-23
  • 打赏
  • 举报
回复
是report。

都没有使用LVS_OWNERDAWFIXED了。

一个工程里面item可以显示,而在另一个工程里面item就不显示。。。
Eleven 2012-08-23
  • 打赏
  • 举报
回复
去掉LVS_OWNERDAWFIXED风格,你的ListCtrl是report风格吗?LVS_REPROT ?
Eleven 2012-08-23
  • 打赏
  • 举报
回复
LVS_OWNERDRAWFIXED
:
LVS_OWNERDRAWFIXED
The owner window can paint items in report view. The list-view control sends a WM_DRAWITEM message to paint each item; it does not send separate messages for each subitem. The iItemData member of the DRAWITEMSTRUCT structure contains the item data for the specified list-view item.

需要自己自绘的的,你又没有自绘,添加处理DrawItem虚函数,所以当然显示不了。
gbcin 2012-08-23
  • 打赏
  • 举报
回复
不能使用LVS_OWNERDRAWFIXED。

新建了个单文档工程,一样的code,结果item就可以显示。。。

有高手能给解释下么。
gbcin 2012-08-22
  • 打赏
  • 举报
回复
在style里面加了LVS_OWNERDRAWFIXED,还是没有item显示出来。

lStyle = GetWindowLong(cList.m_hWnd, GWL_STYLE);
lStyle &= ~LVS_TYPEMASK;
lStyle |= LVS_REPORT;
lStyle |= LVS_OWNERDRAWFIXED;
SetWindowLong(cList.m_hWnd, GWL_STYLE, lStyle);

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧