📄 62_s1_clientdlg.cpp
字号:
// 62_s1_clientDlg.cpp : implementation file
//
#include "stdafx.h"
#include "62_s1_client.h"
#include "62_s1_clientDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int flag=0;
/////////////////////////////////////////////////////////////////////////////
// CMy62_s1_clientDlg dialog
CMy62_s1_clientDlg::CMy62_s1_clientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy62_s1_clientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy62_s1_clientDlg)
m_szSend = _T("");
m_port = 0;
m_address = _T("10.23.6.14");
m_time = 0;
m_delaytime = 100;
m_endport = 6801;
m_packetsize = 500;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
static flag=1;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy62_s1_clientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy62_s1_clientDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_CtrlPro);
DDX_Text(pDX, IDC_EDIT1, m_szSend);
DDX_Text(pDX, IDC_EDIT3, m_port);
DDV_MinMaxInt(pDX, m_port, 0, 65535);
DDX_Text(pDX, IDC_EDIT2, m_address);
DDV_MaxChars(pDX, m_address, 15);
DDX_Text(pDX, IDC_EDIT4, m_time);
DDV_MinMaxInt(pDX, m_time, 0, 65535);
DDX_Text(pDX, IDC_EDIT5, m_delaytime);
DDV_MinMaxInt(pDX, m_delaytime, 0, 65535);
DDX_Text(pDX, IDC_EDIT6, m_endport);
DDV_MinMaxInt(pDX, m_endport, 0, 65535);
DDX_Text(pDX, IDC_EDIT7, m_packetsize);
DDV_MinMaxInt(pDX, m_packetsize, 0, 65535);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy62_s1_clientDlg, CDialog)
//{{AFX_MSG_MAP(CMy62_s1_clientDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_Send, OnSend)
ON_BN_CLICKED(IDC_Send2, OnSend2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy62_s1_clientDlg message handlers
BOOL CMy62_s1_clientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData(1);
m_sockSend.Create(m_port,SOCK_DGRAM,NULL);
m_sockSend.Bind(m_port,m_address);
SetTimer(1,m_delaytime,NULL);
propos = 0;
m_CtrlPro.SetRange(0, 100);
m_CtrlPro.SetPos(0);
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 CMy62_s1_clientDlg::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 CMy62_s1_clientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy62_s1_clientDlg::OnTimer(UINT nIDEvent)
{
if( nIDEvent == 1 )
{
if(flag%2==1)
{
UpdateData(1);
SetTimer(1,m_delaytime,NULL);
if(m_time<=0)
{
static iIndex=0;
char szSend[20];
sprintf(szSend,"%07d",iIndex++);
int iSend= m_sockSend.SendTo(szSend,m_packetsize,m_endport,m_address,0);
TRACE("sent %d byte\n",iSend);
m_szSend=szSend;
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
propos ++;
if( propos % 100 == 0 )
propos = 0;
m_CtrlPro.SetPos(propos);
}
}
}
void CMy62_s1_clientDlg::OnSend()
{
// TODO: Add your control notification handler code here
UpdateData(1);
SetTimer(1,m_delaytime,NULL);
static Index=0;
char szSend[20];
sprintf(szSend,"%07d",m_time*(++Index));
//propos = 0;
//m_CtrlPro.SetPos(0);
for(int i=0;i<m_time;i++)
{
int iSend= m_sockSend.SendTo(szSend,m_packetsize,m_endport,m_address,0);
TRACE("sent %d byte\n",iSend);
m_szSend=szSend;
}
UpdateData(0);
}
void CMy62_s1_clientDlg::OnSend2()
{
// TODO: Add your control notification handler code here
UpdateData(1);
flag+=1;
if(flag%2==1)
{
m_time=0;
UpdateData(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -