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

📄 receiverview.cpp

📁 visual c++网络通信程序开发指南附带的程序所有的源码。
💻 CPP
字号:
// ReceiverView.cpp : implementation of the CReceiverView class
//

#include "stdafx.h"
#include "Receiver.h"

#include "ReceiverDoc.h"
#include "ReceiverView.h"

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

#define PORT 2000

/////////////////////////////////////////////////////////////////////////////
// CReceiverView

IMPLEMENT_DYNCREATE(CReceiverView, CFormView)

BEGIN_MESSAGE_MAP(CReceiverView, CFormView)
	//{{AFX_MSG_MAP(CReceiverView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReceiverView construction/destruction

CReceiverView::CReceiverView()
	: CFormView(CReceiverView::IDD)
{
	//{{AFX_DATA_INIT(CReceiverView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here
}

CReceiverView::~CReceiverView()
{
}

void CReceiverView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReceiverView)
	DDX_Control(pDX, IDC_DATA, m_listData);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CReceiverView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	// 创建套接字
	m_pSocket = new CListeningSocket();
	if (m_pSocket->Create(PORT, SOCK_STREAM, FD_ACCEPT) == FALSE)
	{
    	AfxMessageBox("创建套接字失败!");
		m_pSocket->Close();
	   	return;
	}

	// 侦听成功,等待连接请求
	if (m_pSocket->Listen(1) == FALSE)
	{
	    if (m_pSocket->GetLastError() == WSAEWOULDBLOCK)
		{
		  	AfxMessageBox("网络侦听失败!");
			m_pSocket->Close();
		   	return;
		}
	}	
}

/////////////////////////////////////////////////////////////////////////////
// CReceiverView printing

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

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

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

void CReceiverView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CReceiverView diagnostics

#ifdef _DEBUG
void CReceiverView::AssertValid() const
{
	CFormView::AssertValid();
}

void CReceiverView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CReceiverView message handlers

⌨️ 快捷键说明

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