Click here to Skip to main content
15,891,943 members
Articles / Desktop Programming / MFC

EasyFtp 1.3.2 (for Applications)

Rate me:
Please Sign up or sign in to vote.
4.91/5 (28 votes)
21 Mar 2004CC (ASA 2.5)7 min read 150.1K   3.1K   119  
A 'drop-in' FTP solution for applications providing a full GUI, extended commandline options and no resource files. Use standalone or compiled into your own app.
// ProgressDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ProgressDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CProgressDlg dialog

enum
{
	IDC_PROGRESSBAR = 101,
	IDC_DESCRIPTION,
	IDC_PROGRESS,
};


CProgressDlg::CProgressDlg(CWnd* pParent /*=NULL*/) : m_bContinue(FALSE)
{
	//{{AFX_DATA_INIT(CProgressDlg)
	m_sProgress = _T("");
	m_sDescription = _T("");
	//}}AFX_DATA_INIT

	AddRCControl("PUSHBUTTON", "", "Cancel", 0, 0, 67,73,50,14,IDCANCEL);
    AddRCControl("CONTROL", "msctls_progress32", "", 0, 0, 7,55, 172,9, IDC_PROGRESSBAR);
    AddRCControl("LTEXT", "", "", 0, 0, 7,7,172,30, IDC_DESCRIPTION);
    AddRCControl("LTEXT", "", "", 0, 0, 7,42,172,8, IDC_PROGRESS);
}


void CProgressDlg::DoDataExchange(CDataExchange* pDX)
{
	CRuntimeDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProgressDlg)
	DDX_Control(pDX, IDC_PROGRESSBAR, m_progress);
	DDX_Text(pDX, IDC_PROGRESS, m_sProgress);
	DDX_Text(pDX, IDC_DESCRIPTION, m_sDescription);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProgressDlg, CRuntimeDlg)
	//{{AFX_MSG_MAP(CProgressDlg)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProgressDlg message handlers

BOOL CProgressDlg::Create(LPCTSTR szCaption, LPCTSTR szDescription, CWnd* pParent)
{
	m_sDescription = szDescription;
	m_sProgress.Empty();

	return CRuntimeDlg::Create(szCaption, RTD_DEFSTYLE, RTD_DEFEXSTYLE, rectAuto, pParent); 
}

void CProgressDlg::SetCaption(LPCTSTR szCaption)
{
	ASSERT (GetSafeHwnd());

	SetWindowText(szCaption);

	Continue();
}

void CProgressDlg::SetProgress(LPCTSTR szProgress)
{
	ASSERT (GetSafeHwnd());

	m_sProgress = szProgress;
	UpdateData(FALSE);

	GetDlgItem(IDCANCEL)->EnableWindow(TRUE);

	Continue();
}

void CProgressDlg::SetProgress(int nProgress)
{
	ASSERT (GetSafeHwnd());

	m_progress.SetPos(nProgress);
	GetDlgItem(IDCANCEL)->EnableWindow(TRUE);

	Continue();
}

void CProgressDlg::SetDescription(LPCTSTR szDescription)
{
	ASSERT (GetSafeHwnd());

	m_sDescription = szDescription;
	UpdateData(FALSE);

	Continue();
}

BOOL CProgressDlg::OnInitDialog() 
{
	CRuntimeDlg::OnInitDialog();

	m_bContinue = TRUE;
	m_progress.SetRange(0, 100);
	GetDlgItem(IDCANCEL)->EnableWindow(FALSE); // till SetProgress is called for the first time
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CProgressDlg::Continue()
{
	MSG msg;
	
	// check messages for the cancel dialog
	while (::PeekMessage((LPMSG) &msg, NULL, 0, 0, PM_REMOVE))
	{
		BOOL bDlgMsg = ::IsDialogMessage(*this, &msg);
		
		if (!bDlgMsg) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return m_bContinue; 
}

void CProgressDlg::OnCancel()
{
	m_bContinue = FALSE;

	ShowWindow(SW_HIDE);
}

void CProgressDlg::OnDestroy() 
{
	CRuntimeDlg::OnDestroy();
}

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, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License


Written By
Software Developer Maptek
Australia Australia
.dan.g. is a naturalised Australian and has been developing commercial windows software since 1998.

Comments and Discussions