?? ppqtestdlg.cpp
字號:
// PPQTESTDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PPQTEST.h"
#include "PPQTESTDlg.h"
#include "DSP.h"
#include "HGF.h"
#include "PPQ.h"
#include "DSPFile.h"
#include "DSPSpider.h"
#include "SpiderWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPPQTESTDlg dialog
CPPQTESTDlg::CPPQTESTDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPPQTESTDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPPQTESTDlg)
// 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);
this->m_lphParam =NULL;
}
void CPPQTESTDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPPQTESTDlg)
DDX_Control(pDX, IDC_CHECKNET, m_checkNet);
DDX_Control(pDX, IDC_CHECKCRC, m_checkCrc);
DDX_Control(pDX, IDC_COMBOIP, m_comboIP);
DDX_Control(pDX, IDC_BTNLISTEN, m_btnListen);
DDX_Control(pDX, IDC_STATIC_SIZE, m_strFileSize);
DDX_Control(pDX, IDC_STATIC_LEN, m_strFileLen);
DDX_Control(pDX, IDC_PROGRESS1, m_progress);
DDX_Control(pDX, IDC_EDITFILENAME, m_editFilename);
DDX_Control(pDX, IDC_BTNSEND, m_btnSend);
DDX_Control(pDX, IDC_BTNCONNECT, m_btnConnect);
DDX_Control(pDX, IDC_BTNCLOSE, m_btnClose);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPPQTESTDlg, CDialog)
//{{AFX_MSG_MAP(CPPQTESTDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTNCLOSE, OnBtnclose)
ON_BN_CLICKED(IDC_BTNCONNECT, OnBtnconnect)
ON_BN_CLICKED(IDC_BTNSEND, OnBtnsend)
ON_BN_CLICKED(IDC_BTNLISTEN, OnBtnListen)
ON_BN_CLICKED(IDC_BTNSPIDERRECV, OnBtnspiderrecv)
//}}AFX_MSG_MAP
ON_MESSAGE(DSPFile::MSG_SENDSECT,OnSendSect)
ON_MESSAGE(DSPFile::MSG_RECVSECT,OnRecvSect)
ON_MESSAGE(DSPFile::MSG_SENDCOMPLETE,OnSendComplete)
ON_MESSAGE(DSPFile::MSG_SENDABORT,OnSendAbort)
ON_MESSAGE(DSPFile::MSG_SETFILENAMESIZE,OnSetFilenameSize)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPPQTESTDlg message handlers
BOOL CPPQTESTDlg::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_btnClose.EnableWindow(FALSE);
this->m_btnSend.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 CPPQTESTDlg::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 CPPQTESTDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPPQTESTDlg::OnButton1()
{
// TODO: Add your control notification handler code here
DSP::RegisterAct("PPQ.DSP",&PPQ::GetDSPObject);
ofstream ofs;
DSP::OpenOfstreamForWrite(ofs,"testObject.txt",ios::app);
// DSP::OpenOfstreamForWrite(ofs,"testObject.txt");
PPQ pp;
pp.m_bBOOL =TRUE;
pp.m_bBool =true;
pp.m_byValue=111;
pp.m_cValue =23;
pp.m_dwValue=456789;
pp.m_iValue =-456789;
pp.m_sValue =-23456;
pp.m_wValue =23456;
pp.m_str ="this is test2dfsd.中華人民共和國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共this";
pp.m_str.append("和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國sec");
pp.m_str.append("和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國國中華人民共和國中華人民共和國中華人民共和國中華人民共和國this is end.");
pp.m_hgf.m_byValue =45;
pp.m_hgf.m_sValue =-12345;
pp.m_hgf.m_wValue =12345;
pp.m_hgf.m_hCVB.bEnd =TRUE;
pp.m_hgf.m_hCVB.bFlag =FALSE;
pp.m_hgf.m_hCVB.bReset =FALSE;
pp.m_hgf.m_hCVB.byCount =57;
pp.m_hgf.m_hCVB.byType =198;
pp.m_hgf.m_hCVB.dwSum =9876543;
pp.m_hgf.m_hCOMB.bEnd =FALSE;
pp.m_hgf.m_hCOMB.byCount =97;
pp.m_hgf.m_hCOMB.byType =79;
pp.m_hgf.m_hCOMB.strDetail ="this is string var in struct.這是一個在結構中的字符串變量.";
pp.m_hgf.m_hCOMB.strApp ="這是一個CString變量,測試讀出和保存。";
bool bRun =true;
DSP::_DSPPACKET dp(bRun);
dp.SetParameter(FALSE,FALSE);
dp.WriteObject(ofs,pp);
ofs.flush();
ofs.close();
ifstream ifs;
DSP::OpenIfstreamForRead(ifs,"testObject.txt");
dp.Empty();
DSPACT* pAct =dp.ReadObject(ifs);
DSP::_DSPERROR* error =dp.GetLastError();
PPQ* pq =(PPQ*)pAct;
int size =pq->m_str.length();
HGF hf;
pAct =dp.ReadObject(ifs,&hf);
while(true)
{
pAct =dp.ReadObject(ifs);
if(ifs.eof() || pAct!=NULL)
break;
}
pq =(PPQ*)pAct;
ifs.close();
}
void CPPQTESTDlg::OnBtnclose()
{
// TODO: Add your control notification handler code here
//傳送放棄
this->m_bRun =false;
//禁止放棄、傳送按鈕
this->m_btnClose.EnableWindow(FALSE);
this->m_btnSend.EnableWindow(FALSE);
if(this->m_btnListen.IsWindowEnabled())
{
//如果沒有點擊監聽按鈕
//允許重新選擇連接類型和是否校驗
this->m_checkCrc.EnableWindow();
this->m_checkNet.EnableWindow();
}
//允許連接按鈕
this->m_btnConnect.EnableWindow();
}
void CPPQTESTDlg::OnBtnconnect()
{
// TODO: Add your control notification handler code here
CString str;
int nSel =this->m_comboIP.GetCurSel();
if(nSel<0)
{
//如果沒有選擇
this->m_comboIP.GetWindowText(str);
if(str=="")
{
//如果輸入了IP
::AfxMessageBox("請首先選擇一個IP");
return;
}
}
else
{
//如果選擇了一個IP
this->m_comboIP.GetLBText(nSel,str);
}
if(str=="")
{
::AfxMessageBox("請首行輸入連接方的IP!");
}
else
{
//連接指定的IP
SOCKET sock =DSP::ConnectTo((LPSTR)(LPCTSTR)str,34567,(this->m_checkNet.GetCheck())?false:true);
if(sock!=INVALID_SOCKET)
{
if(nSel<0)
{
//如果沒有選擇一個IP,則將這個成功的IP加入下拉列表中
this->m_comboIP.AddString(str);
}
//初始化允許傳送
this->m_bRun =true;
this->m_lphParam =new _THREADPARAM(this->m_bRun);
this->m_lphParam->sock =(int)sock;
this->m_lphParam->hWnd =this->m_hWnd;
this->m_lphParam->bCrc =this->m_checkCrc.GetCheck();
//禁止選擇連接類型
this->m_checkNet.EnableWindow(FALSE);
//禁止連接按鈕
this->m_btnConnect.EnableWindow(FALSE);
//允許傳送、放棄按鈕
this->m_btnSend.EnableWindow();
this->m_btnClose.EnableWindow();
}
else
{
::AfxMessageBox("連接失敗,請檢查IP后重試!");
}
}
}
void CPPQTESTDlg::OnBtnsend()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -