?? senderview.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 CAsyncSocket();
}
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 + -