ListCtrlView.cpp
上传用户:weimei12
上传日期:2022-08-11
资源大小:185k
文件大小:3k
- // ListCtrlView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SimpleMail.h"
- #include "ListCtrlView.h"
- // CListCtrlView
- IMPLEMENT_DYNCREATE(CListCtrlView, CFormView)
- CListCtrlView::CListCtrlView()
- : CFormView(CListCtrlView::IDD)
- {
- }
- CListCtrlView::~CListCtrlView()
- {
- }
- void CListCtrlView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LIST, m_listCtrl);
- }
- BEGIN_MESSAGE_MAP(CListCtrlView, CFormView)
- ON_WM_SIZE()
- ON_NOTIFY(LVN_ITEMACTIVATE, IDC_LIST, &CListCtrlView::OnLvnItemActivateList)
- END_MESSAGE_MAP()
- // CListCtrlView diagnostics
- #ifdef _DEBUG
- void CListCtrlView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- #ifndef _WIN32_WCE
- void CListCtrlView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif
- #endif //_DEBUG
- // CListCtrlView message handlers
- void CListCtrlView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- // TODO: Add your specialized code here and/or call the base class
- //SetDlgCtrlID(VIEW_LISTCTRL);
- CRect rect;
- GetClientRect(&rect);
- m_listCtrl.InsertColumn(0, _T("From"), LVCFMT_LEFT, rect.Width() / 4);
- m_listCtrl.InsertColumn(1, _T("Subject"), LVCFMT_LEFT, rect.Width() / 4);
- m_listCtrl.InsertColumn(2, _T("Date"), LVCFMT_LEFT, rect.Width() / 4);
- m_listCtrl.InsertColumn(3, _T("Size"), LVCFMT_LEFT, rect.Width() / 4);
- m_listCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE
- | LVS_EX_FLATSB);//显示表格线等设置
- }
- void CListCtrlView::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- CFormView::ShowScrollBar(SB_VERT,FALSE);
- CFormView::ShowScrollBar(SB_HORZ,FALSE);
- if (GetSafeHwnd())
- {
- if (m_listCtrl.GetSafeHwnd())
- {
- CRect rect(0,0,cx,cy);
- m_listCtrl.MoveWindow(&rect);
- }
- }
- }
- void CListCtrlView::InsertRowItem(CString strFrom, CString strSubject, CString strDate, CString strSize)
- {
- LVITEM lvItem;
- lvItem.mask = LVIF_TEXT;
- lvItem.iItem = 0;
- lvItem.iSubItem = 0;
- lvItem.pszText = strFrom.GetBuffer(strFrom.GetLength());
- int nRes = -2;
- nRes = m_listCtrl.InsertItem(&lvItem);
- strFrom.ReleaseBuffer();
- lvItem.iItem = nRes;
- lvItem.pszText = strSubject.GetBuffer(strSubject.GetLength());
- lvItem.iSubItem = 1;
- m_listCtrl.SetItem(&lvItem);
- strSubject.ReleaseBuffer();
- lvItem.iItem = nRes;
- lvItem.pszText = strDate.GetBuffer(strDate.GetLength());
- lvItem.iSubItem = 2;
- m_listCtrl.SetItem(&lvItem);
- strDate.ReleaseBuffer();
- lvItem.iItem = nRes;
- lvItem.pszText = strSize.GetBuffer(strSize.GetLength());
- lvItem.iSubItem = 3;
- m_listCtrl.SetItem(&lvItem);
- strSize.ReleaseBuffer();
- }
- BOOL CListCtrlView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Add your specialized code here and/or call the base class
- cs.style |= LVS_REPORT;
- return CFormView::PreCreateWindow(cs);
- }
- void CListCtrlView::OnLvnItemActivateList(NMHDR *pNMHDR, LRESULT *pResult)
- {
- LPNMITEMACTIVATE pNMIA = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
- // TODO: Add your control notification handler code here
- ::SendMessage(AfxGetMainWnd()->m_hWnd, WM_LIST_SELECTED, pNMIA->iItem, 0);
- *pResult = 0;
- }