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

📄 senderview.cpp

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

#include "stdafx.h"
#include "Sender.h"

#include "SenderDoc.h"
#include "SenderView.h"

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

#define PORT 2000

/////////////////////////////////////////////////////////////////////////////
// CSenderView

IMPLEMENT_DYNCREATE(CSenderView, CFormView)

BEGIN_MESSAGE_MAP(CSenderView, CFormView)
	//{{AFX_MSG_MAP(CSenderView)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_SEND, OnSend)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSenderView construction/destruction

CSenderView::CSenderView()
	: CFormView(CSenderView::IDD)
{
	//{{AFX_DATA_INIT(CSenderView)
	m_sData = _T("");
	m_sIP = _T("172.168.1.18");
	//}}AFX_DATA_INIT
	// TODO: add construction code here
	m_pSocket = new CSocket();
}

CSenderView::~CSenderView()
{
	delete m_pSocket;
}

void CSenderView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSenderView)
	DDX_Text(pDX, IDC_DATA, m_sData);
	DDX_Text(pDX, IDC_IP, m_sIP);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

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

	// 创建套接字
	m_pSocket->Create(0);
}

/////////////////////////////////////////////////////////////////////////////
// CSenderView printing

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

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSenderView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CSenderView message handlers

void CSenderView::OnStart() 
{
	UpdateData(TRUE);

	// 与服务器建立连接
	m_pSocket->Connect(m_sIP, PORT);
}

void CSenderView::OnSend() 
{
	UpdateData(TRUE);
	
	// 发送数据
	m_pSocket->Send(m_sData, m_sData.GetLength());
}

⌨️ 快捷键说明

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