⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 meetingview.cpp

📁 聊天的
💻 CPP
字号:
// MeetingView.cpp : implementation of the CMeetingView class
//

#include "stdafx.h"
#include "Meeting.h"

#include "Shape.h"
#include "MeetingView.h"
#include "MeetingDoc.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMeetingView
CMeetingView* g_pView=NULL;
IMPLEMENT_DYNCREATE(CMeetingView, CScrollView)

BEGIN_MESSAGE_MAP(CMeetingView, CScrollView)
	//{{AFX_MSG_MAP(CMeetingView)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_SIZE()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
	ON_MESSAGE(USER_MESSAGE_PLAY, OnSendAudio)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMeetingView construction/destruction

CMeetingView::CMeetingView()
{

	g_pView=this;
}

CMeetingView::~CMeetingView()
{
}

BOOL CMeetingView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMeetingView drawing

void CMeetingView::OnDraw(CDC* pDC)
{
	CMeetingDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CTypedPtrList<CObList,CShape*>& shapeList=pDoc->m_shapeList;
	POSITION pos=shapeList.GetHeadPosition();

	while(pos!=NULL)
	{
		CShape* pShape=shapeList.GetNext(pos);
		pShape->DrawShape(pDC);
	}}

void CMeetingView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CMeetingView printing

BOOL CMeetingView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMeetingView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMeetingView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMeetingView diagnostics

#ifdef _DEBUG
void CMeetingView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMeetingView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CMeetingDoc* CMeetingView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMeetingDoc)));
	return (CMeetingDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMeetingView message handlers

void CMeetingView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CMeetingDoc* pDoc=GetDocument();
	CClientDC dc(this);
	CPen* pOldPen;

	OnPrepareDC(&dc);
	dc.DPtoLP(&point);
	pOldPen=dc.SelectObject(pDoc->GetCurrentPen());

	switch(pDoc->m_shapeCur)
	{
	case PICK:
		break;
	case HAND:
		m_pShape=new CHand(pDoc->m_nPenWidth,
			pDoc->m_colorPen);
		pDoc->m_shapeList.AddTail((CHand*)m_pShape);
		((CHand*)m_pShape)->m_pointArray.Add(point);
		SetCapture();
		m_ptPre=point;
		dc.MoveTo(m_ptPre);
		dc.LineTo(point);
		break;
	case RECTANGLE:
		m_pShape=new CRectangle(pDoc->m_nPenWidth,
			pDoc->m_colorFill,pDoc->m_colorPen,pDoc->m_bFill);
		pDoc->m_shapeList.AddTail((CRectangle*)m_pShape);
		((CRectangle*)m_pShape)->m_rectRect.left=point.x;
		((CRectangle*)m_pShape)->m_rectRect.top=point.y;
		((CRectangle*)m_pShape)->m_rectRect.right=point.x;
		((CRectangle*)m_pShape)->m_rectRect.bottom=point.y;

		SetCapture();
		m_ptPre=point;
		dc.SetROP2(R2_NOTXORPEN);
		dc.Rectangle(((CRectangle*)m_pShape)->m_rectRect.left,
			((CRectangle*)m_pShape)->m_rectRect.top,
			point.x,point.y);
		break;
	case LINE:
		m_pShape=new CLine(pDoc->m_nPenWidth,
			pDoc->m_colorPen);
		pDoc->m_shapeList.AddTail((CLine*)m_pShape);
		((CLine*)m_pShape)->m_pointStart=point;
		((CLine*)m_pShape)->m_pointEnd=point;
		SetCapture();
		m_ptPre=point;
		dc.SetROP2(R2_NOTXORPEN);
		dc.MoveTo(m_ptPre);
		dc.LineTo(point);
		break;
	case CIRCLE:
		m_pShape=new CCircle(pDoc->m_nPenWidth,
			pDoc->m_colorFill,pDoc->m_colorPen,pDoc->m_bFill);
		pDoc->m_shapeList.AddTail((CCircle*)m_pShape);
		((CCircle*)m_pShape)->m_rectCircle.top=point.y;
		((CCircle*)m_pShape)->m_rectCircle.left=point.x;
		SetCapture();
		break;
  default:
		break;
	}

	dc.SelectObject(pOldPen);

	CView::OnLButtonDown(nFlags, point);
}

void CMeetingView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CMeetingDoc* pDoc=GetDocument();
	if(GetCapture()!=this)
		return;
	switch(pDoc->m_shapeCur)
	{
	case HAND:
		ReleaseCapture();
		break;

	case PICK:

		break;
	case RECTANGLE:
		((CRectangle*)m_pShape)->m_rectRect.right=point.x;
		((CRectangle*)m_pShape)->m_rectRect.bottom=point.y;

		ReleaseCapture();
		break;
	case LINE:
		((CLine*)m_pShape)->m_pointEnd=point;
		ReleaseCapture();
		break;
	case CIRCLE:
		ReleaseCapture();
		break;

	default:
		break;
	}	

	CClientDC dc(this);

	m_pShape->DrawShape(&dc);
	pDoc->BroadcastMsg(m_pShape);
	
	
	CView::OnLButtonUp(nFlags, point);
}

