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

📄 fan1dlg.cpp

📁 基于linux嵌入式开发板的图像采集 服务器端作为图像采集端客户从服务器接受图像
💻 CPP
字号:
// fan1Dlg.cpp : implementation file
//#include <mem.h>

#include "stdafx.h"
#include "fan1.h"
#include "fan1Dlg.h"
#include "RecevieSocket.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()

/////////////////////////////////////////////////////////////////////////////
// CFan1Dlg dialog

CFan1Dlg::CFan1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFan1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFan1Dlg)
	m_LocatePort = 2050;
	m_nServerPort = 20;
	m_ServerIP = _T("192.168.2.120");
	m_FileName = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFan1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFan1Dlg)
	DDX_Control(pDX, IDC_BUTTON3, m_nButton3);
	DDX_Control(pDX, IDC_BUTTON2, m_nButton2);

	DDX_Control(pDX, IDC_BUTTON1, m_nButton1);
	DDX_Text(pDX, IDC_EDIT1, m_LocatePort);
	DDX_Text(pDX, IDC_EDIT2, m_nServerPort);
	DDX_Text(pDX, IDC_EDIT3, m_ServerIP);
	DDX_Text(pDX, IDC_EDIT4, m_FileName);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFan1Dlg, CDialog)
	//{{AFX_MSG_MAP(CFan1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)

    ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFan1Dlg message handlers

BOOL CFan1Dlg::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
	GetDlgItem(IDC_BUTTON3)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
    GetDlgItem(IDC_EDIT4)->EnableWindow(FALSE);
	GetDlgItem(IDC_STATIC1)->EnableWindow(FALSE);
	GetDlgItem(IDC_STATIC2)->EnableWindow(FALSE);

	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CFan1Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);    
	//revise by ln
    m_nSocket=new CRecevieSocket(this); //把主对话框指针this 传值
	if(m_nSocket->Create(m_LocatePort))
	{
		if(!m_nSocket->Connect(m_ServerIP,m_nServerPort))
		{
			AfxMessageBox("连接失败!");
			delete m_nSocket;
			m_nSocket=NULL;
			PostQuitMessage(0);
		}
		else
		{
			GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
			AfxMessageBox("请填入信息文件名!");
	        GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
	        GetDlgItem(IDC_BUTTON2)->EnableWindow(TRUE);
	        GetDlgItem(IDC_EDIT4)->EnableWindow(TRUE);
	        GetDlgItem(IDC_STATIC1)->EnableWindow(TRUE);
	        GetDlgItem(IDC_STATIC2)->EnableWindow(TRUE);
		}
	}
	else
	{
		delete m_nSocket;
		m_nSocket=NULL;
	}
}

void CFan1Dlg::DealRecv()
{
//    char buf[300*1024];
    byte* buf=new byte[300*1024];
    byte  *p=buf;
	CFile file;
	int num=1;
	int i=0;
	/*AfxMessageBox("开始接收!");*/
	UpdateData(TRUE);   
	//buf=(char*)malloc(300*1024);
	//memset(buf,0,sizeof(buf));
	
	
//	pointer=NULL;
//	i=0;
//	file.Open(m_FileName,CFile::modeCreate|CFile::modeReadWrite);
//	num=m_nSocket->Receive(buf,sizeof(buf));
	//AfxMessageBox(sizeof(num));
	while(num!=0)
	{
		num=m_nSocket->Receive(p,10240);
		p+=num;
		i+=num;
//		i++;
//		file->SetLength(100*i);
//		pointer=(file+file->Seek(100*(i-1),CFile::begin));
//		pointer->Write(buf,100);
		if(num<10)
			break;
	}
//	num=m_nSocket->Receive(buf,sizeof(buf));
	file.Open(m_FileName,CFile::modeCreate|CFile::modeReadWrite);
	file.WriteHuge(buf,i);
	file.Close();
//	free(buf);
	AfxMessageBox("接收完毕!");
	free(buf);
	delete m_nSocket;
	m_nSocket=NULL;
	
}

void CFan1Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	char *flag="1";
	m_nSocket->Send(flag,2);
	
}
/*
void CFan1Dlg::DealClose()
{
	CFile file;
	file.Open(m_FileName,CFile::modeCreate|CFile::modeReadWrite);
	file.WriteHuge(buf,i);
	file.Close();
	free(buf);
	delete m_nSocket;
	m_nSocket=NULL;
	PostQuitMessage(0);



}*/

void CFan1Dlg::OnButton3()
{
    CWnd *pWnd0=GetDlgItem(IDC_pp);
    CDC *pDC=pWnd0->GetDC();
	IPicture *pPic;
	IStream *pStm;
	CFileStatus fstatus;
    CFile file;
	LONG cb;
	if(file.Open(m_FileName,CFile::modeRead)
		&&file.GetStatus(m_FileName,fstatus)
		&&((cb=fstatus.m_size)!=-1))
	{
			HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,cb);
			LPVOID pvData=NULL;
			if(hGlobal!=NULL)
			{
				if((pvData=GlobalLock(hGlobal))!=NULL)
				{
					file.ReadHuge(pvData,cb);
					GlobalUnlock(hGlobal);
					CreateStreamOnHGlobal(hGlobal,TRUE,&pStm);
					if(SUCCEEDED(OleLoadPicture(pStm,
						fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
					{
						OLE_XSIZE_HIMETRIC hmWidth;
						OLE_YSIZE_HIMETRIC hmHeight;
						pPic->get_Width(&hmWidth);
						pPic->get_Height(&hmHeight);
						double fX,fY;
						fX=(double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)
							pDC->GetDeviceCaps(HORZSIZE)*140.0);
						fY=(double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)
							pDC-> GetDeviceCaps(VERTSIZE)*140.0);  
//                      fX=pDC->GetDeviceCaps(HORZRES);
//						fY=pDC-> GetDeviceCaps (VERTRES);
                        if(FAILED(pPic-> Render (*pDC,0,0,(DWORD)(173*2),(DWORD)(173*2*fY/fX),
							0,hmHeight,hmWidth,-hmHeight,NULL))) 
                        AfxMessageBox("Failed To Render The picture!");
                        pPic->Release();
						pWnd0->ReleaseDC(pDC);
					//	PostQuitMessage(0);
					} 
					else
                       AfxMessageBox("Error Loading Picture Stream!");
				}
			}
	}
    else
    AfxMessageBox("Can't Open Image File!");
}




⌨️ 快捷键说明

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