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

📄 tcpclient.cpp

📁 客户端
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 2 ";
	sNow+=m_ccb;
	sNow+=" ";
	sNow+=m_ccb4;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S ");
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else if(m_ccb4.IsEmpty())
	{
	 MessageBox("请输入事件类型ID","提示",MB_OK);
	}
	else
	{
	 MessageBox(sNow,"事件开始消息");
	 sNow+="\r";
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");}
	 }
	
	UpdateData(FALSE);
}

void CMainDialog::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 3 ";
	sNow+=m_ccb;
	sNow+=" ";
	sNow+=m_ccb4;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S ");
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else if(m_ccb4.IsEmpty())
	{
	 MessageBox("请输入事件类型ID","提示",MB_OK);
	}
	else
	{
	 MessageBox(sNow,"事件结束消息");
	 sNow+="\r";
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");}
	}
	
	UpdateData(FALSE);

}

void CMainDialog::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 4 ";
	sNow+=m_ccb;
	sNow+=" ";
	sNow+=m_ccb3;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S ");
	
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else if(m_ccb3.IsEmpty())
	{
	 MessageBox("请输入错误类型ID","提示",MB_OK);
	}
	else
	{
	 MessageBox(sNow,"错误消息");
	 sNow+="\r";
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");}
	}
	
	UpdateData(FALSE);

}

void CMainDialog::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	if(m_socket == INVALID_SOCKET)
	{
		return;
	}
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 5 ";
	sNow+=m_ccb;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S ");
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else
	{
	  MessageBox(sNow,"检测器连接消息",MB_OK);
	  sNow += "\r";
	  int f,l;
	  if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");
	 }
	}
	
	UpdateData(FALSE);
}

void CMainDialog::OnBnClickedButton6()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 6 ";
	sNow+=m_ccb;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S ");
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else
	{
	  MessageBox(sNow,"检测器结束消息");
	 sNow+="\r";
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");
	 }
	}
	
	UpdateData(FALSE);
}

void CMainDialog::OnBnClickedButton7()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 7 ";
	sNow+=m_ccb;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S");
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else
	{
	 MessageBox(sNow,"车辆数目测量消息");
	 GetDlgItem(IDC_COMBO1)->SetWindowText("");
	 sNow+="\r";
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");}
	 GetDlgItem(IDC_COMBO1)->SetWindowText("");
	}
	
	UpdateData(FALSE);
}

void CMainDialog::OnBnClickedButton8()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow;
	sNow+="D 8 ";
	sNow+=m_ccb;
	sNow+=tNow.Format(" 20%y%m%d %H%M%S");
	
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else
	{
	 MessageBox(sNow,"视频序列可用消息");
	 
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_TEXT)->SetWindowText("");
	 }
	 sNow+="\r\n";
	}
	
	UpdateData(FALSE);
}

void CMainDialog::OnBnClickedButton9()
{
	// TODO: 在此添加控件通知处理程序代码
	if(m_socket == INVALID_SOCKET)
	{
		return;
	}
	UpdateData(TRUE);
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	CString sNow=tNow.Format("D 9 ");
	sNow+=m_ccb;
	sNow+="\r\n";
	if(m_ccb.IsEmpty())
	{
	 MessageBox("请输入相机ID","提示",MB_OK);
	}
	else
	{
	 MessageBox(sNow,"相机禁用消息",MB_OK);
	 GetDlgItem(IDC_COMBO1)->SetWindowText(" ");
	 int f,l;
	 if(f=::send(m_socket, sNow, l=sNow.GetLength(), 0) != -1)
	 {
		AddStringToList(sNow,FALSE);
		GetDlgItem(IDC_COMBO1)->SetWindowText(" ");
	 }
	}
	GetDlgItem(IDC_COMBO1)->SetWindowText(" ");
    UpdateData(FALSE);
}





void CMainDialog::OnBnClicked1()
{
	// TODO: 在此添加控件通知处理程序代码
   UpdateData(TRUE);
   MessageBox("0- internal usage;1- one minute period;2- six minute period;3- one hour period;4- user period","测量周期");
   UpdateData(FALSE);
}

void CMainDialog::OnBnClicked2()
{
	// TODO: 在此添加控件通知处理程序代码
   UpdateData(TRUE);
   MessageBox("0- no system error The system work well;1- camera move The system indicates that a camera has been moved from its originally position; 2- video error The system indicates that the analyzer meets problem with the camera input;3- numerisation card error or bad video signal The system indicates that the analyzer meets problem with the frame grabber card;4- inactive camera The analyzer is not in operating conditions;5- communication error The communications between the analyzer and the server are failed","错误类型");
   UpdateData(FALSE);
}

void CMainDialog::OnBnClicked3()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
   MessageBox("0- stopped vehicle in fluid condition;1- internal usage;2-slow down;3- stopped vehicle in congested condition;4- isolated slow vehicle;5- wrong way vehicle;6- pedestrian on emergency lane;7- debris;8- distance inter-vehicle above threshold;9- queue length above threshold;10- lost of visibility;11- internal usage;12- internal usage;13- Back way;14- speed vehicle above threshold","事件类型");
   UpdateData(FALSE);
}

