⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netrecvdlg.cpp

📁 组播发送测试网络程序,客户端
💻 CPP
字号:
// NetRecvDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NetRecv.h"
#include "NetRecvDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetRecvDlg dialog

CNetRecvDlg::CNetRecvDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNetRecvDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNetRecvDlg)
	m_bisSave = FALSE;
	m_strAdd = _T("");
	m_dwPort = 0;
	m_strBitrate = _T("");
	m_strIndex = _T("");
	m_strLossCount = _T("");
	m_strPackageSize = _T("");
	m_strRecvCount = _T("");
	m_strLossRate = _T("");
	m_nBlockListSize = 10;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CNetRecvDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNetRecvDlg)
	DDX_Control(pDX, IDC_LIST1, m_list1);
	DDX_Check(pDX, IDC_CHECK1, m_bisSave);
	DDX_Text(pDX, IDC_ADD, m_strAdd);
	DDX_Text(pDX, IDC_PORT, m_dwPort);
	DDV_MinMaxDWord(pDX, m_dwPort, 1000, 60000);
	DDX_Text(pDX, IDC_BITRATE, m_strBitrate);
	DDX_Text(pDX, IDC_BLOCKINDEX, m_strIndex);
	DDX_Text(pDX, IDC_LOSSCOUNT, m_strLossCount);
	DDX_Text(pDX, IDC_PACKAGESIZE, m_strPackageSize);
	DDX_Text(pDX, IDC_RECVCOUNT, m_strRecvCount);
	DDX_Text(pDX, IDC_LOSSRATE, m_strLossRate);
	DDX_Text(pDX, IDC_LISTCOUNT, m_nBlockListSize);
	DDV_MinMaxLong(pDX, m_nBlockListSize, 1, 10000);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNetRecvDlg, CDialog)
	//{{AFX_MSG_MAP(CNetRecvDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_INIT, OnInit)
	ON_BN_CLICKED(IDC_SETSAVE, OnSetsave)
	ON_BN_CLICKED(IDC_SETLISTCOUNT, OnSetlistcount)
	ON_BN_CLICKED(IDC_CLOSERECV, OnCloserecv)
	ON_BN_CLICKED(IDC_SHOWINFO, OnShowinfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetRecvDlg message handlers

BOOL CNetRecvDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	

	 Init();
	 CheckStatus();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNetRecvDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CNetRecvDlg::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 CNetRecvDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CNetRecvDlg::OnInit() 
{
UpdateData(TRUE);
m_RecvAgent.SetBlockListSize(m_nBlockListSize);
m_RecvAgent.Init((LPTSTR)(LPCSTR)m_strAdd,m_dwPort,false);

CheckStatus();

	
}



void CNetRecvDlg::OnCancel() 
{
    m_RecvAgent.Close();
	
	CDialog::OnCancel();
}

void CNetRecvDlg::OnSetsave() 
{   UpdateData(TRUE);

	m_RecvAgent.SetSave(m_bisSave);
	
}

void CNetRecvDlg::Init()
{
m_strAdd=_T("226.8.8.5");
 m_dwPort=1900;
 g_hMonWnd=this->GetSafeHwnd();
 UpdateData(FALSE);
}

LRESULT CNetRecvDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
    switch(message){
	case MSG_RECV_PROGRESS:
		UpdateInfo(wParam,lParam);
		break;
	case MSG_LIST_ERROR:
		ProcError((pBlockListInfo)lParam);
		break;
    }// end switch
	
	return CDialog::WindowProc(message, wParam, lParam);
}

void CNetRecvDlg::UpdateInfo(WPARAM wParam, LPARAM lParam)
{  char szout[64];
   SwapToDotString(szout,(DWORD)lParam);
  // TRACE("bitrate=%d\n",(DWORD)lParam);
   m_strBitrate.Format("%s bps",szout);
   m_strIndex.Format("%d",(DWORD) wParam);
   m_strPackageSize.Format("%d B",m_RecvAgent.GetPackageSize());
   m_strRecvCount.Format("%d",m_RecvAgent.GetRecvPackageCount());
   m_strLossCount.Format("%d",m_RecvAgent.GetLossCount());
   if(m_RecvAgent.GetRecvPackageCount()==0)
     m_strLossRate.Format("000");
   else
    m_strLossRate.Format("%5.2e",(double)m_RecvAgent.GetLossCount()/
	   (double)(m_RecvAgent.GetRecvPackageCount()+m_RecvAgent.GetLossCount()));
   SetDlgItemText(IDC_BLOCKINDEX,m_strIndex);
   SetDlgItemText(IDC_BITRATE,m_strBitrate);
   SetDlgItemText(IDC_LOSSCOUNT,m_strLossCount);
   SetDlgItemText(IDC_PACKAGESIZE,m_strPackageSize);
   SetDlgItemText(IDC_RECVCOUNT,m_strRecvCount);
   SetDlgItemText(IDC_LOSSRATE,m_strLossRate);
	   
  // UpdateData(FALSE);
 
}



void CNetRecvDlg::OnSetlistcount() 
{
	UpdateData(TRUE);
m_RecvAgent.SetBlockListSize(m_nBlockListSize);
	
}

void CNetRecvDlg::ProcError(pBlockListInfo pinfo)
{char szbuff[64];

switch(pinfo->nFlag){
     case BLOCK_ERROR_LOSSBLOCK:      //数据包丢失
        sprintf(szbuff," 丢包: 数量:%d  间隔:%d--%d",
			 pinfo->lIndexOff,pinfo->dwPreBlockIndex,pinfo->dwBlockIndex);  
		 break;
    case  BLOCK_ERROR_LIST :
		sprintf(szbuff,"顺序错误  偏差:%d  延时:%d  间隔:%d--%d",
			pinfo->lIndexOff,pinfo->lTimeOff,pinfo->dwPreBlockIndex,
			pinfo->dwBlockIndex);
		break;
    default:
		break;
} // end switch
   m_list1.InsertString(-1,szbuff);
}

void CNetRecvDlg::OnCloserecv() 
{
	 m_RecvAgent.Close(); 
	
	 Sleep(10);
	 CheckStatus();
}

void CNetRecvDlg::CheckStatus()
{
 Stream_Status s=m_RecvAgent.GetStreamStatus();
 switch(s){
 case S_S_Idle:
 case S_S_Closed:
     	GetDlgItem(IDC_INIT)->EnableWindow(TRUE);
        GetDlgItem(IDC_CLOSERECV)->EnableWindow(FALSE);  

	 break;
 default:
	 	GetDlgItem(IDC_INIT)->EnableWindow(FALSE);
        GetDlgItem(IDC_CLOSERECV)->EnableWindow(TRUE);

	 break;

 }
	 
}

void CNetRecvDlg::OnShowinfo() 
{
 char szbuff[128];
 ::MessageBox(NULL,
	 m_RecvAgent.GetPackageInfo(szbuff,125),
	 "数据包信息",
	  MB_OK);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -