📄 testserverdlg.cpp
字号:
// TestServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TestServer.h"
#include "TestServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestServerDlg dialog
CTestServerDlg::CTestServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestServerDlg)
m_edit2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestServerDlg)
DDX_Control(pDX, IDC_BUTTON2, m_button2);
DDX_Control(pDX, IDC_COMBO4, m_combo4);
DDX_Control(pDX, IDC_COMBO3, m_combo3);
DDX_Control(pDX, IDC_COMBO2, m_combo2);
DDX_Control(pDX, IDC_COMBO1, m_combo1);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
DDX_Control(pDX, IDC_BUTTON1, m_button1);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestServerDlg, CDialog)
//{{AFX_MSG_MAP(CTestServerDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestServerDlg message handlers
BOOL CTestServerDlg::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
// TODO: Add extra initialization here
this->m_combo1.ShowWindow( SW_HIDE );
this->m_combo2.ShowWindow( SW_HIDE );
this->m_combo3.ShowWindow( SW_HIDE );
this->m_combo4.ShowWindow( SW_HIDE );
this->m_button2.ShowWindow( SW_HIDE );
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestServerDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestServerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestServerDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char PortStr[5];
this->m_edit1.GetLine(0, PortStr);
int port = atoi( PortStr);
if( m_sockListen.Create(port,SOCK_STREAM ) )
AfxMessageBox("create成功!");
else
AfxMessageBox("create失败 !");
if( m_sockListen.Listen(1) )
AfxMessageBox("listen成功 !");
else
AfxMessageBox("listen失败 !");
if( m_sockListen.Accept(m_sockSend) )
AfxMessageBox("accept成功,请选择参数 !");
else
AfxMessageBox("accept失败 !");
m_sockListen.Close();
this->m_combo1.ShowWindow( SW_SHOW );
this->m_combo2.ShowWindow( SW_SHOW );
this->m_combo3.ShowWindow( SW_SHOW );
this->m_combo4.ShowWindow( SW_SHOW );
this->m_button2.ShowWindow(SW_SHOW );
}
void CTestServerDlg::OnButton2()
{
// TODO: Add your control notification handler code here
UpdateData( TRUE );
char DataStr[5];
DataStr[0] = 0x11; //设备代号
DataStr[1] = this->m_combo1.GetCurSel() + 1 ; //测试通路号
switch( this->m_combo2.GetCurSel() ) //码速率
{
case 0: DataStr[2] = (int)0x55 ; break;
case 1: DataStr[2] = (char)-86 ; break; //0xAA == 10101010 == -86
}
CString FirstByte; //首字节
this->m_combo3.GetWindowText(FirstByte);
int FB = atoi ( FirstByte );
DataStr[3] = FB;
CString Length; //数据长度
this->m_combo4.GetWindowText( Length );
int L = atoi ( Length );
DataStr[4] = L;
m_sockSend.Send( DataStr, 5, 0 );
UpdateData ( FALSE ) ;
}
void CTestServerDlg::OnButton3() // 退出 按钮
{
// TODO: Add your control notification handler code here
ASSERT(this != NULL);
this->SendMessage(WM_CLOSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -