本人某个项目中的一部分代码,与大家分享。
Region是自己定义的一个类。
程序中定义了四个region容器对象:vector<Region> Reg[4];
在视频窗口画图的参数保存到上述容器中,下面程序实现参数保存到region.ini文件并可以程序启动
时读入这些参数。
class Region
{
public:
int channel;
int function;
CPoint point1;
CPoint point2;
int graphType;
COLORREF color;
// int state;
// bool bExist;
public:
int Match();
void DrawRegion();
void DeleteRegion();
void SaveRegion();
void LoadRegion();
Region();
virtual ~Region();
};
CVideoWin::CVideoWin()
{
m_bIsDraw = FALSE;
FILE *stream;
Region RegTmp;
int assignedBits;
int channel;
stream = fopen( "region.ini", "r" );
if( stream == NULL)
return;
else
{
fseek( stream, 0, SEEK_SET );
while(1)
{
assignedBits = fscanf( stream, "%d", &channel );
if( assignedBits != 1 )
{
fclose( stream );
return;
}
RegTmp.channel = channel;
fscanf( stream, "%d", &RegTmp.function );
fscanf( stream, "%d", &RegTmp.point1.x );
fscanf( stream, "%d", &RegTmp.point1.y );
fscanf( stream, "%d", &RegTmp.point2.x );
fscanf( stream, "%d", &RegTmp.point2.y );
fscanf( stream, "%d", &RegTmp.graphType );
fscanf( stream, "%d", &RegTmp.color );
Reg[channel].push_back(RegTmp);
// fclose( stream );
}
}
}
CVideoWin::~CVideoWin()
{
int i,j;
Region RegTmp;
FILE* stream;
stream = fopen( "region.ini","w+" );
fclose(stream);
for(i=0;i<4;i++)
for(j=0;j<Reg[i].size();j++)
{
RegTmp = Reg[i].at(j);
RegTmp.SaveRegion();
}
}
void Region::SaveRegion()
{
FILE *stream;
stream = fopen( "region.ini","a" );
fprintf( stream,"%d/n%d/n%d/n%d/n%d/n%d/n%d/n%d/n",
channel,function,point1.x,point1.y,point2.x,point2.y,graphType,color );
fclose( stream );
}