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

📄 filedlg.cpp

📁 ARM&WINCE实验与实践(基于S3C2410)第2章 Windows CE.net应用程序开发
💻 CPP
字号:
// FileDlg.cpp : implementation file
//

#include "stdafx.h"
#include "File.h"
#include "FileDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFileDlg dialog

CFileDlg::CFileDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFileDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFileDlg)
	m_FileName = _T("");
	m_Content = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFileDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFileDlg)
	DDX_Text(pDX, IDC_EDIT_FILENAME, m_FileName);
	DDX_Text(pDX, IDC_EDIT_CONTENT, m_Content);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFileDlg, CDialog)
	//{{AFX_MSG_MAP(CFileDlg)
	ON_BN_CLICKED(IDC_BUTTON_WRITE, OnButtonWrite)
	ON_BN_CLICKED(IDC_BUTTON_CLEARN, OnButtonClearn)
	ON_BN_CLICKED(IDC_BUTTON_READ, OnButtonRead)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileDlg message handlers

BOOL CFileDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}


//写文件操作
void CFileDlg::OnButtonWrite()
{
	// TODO: Add your control notification handler code here
	CFile MyFile;
	UpdateData(true);									//更新数据
	if(m_FileName!=_T(""))								//文件名不能为空
	{
		if(!MyFile.Open (_T("\\"+m_FileName+".dat"),CFile::modeCreate|CFile::modeWrite))
		{												//创建文件
			AfxMessageBox(_T("open File faled"));		//创建失败,返回
			return;
		}
		MyFile.SeekToBegin();							//文件指针到文件头
		MyFile.Write (m_Content,m_Content.GetLength()*2);//写文件
		MyFile.Close ();								//关闭文件
		AfxMessageBox(_T("Write OK"));					//输出写成功消息
	}
	else
	AfxMessageBox(_T("Please Input File Name"));		//文件名为空
}


//清除按钮
void CFileDlg::OnButtonClearn() 
{
	// TODO: Add your control notification handler code here

	CEdit *pEditContent;
	pEditContent=(CEdit*)GetDlgItem(IDC_EDIT_CONTENT);	//获取编辑框控件
	m_Content=_T("");									//清空内容
	UpdateData(false);									//更新显示
}

//读按钮
void CFileDlg::OnButtonRead() 
{
	// TODO: Add your control notification handler code here
	CFile MyFile;
	TCHAR str[100];
	DWORD count;
	ZeroMemory(str,100);
	UpdateData(true);									//更新数据

	if(m_FileName!=_T(""))
	{
		if(!MyFile.Open (_T("\\"+m_FileName+".dat"),CFile::modeRead))//打开文件
		{
			AfxMessageBox(_T("open File faled"));
			return;										//创建失败,返回
		}
		//MyFile.SeekToBegin();							//移动文件指针到文件头
		long dwLength =MyFile.GetLength() ;				//得到文件长度
		count=MyFile.Read (str,dwLength);				//读文件
			m_Content=str;								//将文件内容输出到编辑框
		MyFile.Close ();								//关闭文件
		UpdateData(false);								//更新显示
		AfxMessageBox(_T("Read OK"));					//输出读成功消息
	}
	else
	AfxMessageBox(_T("Please Input File Name"));		//文件名为空
}

⌨️ 快捷键说明

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