📄 prop3.cpp
字号:
// Prop3.cpp : implementation file
//
#include "stdafx.h"
#include "table2.h"
#include "Prop3.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char section[20][20];
char key[20][50][100];
char value[20][50][100];
/////////////////////////////////////////////////////////////////////////////
// CProp3 property page
IMPLEMENT_DYNCREATE(CProp3, CPropertyPage)
CProp3::CProp3() : CPropertyPage(CProp3::IDD)
{
//{{AFX_DATA_INIT(CProp3)
m_path = _T("");
//}}AFX_DATA_INIT
}
CProp3::~CProp3()
{
}
void CProp3::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProp3)
DDX_Text(pDX, IDC_EDIT1, m_path);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProp3, CPropertyPage)
//{{AFX_MSG_MAP(CProp3)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProp3 message handlers
BOOL CProp3::OnSetActive()
{
// TODO: Add your specialized code here and/or call the base class
char lp[10000] ;
memset(lp,0,10000);
GetPrivateProfileSectionNames(lp,10000,m_path);
((CComboBox*)GetDlgItem(IDC_COMBO1))->ResetContent();
((CComboBox*)GetDlgItem(IDC_COMBO2))->ResetContent();
int m_numofsec=getsections(lp);
char lp2[10000];
for(int p=0;p<m_numofsec;p++)
{
memset(lp2,0,10000);
GetPrivateProfileSection(section[p],lp2,10000,m_path);
m_numofkey[p]=getkeys(p,lp2);
}
// TODO: Add extra initialization here
int i;
for(i=0;i<m_numofsec;i++)
((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString(section[i]);
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(m_numofsec);
return CPropertyPage::OnSetActive();
}
int CProp3::getsections(char lp[10000])
{ int i=0,n=0;
if(lp[i]==NULL)
return 0;
int j;
for(j=0;j<20;j++)
memset(section[j],0,20);
int zc = 0;//连续的NULL个数
int sc = 0;//字符串个数
while(zc<2)
{
if(lp[i]=='\0')
{
zc++;
sc++;
i++;
n=0;
}
else
{
zc=0;
section[sc][n]+=lp[i];
i++;
n++;
}
}
return sc-1;
}
int CProp3::getkeys(int p,char lp[10000])
{ int i=0,n=0,m=0;
if(lp[i]==NULL)
return 0;
int j;
for(j=0;j<50;j++)
{
memset(key[p][j],0,100);
memset(value[p][j],0,100);
}
int zc = 0;//连续的NULL个数
int sc = 0;//字符串个数
while(zc<2)
{
if(lp[i]!='#')
{
if(lp[i]=='\0')
{
zc++;
sc++;
i++;
n=0;
}
else if(lp[i]!='=')
{
zc=0;
key[p][sc][n]+=lp[i];
i++;
n++;
}
else
{
i++;
m=0;
if(lp[i]==' ')
i++;
while(lp[i]!='\0'&&lp[i]!='#')
{
value[p][sc][m]+=lp[i];
m++;
i++;
}
i--;
while(lp[i]!='\0')
i++;
}
}
else
{
while(lp[i]!='\0')
{
i++;
}
zc--;
sc--;
}
}
return sc-1;
}
void CProp3::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
index1=((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel();
((CComboBox*)GetDlgItem(IDC_COMBO2))->ResetContent();
int j=0;
for(j=0;j<m_numofkey[index1];j++)
{
((CComboBox*)GetDlgItem(IDC_COMBO2))->AddString(key[index1][j]);
}
((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(0);
GetDlgItem(IDC_EDIT3)->SetWindowText("");
}
void CProp3::OnSelchangeCombo2()
{
// TODO: Add your control notification handler code here
index2=((CComboBox*)GetDlgItem(IDC_COMBO2))->GetCurSel();
((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(index2);
GetDlgItem(IDC_EDIT3)->SetWindowText(value[index1][index2]);
}
void CProp3::OnButton3()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT3)->GetWindowText(value[index1][index2],100);
WritePrivateProfileString(section[index1],key[index1][index2],value[index1][index2],
m_path);
}
void CProp3::OnButton1()
{
// TODO: Add your control notification handler code here
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH,path);
CFileDialog file(TRUE);
file.m_ofn.lpstrInitialDir = path;
if(file.DoModal() == IDOK)
{
m_path = file.GetPathName();
UpdateData(false);
}
OnSetActive();
}
BOOL CProp3::OnKillActive()
{
// TODO: Add your specialized code here and/or call the base class
return CPropertyPage::OnKillActive();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -