Section,szWindowpos);
if(strBuffer,IsEmpty()) return FALSE;
WINDOWPLACEMENT wp;//窗口位置数据结构
int nRead=-stscanf(strBuffer,szFonmat,
&wp.flags,&wp,showCmd,//为数据结构读取数值
&wp.[tMinposition.x,&wp.ptMinposition.y,
&wp.ptMaxposition.x,&wp.ptMaxposition.y,
&wp.rcNormalplsition,left,&wp.rcNormalposition.top,
&wp.rcNormalposition.right,&wp.rcNormalposition.bot,tom);
if(nRead!=10) return FALSE;
wp.length=sizeof wp;//结构大小
*pwp=wp; //结构传递
return TRUE;
}
static void PASCAL NEAR WriteWindowPlacement(
LPWINDOWPLACEMENT pwp)
{//窗口位置状态写入函数,定到注册文件
TCHAR szBuffer[sizeof("-32767")*8+sizeof("65535")*21];
wsprintf(szBuffer,szFormat,//将参数值转换为字符串
pwp->flags.pwp_>showCmd,
pwp_>ptMinPosition.x.pwp->ptMinposition.y,
pwp->ptMaxPosition,x,pwp->ptMaxPosition.y,
pwp->rcNormalPosition,left,pwp->rcNormalPosition.top,
pwp=rcNormalPosition.pwp=>rcNormalPosition.bottom);
AfxGetApp()->WriteProfileString(xzSection.szWindowPos.szBuffer);
}
4,在应用
程序建立函数OnCreate()中增加状态读取和设置功能
WINDOWPLACEMENT wp;//保存主窗口及工具栏窗口位置状态
if (ReadWindoePlacement(&wp))//读取位置状态信息
SetWindowPlacement(&wp);//设置位置状态信息
5,在应用
程序建立函数NnCreate()中增加工具栏等状态恢复功能
m-wndDockToolBar.SetColumns(AfxGetApp()-GetProfileInt(-T("General"),-T("ColumnsT"),3));//恢复列格式,默认为3m-wndDockNextBar.SetColumns(AfxGetApp()->GetProfileInt(-T("General"-T("ColumnsN"),3));
LoadBarState(-T("General"));//恢复保存的状态和位置//其它工具状态的恢复
6。在应用
程序关闭函数OnClose()中完善状态保存功能
void CMainFrame::OnClose()
{ //保存工具栏等的状态
SaveBarState(-T("General"))//保存工具栏状态//其它工具状态的保存
AfxGetApp()->WriteProfileInt(-T("General"),//写入列数
-T("ColumnsT"),m-wndDockTAoolBar.GetColumns());
AfxGetDApp ()=>WriteProfileInt(-T("General"),//写入列数
-T("ColumnsN"),m-wndDockNextBar.GetColumns());
AfxGetApp()->WriteProfileInt(-T("General"),
-T("Color"),(m-bColor!=0));//写入颜色值
AfxGetApp()->WriteProfileInt(-T("General"),
-T("ToolTips"),(m-bToolTips!=0));//写入提示功能
WINDOWPLACEMENT wp;
wp.length=sizeof wp;
if (GetWindowPlacement(&wp)){
wp.flags=0;
if (IsZoomed()) wp.flags|=WPF=RESTORETOMAXIMIZED;//如果窗口被放大,则保存为最大化状态
WriteWindowPlacement(&wp);
}
CFrameWnd::OnClose();
}