对于GetPrivateProfileString的问题
使用GetPrivateProfileString的时候,窗口不能正常显示,会报错关闭,代码如下:
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static HDC hdc;
static PAINTSTRUCT ps;
hdc=GetDC(hWnd);
static int PosY=10;
char ch[]="";
LPCSTR str;
switch(uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_CREATE:
GetPrivateProfileString("BackGround","Path",NULL,ch,18,".\\current.ini");
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
SetBkColor(hdc,RGB(255,255,255));
SetTextColor(hdc,RGB(0,0,0));
str=ch;
TextOut(hdc,10,PosY,str,strlen(str));
EndPaint(hWnd,&ps);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
ini 文件里面的内容是:
[BackGround]
Path=McDou/McDou.bmp
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static HDC hdc;
static PAINTSTRUCT ps;
hdc=GetDC(hWnd);
static int PosY=10;
char ch[]="";
LPCSTR str;
switch(uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_CREATE:
GetPrivateProfileString("BackGround","Path",NULL,ch,18,".\\current.ini");
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
SetBkColor(hdc,RGB(255,255,255));
SetTextColor(hdc,RGB(0,0,0));
str=ch;
TextOut(hdc,10,PosY,str,strlen(str));
EndPaint(hWnd,&ps);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
ini 文件里面的内容是:
[BackGround]
Path=McDou/McDou.bmp
...全文
相关推荐
VC 读取INI文件
- 注意字符串和整数之间的转换,避免数据类型不匹配导致的问题。- 当使用双反斜杠(`\\`)作为路径分隔符时,在字符串中只需输入一个反斜杠(`\`)即可。
VB 局域网对战俄罗斯方块源码
它包括获取键值、查找键和节、判断有效性的功能,并解决了使用GetPrivateProfileString函数时的问题。此外,还包含
OpenWriteioi_Demo.rar
**解决bug**: "OpenWriteioi_Demo"中提到已经解决了一些bug,这可能涉及到文件读写中的常见问题,如文件未找到、权限错误、内存溢出、数据不匹配等。
c#读写ini文件 程序代码
(其他逻辑)}```这两个方法不仅涉及到了读写INI文件的操作,还包括了文件路径的构建、异常处理等实际应用场景中可能遇到的问题。
INI 文件读取实用程序:通过提供应用程序和密钥字符串读取 INI 文件条目。-matlab开发
这个"INI文件读取实用程序"就是为了解决这一问题而设计的。它仿照了C语言的GetPrivateProfileString函数,使得MATLAB用户也能方便地从INI文件中检索信息。


