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

📄 senderview.cpp

📁 这是一个学习WinSocket编程的程序
💻 CPP
字号:
// SenderView.cpp : implementation of the CSenderView class
//

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

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

#include "glb_fun.h"

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



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

IMPLEMENT_DYNCREATE(CSenderView, CFormView)

BEGIN_MESSAGE_MAP(CSenderView, CFormView)
	//{{AFX_MSG_MAP(CSenderView)
	ON_BN_CLICKED(IDC_SEND_BUTTON, OnSendButton)
	ON_BN_CLICKED(IDC_CLEARBUTTON, OnClearbutton)
	ON_WM_TIMER()
	//}}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_strSend = _T("");
	nTimer=0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CSenderView::~CSenderView()
{
	
}

void CSenderView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSenderView)
	DDX_Control(pDX, IDC_LIST, m_List);
	DDX_Text(pDX, IDC_SEND_EDIT, m_strSend);
	//}}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();

	CSenderApp* pApp=(CSenderApp*)AfxGetApp();
	pApp->m_pList=&m_List;
}

/////////////////////////////////////////////////////////////////////////////
// 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::OnSendButton() 
{
	// TODO: Add your control notification handler code here
	// TODO: Add your command handler code here
	
	//从编辑框获取发送的信息	
	GetDlgItemText(IDC_SEND_EDIT, str_send, sizeof(str_send));
	msglen = strlen(str_send);
	iSendno = 0;
	if (nTimer == 0)
		nTimer = SetTimer(1,100,NULL);//每隔100微秒(0.1s)产生一次时间中断

	//发送第一个数据
	Encode(str_send[iSendno], iSendno, msglen, now_send);
	SendMsg(now_send, DATA_FRAME_LEN);
	
}

void CSenderView::OnClearbutton() 
{
	// TODO: Add your control notification handler code here
	m_List.ResetContent ();
}

void CSenderView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default

	//超时(1.5秒),重发
	if (bSending)
	{
		iSendTime++;
		if (iSendTime > 15)
			SendMsg(now_send,DATA_FRAME_LEN);
	}

	CFormView::OnTimer(nIDEvent);
}


⌨️ 快捷键说明

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