CListCtrl 不显示列名?

代码片段:

类里面定义:

CListCtrl m_List;
void CDevStateDlg::InitListCtrl(void)
{
	
	LONG styles;
	styles = GetWindowLong(m_List.m_hWnd,GWL_STYLE);//获取窗口风格
	SetWindowLong(m_List.m_hWnd,GWL_STYLE,styles | LVS_REPORT);
	m_List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_List.InsertColumn(0,"时间",LVCFMT_LEFT,200);
	m_List.InsertColumn(1,"数量",LVCFMT_LEFT,200);
	m_List.InsertColumn(2,"备注",LVCFMT_LEFT,200);

	
}

不显示列可能是没加前面的两行:

     LONG styles;
    styles = GetWindowLong(m_List.m_hWnd,GWL_STYLE);//获取窗口风格
    SetWindowLong(m_List.m_hWnd,GWL_STYLE,styles | LVS_REPORT);

然后再接收到消息后添加行:

BOOL CDevStateDlg::PreTranslateMessage(MSG* pMsg)
 {
	 // TODO: Add your specialized code here and/or call the base class
	 if(pMsg->message==WM_NUM) 
	 {
		 CString str;
		 CTime ctime = CTime::GetCurrentTime();
		 CString strTime = ctime.Format("%Y-%m-%d:%H:%M:%S");
		 str.Format("%d", pMsg->wParam);
		 int iIndex = m_List.GetItemCount();
		 m_List.InsertItem(iIndex,strTime);
		 m_List.SetItemText(iIndex,1,str);
		 if (pMsg->wParam == 0)
		 {
			  m_List.SetItemText(iIndex,2,"失败");
		 } 
		 else
		 {
			  m_List.SetItemText(iIndex,2,"成功");
		 }
		
	 }

	 return CDialogEx::PreTranslateMessage(pMsg);
 }

         接收到WM_NUM消息后,处理界面:

         CTime ctime = CTime::GetCurrentTime();
         CString strTime = ctime.Format("%Y-%m-%d:%H:%M:%S");//获取系统时间

          str.Format("%d", pMsg->wParam);//整型转CString

         int iIndex = m_List.GetItemCount();
         m_List.InsertItem(iIndex,strTime);
         m_List.SetItemText(iIndex,1,str);//追加到下一行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值