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

📄 clientdlg.cpp

📁 运行服务器端后
💻 CPP
字号:
// clientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "client.h"
#include "clientDlg.h"
#include "global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
mytcp a;
CString ip;
int co;
/////////////////////////////////////////////////////////////////////////////
// CClientDlg dialog

CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CClientDlg::IDD, pParent)
{co=0;
m_reset=0;
m_file="";
m_filepath="";
	//{{AFX_DATA_INIT(CClientDlg)
	m_ip = _T("");
	m_string = _T("");
	m_reset = 0;
	m_file = _T("");
	m_filepath = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CClientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClientDlg)
	DDX_Text(pDX, IDC_EDIT1, m_ip);
	DDX_Text(pDX, IDC_EDIT2, m_string);
	DDX_Text(pDX, IDC_EDIT3, m_reset);
	DDX_Text(pDX, IDC_EDIT4, m_file);
	DDX_Text(pDX, IDC_EDIT5, m_filepath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
	//{{AFX_MSG_MAP(CClientDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClientDlg message handlers

BOOL CClientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	a.mycreat(8000);
SetTimer(1,100,0);
	// 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
	m_string="你好";
	UpdateData(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 CClientDlg::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 CClientDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CClientDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{if(a.isreceve==1)
{a.isreceve=0;
if(a.type==1)
{CString m_path="";
void* buffer=::GlobalAlloc(0,1024*1024*50);
char*ps=(char*)buffer;
DWORD size=0;
node*p=&a.rhead;
node *prr;
prr=p;
CString rr;
for(int i=0;i<a.rhead.len;i++)
{prr=p;
	p=p->next;
memcpy((char*)ps,p->data,p->pos);
ps=(char*)ps+p->pos;
size=size+p->pos;
if(prr!=&a.rhead)
free(prr);
}
a.rhead.len=0;
BITMAPFILEHEADER he;
	he.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    he.bfReserved1=0;
	he.bfReserved2=0;
    he.bfType=0x4d42;
	he.bfSize=size+sizeof(BITMAPFILEHEADER);
	CFile file;
	//m_path="d:\\a.bmp";
	m_path.Format("%d.bmp",co);
	co++;
	if(file.Open(m_path,CFile::modeWrite|CFile::modeCreate))
	{
	file.Write(&he,sizeof(BITMAPFILEHEADER));
	file.SeekToEnd();
	file.Write(buffer,size);
	file.Close();
	::GlobalFree(buffer);
	UpdateData(true);
    if(m_reset==1)
		a.mysend(m_string.GetBuffer(0),m_string.GetLength());
	}

}
if(a.type==0)
{
char di[2048];
memcpy(di,a.rhead.next->data,a.rhead.next->pos);
di[a.rhead.next->pos]=0;
MessageBox(di);
a.rhead.len=0;
free(di);

}
if(a.type==2)
{
void* buffer=::GlobalAlloc(0,1024*1024*50);
char*ps=(char*)buffer;
DWORD size=0;
node*p=&a.rhead;
node *prr;
prr=p;
CString rr;
for(int i=0;i<a.rhead.len;i++)
{prr=p;
	p=p->next;
memcpy((char*)ps,p->data,p->pos);
ps=(char*)ps+p->pos;
size=size+p->pos;
if(prr!=&a.rhead)
free(prr);
}
a.rhead.len=0;
CFile file;
CString pp;
pp=a.name;
if(file.Open(pp,CFile::modeWrite|CFile::modeCreate,0))
{
file.Write(buffer,size);
file.Close();
::GlobalFree(buffer);
}


}


}

}

	
	CDialog::OnTimer(nIDEvent);
}
DWORD WINAPI mym1(LPVOID param)
{
	a.myconnect(ip,6000);	
return 1;
}
void CClientDlg::OnOK() 
{
UpdateData(true);	// TODO: Add extra validation here

ip=m_ip;
	DWORD  dwthewad;
HANDLE thread=::CreateThread(NULL,0,mym1,0,0,&dwthewad);

//	CDialog::OnOK();
}

void CClientDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(m_file=="")
	{a.type=0;
	a.mysend(m_string.GetBuffer(0),m_string.GetLength());
	}
	else
	{
	CFile file;
	UpdateData(true);
	if(file.Open(m_file,CFile::modeRead,0))
	{
	char *bu=(char*)::GlobalAlloc(0,file.GetLength());
	//MessageBox(m_file);
	file.Read(bu,file.GetLength());
	a.type=1;
	strcpy(a.name,m_filepath+file.GetFileName());
	MessageBox(a.name);
	a.mysend(bu,file.GetLength());
	}
	
	}
}

void CClientDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
CFileDialog dd(true);
if(dd.DoModal()==IDOK)
{
m_file=dd.GetPathName();
UpdateData(false);

}	
}

⌨️ 快捷键说明

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