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

📄 cclentdlg.cpp

📁 This program is about data organization using Visual C++ tools.It is able to control the other s com
💻 CPP
字号:
// cclentDlg.cpp : implementation file
//

#include "stdafx.h"
#include "cclent.h"
#include "cclentDlg.h"
//#include <recvfile.h>
#include <stdio.h>
#include <initsock.h>
#define BYTEMAXLEN 256

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

CInitSock initsock;

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

/////////////////////////////////////////////////////////////////////////////
// CCclentDlg dialog

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

void CCclentDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCclentDlg)
	DDX_Text(pDX, IDC_EDIT1, m_ip);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCclentDlg, CDialog)
//{{AFX_MSG_MAP(CCclentDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCclentDlg message handlers

BOOL CCclentDlg::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
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CCclentDlg::OnOK() 
{
	
	// TODO: Add extra validation here
	SOCKET s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(s == INVALID_SOCKET)
	{
		MessageBox(" Failed socket() \n");
		
	}
	else
	{
	
	// 也可以在这里调用bind函数绑定一个本地地址
	// 否则系统将会自动安排
	
	// 填写远程地址信息
	sockaddr_in servAddr; 
	servAddr.sin_family = AF_INET;
	servAddr.sin_port = htons(4567);
	// 注意,这里要填写服务器程序(TCPServer程序)所在机器的IP地址
	// 如果你的计算机没有联网,直接使用127.0.0.1即可
//	servAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
	UpdateData(TRUE);
	servAddr.sin_addr.S_un.S_addr = inet_addr(m_ip);
	
	if(::connect(s, (sockaddr*)&servAddr, sizeof(servAddr)) == -1)
	{
		MessageBox(" Failed connect() \n");
	}
	else
	{
	
	// 接收数据
	char buff[256];
	int nRecv = ::recv(s, buff, 256, 0);
	//001
	if(nRecv > 0)
	{
		buff[nRecv] = '\0';
//		MessageBox(" 接收到数据:%s", buff);
	}
	buff[0]='s';
	buff[1]='s';
	buff[2]='s';
	buff[3]='\0';
	//002
	::send(s,buff,256,0);
	memset(buff,0,sizeof(buff));
	nRecv = ::recv(s, buff, 256, 0);
	if(nRecv > 0)
	{
		if(!strcmp(buff,"ok"))
//			MessageBox("ok");
		{}
		else
			MessageBox("error");
	}
	
	
	//recvfile(s);
	int ic=0;
	char   msg[BYTEMAXLEN]; 
	FILE *f=fopen("01.bmp","wb");   
	while   (true) //接收   
	{   
		strcpy(msg,"");   
		int l=recv(s,msg,BYTEMAXLEN,0);   
		if   (msg[l-3]=='^'   &&   msg[l-2]=='&'   &&   msg[l-1]=='*') //发送完的标志     
		{   
			msg[l-3]='\0';   
			fwrite((void*)msg,1,l-3,f);   //写入数据   
			break;   
		}   
		fwrite((void*)msg,1,l,f);   
	}   
	fclose(f);   
	
	
	
	// 关闭套节字
	
	
	::closesocket(s);
	
	
	CDC   *   dc;   
	dc=GetDC();     //得到对话框的设备环境   
	CDC   dcMemory;       
	dcMemory.CreateCompatibleDC(dc);     //得到与对话框设备环境相兼容的内存DC   
    
	CBitmap *bitmap=new  CBitmap();   
	HBITMAP   hbitmap;   
	//装载图片   
	hbitmap=(HBITMAP)::LoadImage(NULL,"01.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);   
	if(hbitmap)     //成功   
	{   
		bitmap->Attach(hbitmap);   
	}   
	else   
	{                         //出错。。返回   
		AfxMessageBox("打开图像文件出错");   
		//释放内存中的设备环境   
		ReleaseDC(dc);   
		ReleaseDC(&dcMemory);   
		delete   bitmap;   
		return;   
	}   
	//取得图像的大小   
	long   bmWidth,bmHeight;   //图像的宽度,和高度   
	BITMAP   bm;   
	bitmap->GetBitmap(&bm);   
	bmWidth=bm.bmWidth;   
	bmHeight=bm.bmHeight;   
    
	dcMemory.SelectObject(bitmap);   
	dc->StretchBlt(60,60,bmWidth/2,bmHeight/2+60,&dcMemory,0,0,bmWidth,bmHeight,SRCCOPY);
//	dc->BitBlt(0,0,bmWidth,bmHeight,&dcMemory,0,0,SRCCOPY);//把内存中的图像复制到对话框DC中去
	}
	}
}

⌨️ 快捷键说明

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