VC:读写文件 及 注册表
2012-02-01 11:58
260 查看
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);
}
{
// 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配置文件ini的读写
- VC++读写文件
- 文件对话框读写文本文件[VC]
- vc读写注册表
- VC 读写txt文件——FILE *
- VC往PE文件末尾读写数据
- VC操作word和excel文件,查询与读写[依赖office环境]
- VC 编程ANSI环境下读写Unicode文件
- VC++读写INI配置文件
- VC中INI文件读写
- VC++ 文件读写总结
- 配置文件与注册表的读写
- C#中关于文件读写操作和注册表操作
- VC中海量文件读写类设计与应用
- VC文件读写操作总结
- VC 读写注册表
- VC配置文件ini的读写
- VC读写word文件(RTF文件)
- VC++中文件读写汇总