// UserListView.cpp : implementation of the CUserListView class // #include "stdafx.h" #include "StockServer.h" //#include "MessagesView.h" #include "UserListView.h" #include "..\\Common\\ComData.h" #include "..\\Common\\LCLayout.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif enum eUserListView { USERLISTVIEW_COL_NAME = 0, // USERLISTVIEW_COL_TIME }; ///////////////////////////////////////////////////////////////////////////// // CUserListView IMPLEMENT_DYNCREATE(CUserListView, CListView) BEGIN_MESSAGE_MAP(CUserListView, CListView) //{{AFX_MSG_MAP(CClientMessagesView) ON_WM_CREATE() ON_WM_DESTROY() ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CUserListView construction/destruction CUserListView::CUserListView() { // TODO: add construction code here } CUserListView::~CUserListView() { } ///////////////////////////////////////////////////////////////////////////// // CUserListView drawing void CUserListView::OnPaint() { CListCtrl& lc = GetListCtrl(); Default(); if (!lc.GetItemCount()) { CDC* pDC = GetDC(); int nSavedDC = pDC->SaveDC(); CRect rc; GetClientRect(&rc); CHeaderCtrl* pHC; pHC = lc.GetHeaderCtrl(); if (pHC != NULL) { CRect rcH; pHC->GetItemRect(0, &rcH); rc.top += rcH.bottom; } pDC->FillRect(rc, &CBrush(::GetSysColor(COLOR_WINDOW))); pDC->SetBkMode(TRANSPARENT); pDC->SelectStockObject(ANSI_VAR_FONT); pDC->DrawText(CString((LPCSTR)IDS_EMPTY_LIST), rc, DT_CENTER|DT_WORDBREAK|DT_NOPREFIX| DT_NOCLIP|DT_VCENTER|DT_SINGLELINE); pDC->RestoreDC(nSavedDC); ReleaseDC(pDC); } } BOOL CUserListView::PreCreateWindow(CREATESTRUCT& cs) { cs.style |= LVS_REPORT; cs.style |= LVS_SHOWSELALWAYS; cs.style |= LVS_SINGLESEL; return CListView::PreCreateWindow(cs); } int CUserListView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CListView::OnCreate(lpCreateStruct) == -1) return -1; CListCtrl& lc = GetListCtrl(); lc.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES); // insert columns lc.InsertColumn(USERLISTVIEW_COL_NAME, "À̸§", LVCFMT_LEFT, 130); CLCLayout::RestoreLayout(&lc, "UserListView"); return 0; } void CUserListView::OnDestroy() { CLCLayout::SaveLayout(&GetListCtrl(), "UserListView"); CListView::OnDestroy(); } ///////////////////////////////////////////////////////////////////////////// // CUserListView diagnostics #ifdef _DEBUG void CUserListView::AssertValid() const { CListView::AssertValid(); } void CUserListView::Dump(CDumpContext& dc) const { CListView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CUserListView message handlers void CUserListView::UpdateCols() { CString szBuf; LVCOLUMN pCol; CListCtrl& lc = GetListCtrl(); ZeroMemory(&pCol, sizeof(LVCOLUMN)); pCol.mask = LVCF_TEXT; szBuf = "À̸§"; pCol.cchTextMax = szBuf.GetLength(); pCol.pszText = szBuf.GetBuffer(pCol.cchTextMax); szBuf.ReleaseBuffer(); lc.SetColumn(USERLISTVIEW_COL_NAME, &pCol); Invalidate(); } void CUserListView::ClearView() { CListCtrl& lc = GetListCtrl(); lc.DeleteAllItems(); } void CUserListView::UpdateClientsList(CPtrList* pClientstList) { ASSERT(pClientstList); CListCtrl& lc = GetListCtrl(); int nSelected = lc.GetNextItem(-1, LVNI_ALL|LVNI_SELECTED); lc.DeleteAllItems(); int nCount = pClientstList->GetCount(); for(int i = 0; i < nCount; i++) { sClientComInfos* pClientCom = (sClientComInfos*)pClientstList->GetAt(pClientstList->FindIndex(i)); ASSERT(pClientCom); LV_ITEM lvItem; ZeroMemory(&lvItem, sizeof(LV_ITEM)); lvItem.mask = LVIF_TEXT; // | LVIF_IMAGE; // lvItem.iImage = pComData->uSignIcon; lvItem.pszText = (LPSTR)(LPCTSTR)pClientCom->strID; // pComData->szFrom.GetBuffer(pComData->szFrom.GetLength()); lvItem.cchTextMax = pClientCom->strID.GetLength(); // pComData->szFrom.GetLength(); // pComData->szFrom.ReleaseBuffer(); lc.InsertItem(&lvItem); } // m_pMainFrame->ClearClientView(); if (nCount > 0 && nSelected > -1) { lc.SetItemState(nSelected, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); // ShowClientInfos(); } }