📄 mfctestdlg.cpp
字号:
// mfctestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "mfctest.h"
#include "mfctestDlg.h"
#include "ClientSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMfctestDlg dialog
CMfctestDlg::CMfctestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMfctestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMfctestDlg)
m_sAddress = _T("");
m_sRecv = _T("");
m_sSend = _T("");
m_sPort = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMfctestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMfctestDlg)
DDX_Control(pDX, IDC_TCP, m_btTCP);
DDX_Text(pDX, IDC_ADDRESS, m_sAddress);
DDX_Text(pDX, IDC_NETRECV, m_sRecv);
DDX_Text(pDX, IDC_NETSEND, m_sSend);
DDX_Text(pDX, IDC_PORT, m_sPort);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMfctestDlg, CDialog)
//{{AFX_MSG_MAP(CMfctestDlg)
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_BN_CLICKED(IDC_CONNECT, OnConnect)
ON_MESSAGE(SOCK_ONRECEIVE, OnReceive)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMfctestDlg message handlers
BOOL CMfctestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
m_ClientSocket = new CClientSocket(this);
m_ClientSocket->SetEolFormat(CCESocket::EOL_CR);
m_btTCP.SetCheck(1);
m_sAddress = "10.137.85.198";
m_sPort = "3000";
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMfctestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
}
void CMfctestDlg::OnOK()
{
// TODO: Add extra validation here
if(m_ClientSocket->GetSocketState() > CCESocket::CREATED)
Send();
// CDialog::OnOK();
}
void CMfctestDlg::OnConnect()
{
// TODO: Add your control notification handler code here
int sockType;
UINT port;
//AfxMessageBox(_T("1fdsafdafd"));
//If it's already connected: disconnect.
if(m_ClientSocket->GetSocketState() > CCESocket::CREATED)
{
m_ClientSocket->Disconnect();
GetDlgItem(IDC_CONNECT)->SetWindowText(_T("Connect"));
return;
}
AfxMessageBox(_T("2fdsafdafd"));
UpdateData();
if(m_btTCP.GetCheck() == 1)
sockType = SOCK_STREAM;
else
sockType = SOCK_DGRAM;
port = _wtoi(m_sPort);
if(m_ClientSocket->Create(sockType))
if(m_ClientSocket->Connect(m_sAddress, port))
{
GetDlgItem(IDC_CONNECT)->SetWindowText(_T("Disconnect"));
return;
}
m_ClientSocket->Disconnect();
AfxMessageBox(_T("3fdsafdafd"));
}
void CMfctestDlg::Send()
{
UpdateData();
m_ClientSocket->SendLine(m_sSend);
}
LRESULT CMfctestDlg::OnReceive(WPARAM wParam, LPARAM lParam)
{
CString str, temp;
while(m_ClientSocket->GetDataSize() > 0 && m_ClientSocket->ReadString(temp))
str += " "+temp;
GetDlgItem(IDC_NETRECV)->SetWindowText(str);
return 0;
}
LRESULT CMfctestDlg::OnDisconnect(WPARAM wParam, LPARAM lParam)
{
GetDlgItem(IDC_NETRECV)->SetWindowText(_T("Disconnected!"));
GetDlgItem(IDC_CONNECT)->SetWindowText(_T("Connect"));
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -