有哪位仁兄用个GetProfileInt,给小菜进行指教,不胜感激

时间:2022-02-13 17:17:21
我有一个程序的初始化信息打算写成INI文本文件,想方便的读写,我想用GetProfileInt、writePrivateProfileString等函数进行,不知能否,有否其它更好的办法,望有哪位仁兄用个GetProfileInt这个函数,WritePrivateProfileString给小菜进行指教,不胜感激,

6 个解决方案

#1


GetProfileInt()只能读Win.ini文件中某个指定段的某个键的值。WriteProfileString()完成相反的功能。
如果你想把信息写入Win.ini中的话,可以用这两个文件,用法很简单的。

#2


WriteProfileInt,WriteProfileString用于想注册表或应用程序的。INI文件中写入信息,GeytProfileInt,GetProfileString则用于从注册表或。INT文件中读取信息。GetProfileInt返回相应的第三个参数的入口号。

#3


AfxGetApp()->WriteProfileString("discover", "IP", str);

AfxGetApp()->GetProfileString("discover", "IP");

试一下就知道,生成一个youproject.ini文件在系统winnt目录下

#4


我这有个事例。
响应WM_CLSOE
WINDOWPLACEMENT WndStatus;
WndStatus.length = sizeof(WINDOWNPLACEMENT);
GetWindowPlacement(&WndStatus);
AfxGetApp()->WriteProfileInt("WNDSTATUS","FLAG",WndStatus.flags);
AfxGetApp()->WriteProfileInt("WNDSTATUS","SHOWCMD",WndStatus.showCmd);
AfxGetApp()->WriteProfileInt("WNDSTATUS","LEFT",WndStatus.rcNormalPosition.left);
AfxGetApp()->WriteProfileInt("WNDSTATUS","RIGHT",WndStatus.rcNormalPosition.right);
AfxGetApp()->WriteProfileInt("WNDSTATUS","TOP",WndStatus.rcNormalPosition.top);
AfxGetApp()->WriteProfileInt("WNDSTATUS","BOTTOM",WndStatus.rcNormalPosition.bottom);
SaveBarState(AfxGetApp()->m_pszProfileName);
CFrameWnd::OnClose();

#5


在程序重启时,读取注册表信息,并重新设置窗口信息。
添加bool m_bFirst;
响应CMainFrame的ActivateFrame消息处理函数
void CMainFrame::ActiveFrame(int nCmdShow)
{
  if(m_bFirst)//用来表示是否初次激活窗口
   {
     m_bFirst = FALSE;
     WINDOWPLACEMENT WndStatus;
     CRect rect;
     rect.left =AfxGetApp()->GetProfileInt("WNDSTATUS","LEFT",100);
  rect.top=AfxGetApp()->GetProfileInt("WNDSTATUS","TOP",100);
rect.right =AfxGetApp()->GetProfileInt("WNDSTATUS","RIGHT",500);
rect.bottom =AfxGetApp()->GetProfileInt("WNDSTATUS","BOTTOM",400);
WndStatus.rcNormalPosition = rect;
WndStatus.flags= AfxGetApp()->GetProfileInt("WNDSTATUS","FLAG",0);
nCmdShow = AfxGetApp()->GetProfileInt("WNDSTATUS","SHOWCMD",SW_SHOW);
WndStatus.showCmd = nCmdShow;
WndStatus.ptMinPosition = CPoint(0,0);
WndStatus.ptMaxPosition = CPoint(-GetSystemMetrics(SM_CXBORDER),GetSysTemMetrics(SM_CYBORDER));
LoadBarState(AfxGetApp()->m_pszProfileName);
SetWindowPlacement(&WndStatus);
 }
CFrameWnd::ActivateFrame(nCmdShow);
}

#6


更正:sizeof(WINDOWPLACEMENT),GetSystemMetrics

#1


GetProfileInt()只能读Win.ini文件中某个指定段的某个键的值。WriteProfileString()完成相反的功能。
如果你想把信息写入Win.ini中的话,可以用这两个文件,用法很简单的。

#2


WriteProfileInt,WriteProfileString用于想注册表或应用程序的。INI文件中写入信息,GeytProfileInt,GetProfileString则用于从注册表或。INT文件中读取信息。GetProfileInt返回相应的第三个参数的入口号。

#3


AfxGetApp()->WriteProfileString("discover", "IP", str);

AfxGetApp()->GetProfileString("discover", "IP");

试一下就知道,生成一个youproject.ini文件在系统winnt目录下

#4


我这有个事例。
响应WM_CLSOE
WINDOWPLACEMENT WndStatus;
WndStatus.length = sizeof(WINDOWNPLACEMENT);
GetWindowPlacement(&WndStatus);
AfxGetApp()->WriteProfileInt("WNDSTATUS","FLAG",WndStatus.flags);
AfxGetApp()->WriteProfileInt("WNDSTATUS","SHOWCMD",WndStatus.showCmd);
AfxGetApp()->WriteProfileInt("WNDSTATUS","LEFT",WndStatus.rcNormalPosition.left);
AfxGetApp()->WriteProfileInt("WNDSTATUS","RIGHT",WndStatus.rcNormalPosition.right);
AfxGetApp()->WriteProfileInt("WNDSTATUS","TOP",WndStatus.rcNormalPosition.top);
AfxGetApp()->WriteProfileInt("WNDSTATUS","BOTTOM",WndStatus.rcNormalPosition.bottom);
SaveBarState(AfxGetApp()->m_pszProfileName);
CFrameWnd::OnClose();

#5


在程序重启时,读取注册表信息,并重新设置窗口信息。
添加bool m_bFirst;
响应CMainFrame的ActivateFrame消息处理函数
void CMainFrame::ActiveFrame(int nCmdShow)
{
  if(m_bFirst)//用来表示是否初次激活窗口
   {
     m_bFirst = FALSE;
     WINDOWPLACEMENT WndStatus;
     CRect rect;
     rect.left =AfxGetApp()->GetProfileInt("WNDSTATUS","LEFT",100);
  rect.top=AfxGetApp()->GetProfileInt("WNDSTATUS","TOP",100);
rect.right =AfxGetApp()->GetProfileInt("WNDSTATUS","RIGHT",500);
rect.bottom =AfxGetApp()->GetProfileInt("WNDSTATUS","BOTTOM",400);
WndStatus.rcNormalPosition = rect;
WndStatus.flags= AfxGetApp()->GetProfileInt("WNDSTATUS","FLAG",0);
nCmdShow = AfxGetApp()->GetProfileInt("WNDSTATUS","SHOWCMD",SW_SHOW);
WndStatus.showCmd = nCmdShow;
WndStatus.ptMinPosition = CPoint(0,0);
WndStatus.ptMaxPosition = CPoint(-GetSystemMetrics(SM_CXBORDER),GetSysTemMetrics(SM_CYBORDER));
LoadBarState(AfxGetApp()->m_pszProfileName);
SetWindowPlacement(&WndStatus);
 }
CFrameWnd::ActivateFrame(nCmdShow);
}

#6


更正:sizeof(WINDOWPLACEMENT),GetSystemMetrics