📄 wincltalldlg.cpp
字号:
// winCltAllDlg.cpp : implementation file
//
#include "stdafx.h"
#include "winCltAll.h"
#include "winCltAllDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWinCltAllDlg dialog
CWinCltAllDlg::CWinCltAllDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWinCltAllDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWinCltAllDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWinCltAllDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWinCltAllDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWinCltAllDlg, CDialog)
//{{AFX_MSG_MAP(CWinCltAllDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(ID_connectServer, OnconnectServer)
ON_BN_CLICKED(ID_cmdSendShort, OncmdSendShort)
ON_BN_CLICKED(ID_cmdSendLong, OncmdSendLong)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWinCltAllDlg message handlers
BOOL CWinCltAllDlg::OnInitDialog()
{
char buff[255];
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
GetDlgItem(IDC_serverIP)->SetWindowText(REMOTE_SERVER_IPBUFF);
sprintf(buff,"%d",REMOTE_SERVER_PORT);
GetDlgItem(IDC_server_port)->SetWindowText(buff);
sprintf(buff,"0x%04x",DFT_CMD_NUM);
GetDlgItem(IDC_cmdNumLong)->SetWindowText(buff);
GetDlgItem(IDC_cmdNumShort)->SetWindowText(buff);
sprintf(buff,"%d",NET_CMD_HEADLEN);
GetDlgItem(IDC_cmdLenLong)->SetWindowText(buff);
GetDlgItem(IDC_cmdLenShort)->SetWindowText(buff);
GetDlgItem(IDC_cmdFileLong)->SetWindowText(DFT_FILE_NAME);
sprintf(buff,"0x%02x",DFT_CMD_PARAM);
GetDlgItem(IDC_cmdParam1Short)->SetWindowText(buff);
GetDlgItem(IDC_cmdParam2Short)->SetWindowText(buff);
GetDlgItem(IDC_cmdParam3Short)->SetWindowText(buff);
GetDlgItem(IDC_cmdParam4Short)->SetWindowText(buff);
GetDlgItem(IDC_cmdNumReturn)->SetWindowText(DFT_CMD_RETURN);
GetDlgItem(IDC_cmdLenReturn)->SetWindowText(DFT_CMD_RETURN);
GetDlgItem(IDC_cmdParam1Return)->SetWindowText(DFT_CMD_RETURN);
GetDlgItem(IDC_cmdParam2Return)->SetWindowText(DFT_CMD_RETURN);
GetDlgItem(IDC_cmdParam3Return)->SetWindowText(DFT_CMD_RETURN);
GetDlgItem(IDC_cmdParam4Return)->SetWindowText(DFT_CMD_RETURN);
GetDlgItem(ID_cmdSendLong)->EnableWindow(FALSE);
GetDlgItem(ID_cmdSendShort)->EnableWindow(FALSE);
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 CWinCltAllDlg::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 CWinCltAllDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWinCltAllDlg::OnconnectServer()
{
// TODO: Add your control notification handler code here
CString buff;
int serverport;
BOOL flag;
cltSkt.ShutDown(2);
cltSkt.m_hSocket=INVALID_SOCKET;
flag = cltSkt.Create(0,SOCK_STREAM,FD_CONNECT);
if(flag==0)
{
MessageBox("unable to create!");
return;
}
/*get IP and port number from dialog box*/
GetDlgItem(IDC_server_port)->GetWindowText(buff);
serverport = atoi((LPCTSTR)buff);
GetDlgItem(IDC_serverIP)->GetWindowText(buff);
cltSkt.Connect(buff,serverport);
}
void CWinCltAllDlg::OncmdSendShort()
{
// TODO: Add your control notification handler code here
GetDlgItem(ID_cmdSendLong)->EnableWindow(FALSE);
GetDlgItem(ID_cmdSendShort)->EnableWindow(FALSE);
cltSkt.netSendSource = NET_SEND_SHORT;
cltSkt.stateSend = STAT_SEND_BEGIN;
cltSkt.AsyncSelect(FD_WRITE|FD_CLOSE);
}
void CWinCltAllDlg::OncmdSendLong()
{
// TODO: Add your control notification handler code here
GetDlgItem(ID_cmdSendLong)->EnableWindow(FALSE);
GetDlgItem(ID_cmdSendShort)->EnableWindow(FALSE);
cltSkt.netSendSource = NET_SEND_LONG;
cltSkt.stateSend = STAT_SEND_BEGIN;
cltSkt.AsyncSelect(FD_WRITE|FD_CLOSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -