Click here to Skip to main content
15,897,519 members
Articles / Desktop Programming / MFC

Simple File Transfer Using the Network Development Kit 2.0

Rate me:
Please Sign up or sign in to vote.
4.74/5 (14 votes)
29 Dec 20062 min read 91.9K   4.7K   99  
NDK File Transfer is a simple demonstration on how to send and receive a file using the NDK 2.0.
// NDKFileTransferClientDlg.h : header file
//

#pragma once
#include "afxwin.h"
#include "NDKClient.h"
#include "NDKFileTransferCommon.h"
#include "afxcmn.h"


// CNDKFileTransferClientDlg dialog
class CNDKFileTransferClientDlg : public CDialog, public CNDKClient
{
// Construction
public:
	CNDKFileTransferClientDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_NDKFILETRANSFERCLIENT_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnBnClickedButtonConnect();
	afx_msg void OnBnClickedButtonDisconnect();
	afx_msg void OnBnClickedButtonBrowse();
	afx_msg void OnBnClickedButtonDownloadFiles();
	afx_msg void OnBnClickedOk();
	DECLARE_MESSAGE_MAP()

protected:
	////////////////////////////////////////////////////////////////////////////
	// Callbacks from NDKClient                                               //
	////////////////////////////////////////////////////////////////////////////

	// Called when a message is received. The derived class must override this
	// method.
	virtual void OnMessage(CNDKMessage& message);

	// Called whenever a disconnection occurs. The NDKDisconnectionType specify
	// how the disconnection occurred. CloseConnection don't need to be called 
	// when OnDisconnect is used. The derived class must override this method.
	virtual void OnDisconnect(NDKClientDisconnection disconnectionType);

private:
	void UpdateUI();

private:
	CIPAddressCtrl m_IPServer;
	CEdit          m_editServerPort;
	int            m_nServerPort;
	CButton        m_buttonConnect;
	CButton        m_buttonDisconnect;
	CEdit          m_editDownloadPath;
	CString        m_strDownloadPath;
	CButton        m_buttonBrowse;
	CListBox       m_listServerFiles;
	CButton        m_buttonDownload;
	CProgressCtrl  m_progressDownload;
	BOOL           m_bIsDownloading;
	CFile          m_fileDownload;
	int            m_nFileSize;
	BYTE           m_byteBuffer[BUFFER_SIZE];
	UINT		   m_unBufferLength;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Mirego
Canada Canada
My name is Sébastien Lachance.

I love C# developing Windows Phone and Windows 8 applications.

When I’m not in front of a computer, my hobbies include playing bridge, poker and other card games, biking, reading technology news.

Comments and Discussions