online.cpp

来自「基于winsock的聊天程序」· C++ 代码 · 共 94 行

CPP
94
字号
/ OnLine.cpp : implementation file
//

#include "stdafx.h"
#include "chatclient.h"
#include "OnLine.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COnLine dialog

COnLine::COnLine()
{
}

COnLine::~COnLine()
{
	delete m_ListCtrl;
}

BEGIN_MESSAGE_MAP(COnLine, CDialogBar)
	//{{AFX_MSG_MAP(COnLine)
	ON_WM_CREATE()
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COnLine message handlers
int COnLine::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialogBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	CRect rect;
	GetClientRect(&rect);
	rect.left += 8;
	rect.top += 15;
	rect.right -= 8;
	rect.bottom -= 8;
	
	m_ListCtrl = new COnlineList;
	if (!m_ListCtrl->Create(WS_CHILD | WS_VISIBLE | LVS_REPORT,
		rect, this, IDC_LISTBOX))
	{
		TRACE0("Failed to create view for CMyBarLeft\n");
		return -1;
	}

	m_ListCtrl->ModifyStyleEx(0, WS_EX_CLIENTEDGE);
	AddExStyle(LVS_EX_FULLROWSELECT | LVS_OWNERDRAWFIXED);
	
	int i;
	LV_COLUMN lvc;

	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	CString	strTemp[2] = {"名称", "IP"};
	int size[2] = {140,40};
	for(i = 0; i < 2; i++)
	{
		lvc.iSubItem = i;
		lvc.pszText = (char*)(LPCTSTR)strTemp[i];
		lvc.cx = size[i];
		lvc.fmt = LVCFMT_LEFT;
		m_ListCtrl->InsertColumn(i, &lvc);
	}
	
	return 0;
}

void COnLine::AddExStyle(DWORD dwNewStyle)
{
	DWORD dwStyle = ::SendMessage (m_ListCtrl->m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
	dwStyle |= dwNewStyle;

	::SendMessage (m_ListCtrl->m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
}



void COnLine::OnSize(UINT nType, int cx, int cy) 
{
	//CDialogBar::OnSize(nType, cx, cy);
	if(m_ListCtrl->m_hWnd)
		m_ListCtrl->SetWindowPos(this,0,0,cx-15,cy-25,SWP_NOZORDER|SWP_NOMOVE);
	// TODO: Add your message handler code here
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?