VC:读写文件 及 注册表
来源:互联网 发布:mac版word的选项在哪 编辑:程序博客网 时间:2024/05/19 21:18
void CFileView::OnFileWrite()
{
// TODO: Add your command handler code here
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrTitle="我的文件保存对话框";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt="txt";
if(IDOK==fileDlg.DoModal())
{
CFile file(fileDlg.GetFileName(),CFile::modeCreate | CFile::modeWrite);
file.Write("http://www.gaoyuan.org",strlen("http://www.gaoyuan.org"));
file.Close();
}
}
void CFileView::OnFileRead()
{
// TODO: Add your command handler code here
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="我的文件打开对话框";
fileDlg.m_ofn.lpstrFilter="Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
if(IDOK==fileDlg.DoModal())
{
CFile file(fileDlg.GetFileName(),CFile::modeRead);
char *pBuf;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf=new char[dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
file.Close();
MessageBox(pBuf);
}
}
=================================================
串行化读写
void CGraphicView::OnFileWrite()
{
// TODO: Add your command handler code here
CFile file("1.txt",CFile::modeCreate | CFile::modeWrite);
CArchive ar(&file,CArchive::store);
int i=4;
char ch='a';
float f=1.3f;
CString str("http://www.sunxin.org");
ar<<i<<ch<<f<<str;
}
void CGraphicView::OnFileRead()
{
// TODO: Add your command handler code here
CFile file("1.txt",CFile::modeRead);
CArchive ar(&file,CArchive::load);
int i;
char ch;
float f;
CString str;
CString strResult;
ar>>i>>ch>>f>>str;
strResult.Format("%d,%c,%f,%s",i,ch,f,str);
MessageBox(strResult);
}
==============================================================
void CFileView::OnRegWrite()
{
// TODO: Add your command handler code here
HKEY hKey;
DWORD dwAge=30;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\http://www.gaoyuan.org\\admin",&hKey);
RegSetValue(hKey,NULL,REG_SZ,"zhangsan",strlen("zhangsan"));
RegSetValueEx(hKey,"age",0,REG_DWORD,(CONST BYTE*)&dwAge,4);
RegCloseKey(hKey);
}
void CFileView::OnRegRead()
{
// TODO: Add your command handler code here
HKEY hKey;
RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\http://www.gaoyuan.org\\admin",&hKey);
DWORD dwType;
DWORD dwValue;
DWORD dwAge;
RegQueryValueEx(hKey,"age",0,&dwType,(LPBYTE)&dwAge,&dwValue);
CString str;
str.Format("age=%d",dwAge);
MessageBox(str);
}
- VC:读写文件 及 注册表
- VC读写注册表类及用法
- VC++ 读写注册表,注册文件图标关联
- 用vc读写注册表
- VC读写注册表
- vc下读写注册表
- VC++中读写注册表
- VC读写注册表
- VC++中读写注册表
- vc读写注册表
- vc读写注册表
- VC读写注册表操作
- VC读写注册表实例
- VC读写注册表
- VC 读写注册表
- VC++读写注册表
- VC 读写注册表
- VC 注册表读写
- QT:不规则窗口的实现
- ThinkPHP源码剖析
- java多线程源码例子
- base-kernel-device files
- 登陆linux工具网址
- VC:读写文件 及 注册表
- C#复制文件的问题
- 大数处理
- Palindrome
- ListView优化
- android学习笔记之--android中各种java包的功能描述
- hbase修复.META.表与HDFS文件不一致问题
- Android Nine Patch图片及按钮背景
- thinkphp2.1自定义标签的使用(官方文档不够详细)