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

📄 ftpserverdlg.cpp

📁 FTP上传工具,FTP上传的小例子,包括定制时间上传功能
💻 CPP
字号:
// FtpServerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FtpServer.h"
#include "FtpServerDlg.h"

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

ULONG WINAPI ThreadFunc(LPVOID lpparam);
CTaskManager * m_dlgConfig;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CFtpServerDlg dialog

CFtpServerDlg::CFtpServerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFtpServerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFtpServerDlg)
	m_bCheck_Error = FALSE;
	m_bCheck_Normal = FALSE;
	m_bCheck_ShowTime = FALSE;
	m_bCheck_Warn = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//	myTask=new CMyTask;
	bStrat=FALSE;
}

void CFtpServerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFtpServerDlg)
	DDX_Control(pDX, IDC_LIST1, m_listbox);
	DDX_Check(pDX, IDC_CHECK_ERROR, m_bCheck_Error);
	DDX_Check(pDX, IDC_CHECK_NORMAL, m_bCheck_Normal);
	DDX_Check(pDX, IDC_CHECK_SHOWTIME, m_bCheck_ShowTime);
	DDX_Check(pDX, IDC_CHECK_WARN, m_bCheck_Warn);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFtpServerDlg, CDialog)
	//{{AFX_MSG_MAP(CFtpServerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_CHECK_NORMAL, OnCheckNormal)
	ON_BN_CLICKED(IDC_CHECK_WARN, OnCheckWarn)
	ON_BN_CLICKED(IDC_CHECK_ERROR, OnCheckError)
	ON_BN_CLICKED(IDC_CHECK_SHOWTIME, OnCheckShowtime)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFtpServerDlg message handlers

BOOL CFtpServerDlg::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
	
	CButton *pbt1=(CButton *)GetDlgItem(IDC_CHECK_ERROR);
    pbt1->SetCheck(TRUE);
	CButton *pbt2=(CButton *)GetDlgItem(IDC_CHECK_NORMAL);
    pbt2->SetCheck(TRUE);
	CButton *pbt3=(CButton *)GetDlgItem(IDC_CHECK_SHOWTIME);
    pbt3->SetCheck(TRUE);
	
	CFtpServerApp *pApp = (CFtpServerApp *)AfxGetApp();
	pApp->onRead();

	SetTimer(1,1000*60,NULL);
    
    CButton *pbt4=(CButton *)GetDlgItem(IDC_START);
    pbt4->SetWindowText("停止");
	bStrat=TRUE;
	UpdateData();
	CStatic *pst=(CStatic *)GetDlgItem(IDC_PRINT);
//	pst->SetWindowText("FTP服务已启动,正在检索要传送的文件,如果在警告中发现没有找到文件.请确认该文件是否还未生成,否则请检查相关配置");
	m_listbox.AddString("FTP服务已启动,正在检索要传送的文件.如果在警告中发现没有找到文件.请确认该文件是否还未生成.");

	//m_Log.PrintMsg("FTP服务已启动!",CLEAR);
	// TODO: Add extra initialization here


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

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

void CFtpServerDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	// 遍历列表

	CFtpServerApp *pApp = (CFtpServerApp *)AfxGetApp();
	WORD nCount;
	POSITION pos;

    nCount = (WORD)pApp->m_diaryList.GetCount();
	pos = pApp->m_diaryList.GetHeadPosition();
	for(int k = 0; k < nCount && pos != NULL; k++)
	{
		CMyTask* myTask = pApp->m_diaryList.GetNext(pos);

		CTime tmp;
		tmp=tmp.GetCurrentTime();
		int ihour=tmp.GetHour ();
		if ((tmp >= myTask->m_TstartDate ) && (tmp < myTask->m_TendDate))
		{
			if (ihour == myTask->m_starthour)
               myTask->m_AlreadyStart = TRUE;
			int m_cortrol = 0;
			if (myTask->m_IntervalHour>0)
			{
				m_cortrol = myTask->m_IntervalMinute * myTask->m_IntervalHour;
			}else
			{
				m_cortrol = myTask->m_IntervalMinute;
			}

			if ((m_cortrol >= myTask->m_NowStep) && (m_cortrol != 0))
			{
				DWORD dwThreadID;
				CreateThread(NULL,0,ThreadFunc,myTask,0,&dwThreadID);
				myTask->m_NowStep=0;
			}
			else
			{
				if ( myTask->m_AlreadyStart )
				   myTask->m_NowStep+=1;
				TRACE("%d",myTask->m_NowStep);
			}
		}
	}
	CDialog::OnTimer(nIDEvent);
}

ULONG WINAPI ThreadFunc(LPVOID lpparam)
{   
	char szLog[256]={0};
	CMyTask* pTask=(CMyTask*)lpparam;
  	if (!pTask->CheckFileExist(pTask->m_SurveillantPath))
	{
		sprintf(szLog,"要监控的文件%s不存在!",pTask->m_SurveillantPath);
		pTask->m_Log.PrintMsg(szLog,WARNMSG);
	}
    else 
	    pTask->UpLoad();
	return 0;
}

void CFtpServerDlg::OnCheckNormal() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CFtpServerDlg::OnCheckWarn() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CFtpServerDlg::OnCheckError() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CFtpServerDlg::OnCheckShowtime() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CFtpServerDlg::OnStart() 
{
	// TODO: Add your control notification handler code here
	if (bStrat)
	{
       	KillTimer(1);
		CButton *pbt4=(CButton *)GetDlgItem(IDC_START);
		pbt4->SetWindowText("<<启动>>");
		bStrat=FALSE;
		CStatic *pst=(CStatic *)GetDlgItem(IDC_PRINT);
	//	pst->SetWindowText("FTP服务已停止! 启动 请按启动按钮");
		m_listbox.AddString("FTP服务已停止! 启动 请按启动按钮",RGB(0,0,0));
	}
	else
	{
		SetTimer(1,1000*60,NULL);
		CButton *pbt4=(CButton *)GetDlgItem(IDC_START);
		pbt4->SetWindowText("<<停止>>");
		bStrat=TRUE;
		CStatic *pst=(CStatic *)GetDlgItem(IDC_PRINT);
	//	pst->SetWindowText("FTP服务已启动,正在检索要传送的文件,如果在警告中发现没有找到文件.请确认该文件是否还未生成,否则请检查相关配置");
		m_listbox.AddString("FTP服务已启动,正在检索要传送的文件.如果在警告中发现没有找到文件.请确认该文件是否还未生成.");
	}
}

void CFtpServerDlg::OnButtonStart() 
{
	// TODO: Add your control notification handler code here
	m_dlgConfig=new CTaskManager;
	m_dlgConfig->Create(IDD_DIALOGTASK,this);
	m_dlgConfig->ShowWindow(TRUE);
	m_dlgConfig->CenterWindow(NULL);

}


void CFtpServerDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	//CFtpServerApp *pApp = (CFtpServerApp *)AfxGetApp();
	//pApp->onSave();
	delete m_dlgConfig;
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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