优秀的手机游戏下载!
首页 c++里我想用WritePrivateProfileString写入一个HWND类型的值该怎么做?

c++里我想用WritePrivateProfileString写入一个HWND类型的值该怎么做?

发布时间:2024-01-11 00:20:34 编辑:打包星星 浏览:768

//HWND是unsigned long

//LPCTSTR会是const wchar_t*或者const char*

//保存桌面句柄到D:\test.ini里

HWND hd = ::GetDesktopWindow()

TCHAR Tmp[32]

_stprintf(Tmp, _T(“%d”), hd)

WritePrivateProfileString(_T(“section”), _T(“key”), Tmp, _T(“D:\\test.ini”))

ini文件WritePrivateProfileString无法写入,为什么

int Internal

int InternalHigh

int Offset

int OffSetHigh

int hEvent

}

[System.Runtime.InteropServices.DllImport(“kernel32.dll”)]

private static extern int CreateFile(string lpFileName, uint dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile)

[System.Runtime.InteropServices.DllImport(“kernel32.dll”)]

private static extern bool WriteFile(int hFile, byte[] lpBuffer, int nNumberOfBytesToWrite, out int lpNumberOfBytesWritten, out OVERLAPPED lpOverlapped)

[System.Runtime.InteropServices.DllImport(“kernel32.dll”)]

private static extern bool CloseHandle(int hObject)

private int iHandle

public bool Open()

{

iHandle = CreateFile(“LPT1:”, (uint)FileAccess.ReadWrite, 0, 0, (int)FileMode.Open, 0, 0)

if (iHandle != -1)

{

return true

}

else

{

return false

}

c# WritePrivateProfileString修改配置文件,出现重复的组名

配置文件中经常用到ini文件,在VC中其函数分别为:

写入.ini文件:

BOOL WritePrivateProfileString(

LPCTSTR lpAppName, // INI文件中的一个字段名[节名]可以有很多个节名

LPCTSTR lpKeyName, // lpAppName 下的一个键名,也就是里面具体的变量名

LPCTSTR lpString, // 键值,也就是数据

LPCTSTR lpFileName // INI文件的路径

)

读取.ini文件:

DWORD GetPrivateProfileString(

LPCTSTR lpAppName,// INI文件中的一个字段名[节名]可以有很多个节名

LPCTSTR lpKeyName,// lpAppName 下的一个键名,也就是里面具体的变量名

LPCTSTR lpDefault,// 如果lpReturnedString为空,则把个变量赋给lpReturnedString

LPTSTR lpReturnedString, // 存放键值的指针变量,用于接收INI文件中键值(数据)的接收缓冲区

DWORD nSize,// lpReturnedString的缓冲区大小

LPCTSTR lpFileName// INI文件的路径

c++写入ini文件 WritePrivateProfileString函数参数错误,求大神,我用的是控制台。vs2015

ArrayList al=new ArrayList()

do

{

产生一组随机数

if(!al.Contains(你新产生的那组随机数))

{

c++里我想用WritePrivateProfileString写入一个HWND类型的值该怎么做?

al.add(你新产生的那组随机数)

}

}

while(al.Contains(你新产生的那组随机数))

还是好好看看 ini文件相关操作的API函数说明吧:

将信息写入.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文件名,如果没有指定完整路径名,则会在windows目录(默认)查找文件。如果文件没有找到,则函数会在windows目录创建它。

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

GetPrivateProfileString(“StudentInfo”,”Name”,”默认姓名”,strStudName.GetBuffer(MAX_PATH),MAX_PATH,”c:\\stud\\student.ini”)

执行后 strStudName 的值为:”张三”,若前两个参数有误,其值为:”默认姓名”.

注意:如果在读入的ini文件不存在,则按默认值生成相应的ini文件

以上就是关于c++里我想用WritePrivateProfileString写入一个HWND类型的值该怎么做?全部的内容,如果了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

更多相关资讯

//HWND是unsigned long //LPCTSTR会是const wchar_t*或者const char* //保存桌面句柄到D:\test.ini…
查看详情
//HWND是unsigned long //LPCTSTR会是const wchar_t*或者const char* //保存桌面句柄到D:\test.ini…
查看详情
//HWND是unsigned long //LPCTSTR会是const wchar_t*或者const char* //保存桌面句柄到D:\test.ini…
查看详情
相关资讯
猜你喜欢