WTL学习(3)

这本WTL指南的电子书是有附件的,在vckbase上,不过现在下载的话应该是需要注册

再者想尽量自己动手编写一下,那些附件Demo下载运行总是觉得不够深入

还是DDX部分

有如下代码

LRESULT CMainDlg::OnListItemchanged ( NMHDR* phdr )

{

NMLISTVIEW* pnmlv = (NMLISTVIEW*) phdr;

int nSelItem = m_wndList.GetSelectedIndex();

CString sMsg;

 

// If no item is selected, show "none". Otherwise, show its index.

if ( -1 == nSelItem )

      sMsg = _T("(none)");

else

      sMsg.Format ( _T("%d"), nSelItem );

SetDlgItemText ( IDC_SEL_ITEM, sMsg );

return 0;  // retval ignored

}

其他的不重要,问题出现在int nSelItem = m_wndList.GetSelectedIndex();这句

编译能能过,执行也能启动,这是一个List Control控件,想要在选定上面的某一项时,让下面IDC_SEL_ITEM静态文本框显示变化,但结果一旦选定,程序就崩溃

按提示是在这里

//atlctrls.h

 int GetSelectedIndex() const
 {
  ATLASSERT(::IsWindow(m_hWnd));
  ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
  return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
 }

 

ATLASSERT((GetStyle()&LVS_SINGLESEL)!=0);这一句崩掉了

找答案

http://www.codeguru.com/forum/archive/index.php/t-389564.html

Hello, I am sorry, but I am a C++ medium newbie, and I should continue the work of a friend.
It s a kind of trace and there is a ListView with processes. When I click on one of this processes, I get the Error the Assertation failed.
It always happens in the second of these two lines...

ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);


GetStyle points to zero put why ??
Thanks a lot

看来是一样的,答案如下

 

Can i ask you two things.
From which cpp file you are getting this assertion message.
I guss it would be a list control class(猜得很对), if so is it your own list control class or MFC class.
are you subclassing the list control using your own or by some one else list control class.
what my guss is you are using a derived list contol class. and this control class is only supporting multi selection.(这个感觉就不对了,应该是只支持单一选择,而资源却没有设定成单选的) but you may not have set your list control resource multiselection property.
i am not sure its a guss only. think in this way also. it may help you :)

试一试:

 框没有设成单选,更改如下,添加上Single selection就行了。

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值