void CMainDialog::OnBnClicked4()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
   MessageBox("0- internal usage;1- one minute period;2- six minute period;3- one hour period;4- user period","测量类型");
   UpdateData(FALSE);
}



void CMainDialog::OnBnClickedSendfile()
{
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_CREATEPROMPT,"All Files(*.*)||",NULL);
	CFile m_ImgFile;
	CString m_strFileName;

	if (dlg.DoModal()==IDOK)
	{
		m_strFileName=dlg.GetPathName();
		if (m_ImgFile.m_hFile!=CFile::hFileNull)
		{
			m_ImgFile.Close();
		}
		if (!m_ImgFile.Open(m_strFileName,CFile::modeRead))
		{
			MessageBox("文件不能打开!");
			m_strFileName.Empty();
			return;
		}
		m_ImgFile.Seek(0,CFile::begin);
		int m_iFileBegin=0;
		int m_iFileLength=m_ImgFile.GetLength();
		BYTE *m_pSndBuf=new BYTE[m_iFileLength];
		m_ImgFile.Read(m_pSndBuf,m_iFileLength);
		m_ImgFile.Close();
		::send(m_socket,(const char*)m_pSndBuf,m_iFileLength,0);
		delete[] m_pSndBuf;
	}
	else
	{
		m_strFileName.Empty();
	}
}

void CMainDialog::OnBnClickedRecvfile()
{
	// TODO: 在此添加控件通知处理程序代码
	CString m_strFileName;
	CFileDialog dlg(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_CREATEPROMPT,"All Files(*.*)",NULL,0);
	/*if (dlg.DoModal()==IDOK)
	{
		m_strFileName=dlg.GetPathName();
		CFile m_ImgFile(m_strFileName,CFile::modeCreate|CFile::modeRead|CFile::shareExclusive);
	
	

		CString m_strFileName;
		char nFileLength=m_ImgFile.GetLength();
		char * recvBuf=new char[1024];
		if (nFileLength>recvBuf)
		{
			::recv(m_socket,(const char*)recvBuf,sizeof(recvBuf),0);
			nFileLength-=1024;
		}
		m_ImgFile.Write(recvBuf,nFileLength);
		m_ImgFile.Close();

	}*/
	//CCliDlg * dlg=(CDialog *)pParam;
	SOCKET_STREAM_FILE_INFO StreamFileInfo;

	//dlg->cliSock.Receive(&StreamFileInfo,sizeof(SOCKET_STREAM_FILE_INFO));

	//CFile myFile;
	//myFile.Open(StreamFileInfo.szFileTitle, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
	//AfxMessageBox(StreamFileInfo.szFileTitle);
	//UINT nSize=0;
	//UINT nData=0;

	//while (nSize < StreamFileInfo.nFileSizeLow)
	//{
	//	//byte * szBuf=new byte[1024];
	//	char * szBuf=new char[1024];
	//	nData= dlg->cliSock.Receive(szBuf, 1024);
	//	myFile.Write(szBuf, nData);
	//	nSize+=nData;
	//}
	//SetFileTime((HANDLE)myFile.m_hFile,&StreamFileInfo.ftCreationTime,
	//	&StreamFileInfo.ftLastAccessTime,&StreamFileInfo.ftLastWriteTime);
	//myFile.Close();
	//SetFileAttributes(StreamFileInfo.szFileTitle,StreamFileInfo.dwFileAttributes);
	//dlg->cliSock.Close();
	//AfxMessageBox("接收完毕!");
	//(dlg->GetDlgItem(IDC_ACCEPT))->EnableWindow(TRUE);

//	theRecv=NULL;
//	dlg=NULL;	
//	return 0;
/*	else
	{
		m_strFileName.Empty();
	}*/
	UpdateData(true);


}

void CMainDialog::OnEnChangeEditshowpicture()
{
    HBITMAP hbitmap;
    //将pStatic指向要显示的地方
	CStatic *pStatic = NULL;

    //根据ID获取Static控件
	pStatic=(CStatic*)GetDlgItem(IDC_INFO);
    //装载资源*.bmp
    hbitmap=(HBITMAP)::LoadImage (::AfxGetInstanceHandle(),"d:\\image\\test-%d.JPG",
        IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);


    CBitmap hbmp;
    hbmp.Attach(hbitmap);
    //获取图片内容
    BITMAP bm;
    hbmp.GetBitmap(&bm);
    CDC dcMem;

    //创建兼容DC
    dcMem.CreateCompatibleDC(GetDC());
    CBitmap *pOldBitmap=(CBitmap*)dcMem.SelectObject(hbmp);
    CRect lRect;

    //获取Static控件的大小范围
    pStatic->GetClientRect(&lRect);
    //在Static控件上显示位图
    pStatic->GetDC()->StretchBlt(lRect.left ,lRect.top ,lRect.Width(),lRect.Height(),
        &dcMem,0 ,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
    dcMem.SelectObject(&pOldBitmap);

}

⌨️ 快捷键说明

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