?? cclentdlg.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 + -