This commit is contained in:
193
StockServer/MessagesView.cpp
Normal file
193
StockServer/MessagesView.cpp
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
// MessagesView.cpp : implementation of the CMessagesView class
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include "StockServer.h"
|
||||||
|
|
||||||
|
#include "MessagesView.h"
|
||||||
|
//#include "UserListView.h"
|
||||||
|
#include "..\\Common\\LCLayout.h"
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define new DEBUG_NEW
|
||||||
|
#undef THIS_FILE
|
||||||
|
static char THIS_FILE[] = __FILE__;
|
||||||
|
#endif
|
||||||
|
enum eClientMessagesView {
|
||||||
|
MESSAGESVIEW_COL_TIME = 0,
|
||||||
|
MESSAGESVIEW_COL_NAME,
|
||||||
|
MESSAGESVIEW_COL_MESSAGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMessagesView
|
||||||
|
|
||||||
|
IMPLEMENT_DYNCREATE(CMessagesView, CListView)
|
||||||
|
|
||||||
|
BEGIN_MESSAGE_MAP(CMessagesView, CListView)
|
||||||
|
//{{AFX_MSG_MAP(CMessagesView)
|
||||||
|
ON_WM_CREATE()
|
||||||
|
ON_WM_DESTROY()
|
||||||
|
ON_WM_PAINT()
|
||||||
|
//}}AFX_MSG_MAP
|
||||||
|
// Standard printing commands
|
||||||
|
END_MESSAGE_MAP()
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMessagesView construction/destruction
|
||||||
|
|
||||||
|
CMessagesView::CMessagesView()
|
||||||
|
{
|
||||||
|
// TODO: add construction code here
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CMessagesView::~CMessagesView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CMessagesView::PreCreateWindow(CREATESTRUCT& cs)
|
||||||
|
{
|
||||||
|
cs.style |= LVS_REPORT;
|
||||||
|
cs.style |= LVS_SHOWSELALWAYS;
|
||||||
|
cs.style |= LVS_SINGLESEL;
|
||||||
|
|
||||||
|
return CListView::PreCreateWindow(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMessagesView diagnostics
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
void CMessagesView::AssertValid() const
|
||||||
|
{
|
||||||
|
CListView::AssertValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMessagesView::Dump(CDumpContext& dc) const
|
||||||
|
{
|
||||||
|
CListView::Dump(dc);
|
||||||
|
}
|
||||||
|
#endif //_DEBUG
|
||||||
|
|
||||||
|
void CMessagesView::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int CMessagesView::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
||||||
|
{
|
||||||
|
if (CListView::OnCreate(lpCreateStruct) == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
CString szBuf;
|
||||||
|
CListCtrl& lc = GetListCtrl();
|
||||||
|
lc.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_SUBITEMIMAGES);
|
||||||
|
|
||||||
|
// insert columns
|
||||||
|
lc.InsertColumn(MESSAGESVIEW_COL_TIME, "시간", LVCFMT_LEFT, 130);
|
||||||
|
lc.InsertColumn(MESSAGESVIEW_COL_NAME, "이름", LVCFMT_LEFT, 130);
|
||||||
|
lc.InsertColumn(MESSAGESVIEW_COL_MESSAGE, "내용", LVCFMT_LEFT, 280);
|
||||||
|
|
||||||
|
CLCLayout::RestoreLayout(&lc, "MessagesView");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMessagesView::OnDestroy()
|
||||||
|
{
|
||||||
|
CLCLayout::SaveLayout(&GetListCtrl(), "MessagesView");
|
||||||
|
CListView::OnDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMessagesView::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(MESSAGESVIEW_COL_TIME, &pCol);
|
||||||
|
|
||||||
|
szBuf = "이름";
|
||||||
|
pCol.cchTextMax = szBuf.GetLength();
|
||||||
|
pCol.pszText = szBuf.GetBuffer(pCol.cchTextMax);
|
||||||
|
szBuf.ReleaseBuffer();
|
||||||
|
lc.SetColumn(MESSAGESVIEW_COL_NAME, &pCol);
|
||||||
|
|
||||||
|
szBuf = "내용";
|
||||||
|
pCol.cchTextMax = szBuf.GetLength();
|
||||||
|
pCol.pszText = szBuf.GetBuffer(pCol.cchTextMax);
|
||||||
|
szBuf.ReleaseBuffer();
|
||||||
|
lc.SetColumn(MESSAGESVIEW_COL_MESSAGE, &pCol);
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMessagesView::ClearView()
|
||||||
|
{
|
||||||
|
CListCtrl& lc = GetListCtrl();
|
||||||
|
lc.DeleteAllItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMessagesView::AddMessage(CString szTime, CString szName, CString szMessage)
|
||||||
|
{
|
||||||
|
CListCtrl& lc = GetListCtrl();
|
||||||
|
lc.InsertItem(MESSAGESVIEW_COL_TIME, szTime, 0);
|
||||||
|
|
||||||
|
LV_ITEM lvi2;
|
||||||
|
lvi2.mask = LVIF_TEXT;// | LVIF_IMAGE;
|
||||||
|
lvi2.iItem = MESSAGESVIEW_COL_TIME; //item to set
|
||||||
|
lvi2.iSubItem = MESSAGESVIEW_COL_NAME;
|
||||||
|
lvi2.pszText = szName.GetBuffer(szName.GetLength());
|
||||||
|
szName.ReleaseBuffer();
|
||||||
|
lvi2.cchTextMax = szName.GetLength();
|
||||||
|
//lvi2.iImage = uSignIcon == -1 ? 2 : uSignIcon + 3; //image index
|
||||||
|
lc.SetItem(&lvi2);
|
||||||
|
|
||||||
|
LV_ITEM lvi3;
|
||||||
|
lvi3.mask = LVIF_TEXT;// | LVIF_IMAGE;
|
||||||
|
lvi3.iItem = MESSAGESVIEW_COL_TIME; //item to set
|
||||||
|
lvi3.iSubItem = MESSAGESVIEW_COL_MESSAGE;
|
||||||
|
lvi3.pszText = szMessage.GetBuffer(szMessage.GetLength());
|
||||||
|
szMessage.ReleaseBuffer();
|
||||||
|
lvi3.cchTextMax = szMessage.GetLength();
|
||||||
|
//lvi3.iImage = 1; //image index
|
||||||
|
lc.SetItem(&lvi3);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user