b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

writeprivateprofilestring_inifilepath_getmodulefilename

电脑杂谈  发布时间:2017-01-21 17:12:45  来源:网络整理

::WritePrivateProfileString( _T("Options"), _T("Name"), m_strName, pApp->m_szIni );

INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString 收藏

在我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下:

一.将信息写入.INI文件中.

1.所用的WINAPI函数原型为:

BOOL WritePrivateProfileString(

LPCTSTR lpAppName,

LPCTSTR lpKeyName,

LPCTSTR lpString,

LPCTSTR lpFileName

);

其中各参数的意义:

LPCTSTR lpAppName 是INI文件中的一个字段名.

LPCTSTR lpKeyName 是lpAppName下的一个键名,通俗讲就是变量名.

LPCTSTR lpString 是键,也就是变量的,不过必须为LPCTSTR型或CString型的.

LPCTSTR lpFileName 是完整的INI文件名.

2.具体使用方法:设现有一名学生,需把他的姓名和年龄写入 c:\stud\student.ini 文件中.

CString strName,strTemp;

int nAge;

strName="张三";

nAge=12;

::WritePrivateProfileString("StudentInfo","Name",strName,"c:\\stud\\student.ini");

此时c:\stud\student.ini文件中的内容如下:

[StudentInfo]

Name=张三

3.要将学生的年龄保存下来,只需将整型的变为字符型即可:

strTemp.Format("%d",nAge);

::WritePrivateProfileString("StudentInfo","Age",strTemp,"c:\\stud\\student.ini");

二.将信息从INI文件中读入程序中的变量.

1.所用的WINAPI函数原型为:

DWORD GetPrivateProfileString(

LPCTSTR lpAppName,

LPCTSTR lpKeyName,

LPCTSTR lpDefault,

LPTSTR lpReturnedString,

DWORD nSize,

LPCTSTR lpFileName

);

其中各参数的意义:

前二个参数与 WritePrivateProfileString中的意义一样.

lpDefault : 如果INI文件中没有前两个参数指定的字段名或键名,则将此赋给变量.

lpReturnedString : 接收INI文件中的的CString对象,即目的缓存器.

nSize : 目的缓存器的大小.

lpFileName : 是完整的INI文件名.

2.具体使用方法:现要将上一步中写入的学生的信息读入程序中.

CString strStudName;

int nStudAge;


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27849-1.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...