void CMeetingView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if(GetCapture()!=this)
		return;
	CClientDC dc(this);
	CPen* pOldPen;
	OnPrepareDC(&dc);
	dc.DPtoLP(&point);
	CMeetingDoc* pDoc=GetDocument();
	pOldPen=dc.SelectObject(pDoc->GetCurrentPen());

	switch(pDoc->m_shapeCur)
	{
	case HAND:
		dc.MoveTo(m_ptPre);
		dc.LineTo(point);
		((CHand*)m_pShape)->m_pointArray.Add(point);
		m_ptPre=point;
		break;
	case RECTANGLE:
		dc.SetROP2(R2_NOTXORPEN);
		dc.Rectangle(((CRectangle*)m_pShape)->m_rectRect.left,
			((CRectangle*)m_pShape)->m_rectRect.top,
			m_ptPre.x,m_ptPre.y);
		dc.SetROP2(R2_NOTXORPEN);
		dc.Rectangle(((CRectangle*)m_pShape)->m_rectRect.left,
			((CRectangle*)m_pShape)->m_rectRect.top,
			point.x,point.y);
		m_ptPre=point;
		break;
	case LINE:
		dc.SetROP2(R2_NOTXORPEN);
		dc.MoveTo(((CLine*)m_pShape)->m_pointStart);
		dc.LineTo(m_ptPre);
		dc.SetROP2(R2_NOTXORPEN);
		dc.MoveTo(((CLine*)m_pShape)->m_pointStart);
		dc.LineTo(point);
		m_ptPre=point;
		break;
	case CIRCLE:
		dc.SetROP2(R2_NOTXORPEN);
		dc.Ellipse(((CCircle*)m_pShape)->m_rectCircle);
		((CCircle*)m_pShape)->m_rectCircle.bottom=point.y;
		((CCircle*)m_pShape)->m_rectCircle.right=point.x;
		dc.SetROP2(R2_NOTXORPEN);
		dc.Ellipse(((CCircle*)m_pShape)->m_rectCircle);

		break;

	default:
		break;
	}
	dc.SelectObject(pOldPen);
	
	CView::OnMouseMove(nFlags, point);
}

void CMeetingView::OnSize(UINT nType, int cx, int cy) 
{

	CScrollView::OnSize(nType, cx, cy);
	CMainFrame* pF=(CMainFrame*)AfxGetApp()->m_pMainWnd;
	if(!pF)return;
	CRect rect;
	pF->m_wndTalkBar.GetClientRect(rect);
	if(pF->m_wndTalkDlg)
	{
		CEdit* pEdit1=(CEdit*)pF->m_wndTalkDlg.GetDlgItem(IDC_EDIT1);
		pEdit1->SetWindowPos(&wndTop,0,0,rect.right-rect.left,
			rect.bottom-rect.top-30,SWP_SHOWWINDOW);
		CEdit* pEdit2=(CEdit*)pF->m_wndTalkDlg.GetDlgItem(IDC_EDIT2);
		pEdit2->SetWindowPos(&wndTop,0,rect.bottom-27
			,rect.right-rect.left-70,26,SWP_SHOWWINDOW);
		CButton* pBut=(CButton*)pF->m_wndTalkDlg.GetDlgItem(IDOK);
		pBut->SetWindowPos(&wndTop,rect.right-68,rect.bottom-27
			,68,26,SWP_SHOWWINDOW);

	}

	
}

int CMeetingView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CScrollView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	GetDocument()->m_pView=this;
	
	return 0;
}

void CMeetingView::OnSendAudio(WPARAM buf_len,LPARAM buffer)
{


	CShape* p=new CAudio((int)buf_len,(char*)buffer);
	CMeetingDoc* pDoc=GetDocument();

	POSITION pos;
	if(pDoc->m_bIsServer)
	{
		pos=pDoc->m_listClient.GetHeadPosition();
		while(pos!=NULL)
		{
			CClientSocket* pSocket=(CClientSocket*)pDoc->m_listClient.GetNext(pos);
			pSocket->SendShape(p);
			TRACE("<<---------%d,%d\n",buf_len,buffer);

		}
	}
	if(pDoc->m_bIsClient)
	{
		pDoc->m_socketClient->SendShape(p);
		TRACE("<<---------%d,%d\n",buf_len,buffer);

	}
	delete p;

}

⌨️ 快捷键说明

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