单文档,在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();

}
...全文
332 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);
内容概要:本文研究了基于粒子群算法的风电-水电(抽水蓄能)联合优化调度问题,旨在通过智能优化算法实现新能源与储能系统的协同调度,提升电力系统运行效率与稳定性。研究采用粒子群优化(PSO)算法对风电和抽水蓄能电站的出力进行联合优化,以最小化系统运行成本、减少弃风弃电、提高可再生能源消纳能力为目标,构建了包含风电出力不确定性、水电站水量平衡、抽水蓄能机组运行约束在内的多目标优化模型,并通过Matlab编程实现算法求解与仿真验证。文中详细探讨了算法参数设置、收敛性分析及优化结果的合理性,展示了该方法在实际电力系统调度中的应用潜力与工程价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事新能源调度、智能优化算法应用的工程技术人员。; 使用场景及目标:①应用于含大规模风电接入的电力系统中,实现风电与抽水蓄能的协调调度;②为电力系统经济调度、可再生能源消纳、储能优化配置等研究提供算法支持与仿真案例;③作为智能优化算法在能源系统中应用的教学与研究参考资料。; 阅读建议:读者应结合Matlab代码与文中模型描述,理解算法实现细节,建议在学习过程中动手调试代码,尝试修改目标函数或约束条件以观察优化结果变化,从而深入掌握粒子群算法在能源调度中的应用方法。

15,976

社区成员

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

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