[PlayLyric]
left=612
top=184
right=882
bottom=644
[PlayerList]
left=342
top=352
right=612
bottom=644
char apppath[256];
GetCurrentDirectory(256,apppath);
CString path;
path.Format("%s",apppath);
path+="Play.ini";
this->m_left = GetPrivateProfileInt("PlayerList","left",this->m_left,path);
this->m_top = GetPrivateProfileInt("PlayerList","top",this->m_top,path);
this->m_right= GetPrivateProfileInt("PlayerList","right",this->m_right,path);
this->m_bottom= GetPrivateProfileInt("PlayerList","bottom",this->m_bottom,path);
读出来后m_left竟然为1380,根本就不是342.m_top为1498,不是352。
m_left默认值为324,m_top默认值为352
7 个解决方案
#1
看你贴的没问题,其它肯定有影响
#2
代码本身没有什么问题
GetCurreentDirectory()得到的路径是否正确?
GetCurreentDirectory()得到的路径是否正确?
#3
path的文件路径很有可能不正确~~~~`你要是编译调试下的话,不会得到Debug文件目录下的~~~
#4
path+="Play.ini";应该为path+="\\Play.ini";
我在程序推出时调用了WritePrivateProfileString来写,结果第二次运行时读取INI文件时同样出现读取出错误的值
char apppath[256];
GetCurrentDirectory(256,apppath);
CString path;
path.Format("%s",apppath);
path+="\\Play.ini";
char string[32];
sprintf(string,"%d",m_left);
BOOL resurt=WritePrivateProfileString("PlayerList","left",string,path);
我在程序推出时调用了WritePrivateProfileString来写,结果第二次运行时读取INI文件时同样出现读取出错误的值
char apppath[256];
GetCurrentDirectory(256,apppath);
CString path;
path.Format("%s",apppath);
path+="\\Play.ini";
char string[32];
sprintf(string,"%d",m_left);
BOOL resurt=WritePrivateProfileString("PlayerList","left",string,path);
#5
应该是读数据的时候读错位了。
#6
在获取文件路径上有问题.GetCurrentDirectory(...)获得的路径并不一定是Play.ini的路径.
2,path+="\\Play.ini".
这里有一个调试通过的代码:
#include "stdafx.h"
#include <Windows.h>
//#include <afxstr.h>
#include <atlstr.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR apppath[256];
memset(apppath,0,256);
GetModuleFileName(NULL,apppath,255);//GetCurrentDirectory(256,apppath)
TCHAR* p = _tcsrchr(apppath,'\\');
p[1]=0;
//m_path = apppath;
CString path=apppath;
//path.Format("%s",apppath);
path+="\\Play.ini";
const CString pl="PlayerList";
const CString L="left";
int m_left = GetPrivateProfileInt(pl,L,1,path);
/*int m_top = GetPrivateProfileInt(pl,"top",1,path);
int m_right= GetPrivateProfileInt(pl,"right",1,path);
int m_bottom= GetPrivateProfileInt(pl,"bottom",1,path);*/
printf("%d",m_left);
getchar();
return 0;
}
2,path+="\\Play.ini".
这里有一个调试通过的代码:
#include "stdafx.h"
#include <Windows.h>
//#include <afxstr.h>
#include <atlstr.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR apppath[256];
memset(apppath,0,256);
GetModuleFileName(NULL,apppath,255);//GetCurrentDirectory(256,apppath)
TCHAR* p = _tcsrchr(apppath,'\\');
p[1]=0;
//m_path = apppath;
CString path=apppath;
//path.Format("%s",apppath);
path+="\\Play.ini";
const CString pl="PlayerList";
const CString L="left";
int m_left = GetPrivateProfileInt(pl,L,1,path);
/*int m_top = GetPrivateProfileInt(pl,"top",1,path);
int m_right= GetPrivateProfileInt(pl,"right",1,path);
int m_bottom= GetPrivateProfileInt(pl,"bottom",1,path);*/
printf("%d",m_left);
getchar();
return 0;
}
#7
GetPrivateProfileInt("PlayerList","left",this->m_left,path);
GetPrivateProfileInt("PlayerList","top",this->m_top,path);
GetPrivateProfileInt("PlayerList","right",this->m_right,path);
GetPrivateProfileInt("PlayerList","bottom",this->m_bottom,path);
直接这样写就没问题,至于你的那个,我想不出有什么问题
GetPrivateProfileInt("PlayerList","top",this->m_top,path);
GetPrivateProfileInt("PlayerList","right",this->m_right,path);
GetPrivateProfileInt("PlayerList","bottom",this->m_bottom,path);
直接这样写就没问题,至于你的那个,我想不出有什么问题
#1
看你贴的没问题,其它肯定有影响
#2
代码本身没有什么问题
GetCurreentDirectory()得到的路径是否正确?
GetCurreentDirectory()得到的路径是否正确?
#3
path的文件路径很有可能不正确~~~~`你要是编译调试下的话,不会得到Debug文件目录下的~~~
#4
path+="Play.ini";应该为path+="\\Play.ini";
我在程序推出时调用了WritePrivateProfileString来写,结果第二次运行时读取INI文件时同样出现读取出错误的值
char apppath[256];
GetCurrentDirectory(256,apppath);
CString path;
path.Format("%s",apppath);
path+="\\Play.ini";
char string[32];
sprintf(string,"%d",m_left);
BOOL resurt=WritePrivateProfileString("PlayerList","left",string,path);
我在程序推出时调用了WritePrivateProfileString来写,结果第二次运行时读取INI文件时同样出现读取出错误的值
char apppath[256];
GetCurrentDirectory(256,apppath);
CString path;
path.Format("%s",apppath);
path+="\\Play.ini";
char string[32];
sprintf(string,"%d",m_left);
BOOL resurt=WritePrivateProfileString("PlayerList","left",string,path);
#5
应该是读数据的时候读错位了。
#6
在获取文件路径上有问题.GetCurrentDirectory(...)获得的路径并不一定是Play.ini的路径.
2,path+="\\Play.ini".
这里有一个调试通过的代码:
#include "stdafx.h"
#include <Windows.h>
//#include <afxstr.h>
#include <atlstr.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR apppath[256];
memset(apppath,0,256);
GetModuleFileName(NULL,apppath,255);//GetCurrentDirectory(256,apppath)
TCHAR* p = _tcsrchr(apppath,'\\');
p[1]=0;
//m_path = apppath;
CString path=apppath;
//path.Format("%s",apppath);
path+="\\Play.ini";
const CString pl="PlayerList";
const CString L="left";
int m_left = GetPrivateProfileInt(pl,L,1,path);
/*int m_top = GetPrivateProfileInt(pl,"top",1,path);
int m_right= GetPrivateProfileInt(pl,"right",1,path);
int m_bottom= GetPrivateProfileInt(pl,"bottom",1,path);*/
printf("%d",m_left);
getchar();
return 0;
}
2,path+="\\Play.ini".
这里有一个调试通过的代码:
#include "stdafx.h"
#include <Windows.h>
//#include <afxstr.h>
#include <atlstr.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR apppath[256];
memset(apppath,0,256);
GetModuleFileName(NULL,apppath,255);//GetCurrentDirectory(256,apppath)
TCHAR* p = _tcsrchr(apppath,'\\');
p[1]=0;
//m_path = apppath;
CString path=apppath;
//path.Format("%s",apppath);
path+="\\Play.ini";
const CString pl="PlayerList";
const CString L="left";
int m_left = GetPrivateProfileInt(pl,L,1,path);
/*int m_top = GetPrivateProfileInt(pl,"top",1,path);
int m_right= GetPrivateProfileInt(pl,"right",1,path);
int m_bottom= GetPrivateProfileInt(pl,"bottom",1,path);*/
printf("%d",m_left);
getchar();
return 0;
}
#7
GetPrivateProfileInt("PlayerList","left",this->m_left,path);
GetPrivateProfileInt("PlayerList","top",this->m_top,path);
GetPrivateProfileInt("PlayerList","right",this->m_right,path);
GetPrivateProfileInt("PlayerList","bottom",this->m_bottom,path);
直接这样写就没问题,至于你的那个,我想不出有什么问题
GetPrivateProfileInt("PlayerList","top",this->m_top,path);
GetPrivateProfileInt("PlayerList","right",this->m_right,path);
GetPrivateProfileInt("PlayerList","bottom",this->m_bottom,path);
直接这样写就没问题,至于你的那个,我想不出有什么问题