Hi Greg,
Try this:
BOOL ReadWindowPlacement( LPCTSTR lpWindow, LPWINDOWPLACEMENT pWP )
{
CString strBuffer=
AfxGetApp()->GetProfileString( _T("Settings\\Windows"), lpWindow );
if ( strBuffer.IsEmpty() )
{
return( FALSE );
}
TCHAR szFormat[]= _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
WINDOWPLACEMENT wp;
int nRead= _stscanf( strBuffer, szFormat,
&wp.flags, &wp.showCmd,
&wp.ptMinPosition.x, &wp.ptMinPosition.y,
&wp.ptMaxPosition.x, &wp.ptMaxPosition.y,
&wp.rcNormalPosition.left, &wp.rcNormalPosition.top,
&wp.rcNormalPosition.right, &wp.rcNormalPosition.bottom );
if ( nRead != 10 )
{
return( FALSE );
}
wp.length= sizeof( wp );
*pWP= wp;
return( TRUE );
Quote:
}
void WriteWindowPlacement( LPCTSTR lpWindow, LPWINDOWPLACEMENT pWP )
{
TCHAR szBuffer[sizeof("-32767")*8 + sizeof("65535")*2];
TCHAR szFormat[]= _T("%u,%u,%d,%d,%d,%d,%d,%d,%d,%d");
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.right, pWP->rcNormalPosition.bottom );
AfxGetApp()->WriteProfileString( _T("Settings\\Windows"), lpWindow,
szBuffer );
Quote:
}
void CMainFrame::OnClose()
{
// Check if user wants to save application settings.
if ( theApp.m_cfg.GetSaveSettingsFlag() )
{
// Save the main windows position.
WINDOWPLACEMENT wp;
wp.length= sizeof( wp );
if ( GetWindowPlacement( &wp ) )
{
wp.flags= 0;
if ( IsZoomed() )
{
wp.flags |= WPF_RESTORETOMAXIMIZED;
}
// and write it to the .INI file
::WriteWindowPlacement( _T("Main"), &wp );
} // if ( GetWindowPlacement( &wp ) )
// Save the rest of the application settings.
theApp.m_cfg.SaveSettings();
SaveBarState( _T("ToolBars\\") );
} // if ( theApp.m_cfg.GetSaveSettingsFlag() )
CMDIFrameWnd::OnClose();
Quote:
}
int CMainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct )
{
if ( CMDIFrameWnd::OnCreate( lpCreateStruct ) == -1 )
{
return( -1 );
}
WINDOWPLACEMENT wp;
if ( ::ReadWindowPlacement( _T("Main"), &wp ) )
{
SetWindowPlacement( &wp );
}
if ( !m_wndMainBar.Create( this ) ||
!m_wndMainBar.LoadToolBar( IDR_MAINFRAME ) )
{
TRACE0( _T("Failed to create toolbar\n") );
return( -1 ); // fail to create
}
m_wndMainBar.SetBarStyle( m_wndMainBar.GetBarStyle()|
CBRS_TOOLTIPS| CBRS_FLYBY| CBRS_SIZE_DYNAMIC );
m_wndMainBar.SetWindowText( _T("Main Toolbar") );
m_wndMainBar.EnableDocking( CBRS_ALIGN_ANY );
if ( !m_wndUsrMgrBar.Create( this,
WS_CHILD| WS_VISIBLE| CBRS_TOP, IDR_SC3USRMGR ) ||
!m_wndUsrMgrBar.LoadToolBar( IDR_SC3USRMGR ) )
{
TRACE0( _T("Failed to create User Manager toolbar\n") );
return( -1 ); // fail to create
}
m_wndUsrMgrBar.SetBarStyle( m_wndUsrMgrBar.GetBarStyle()|
CBRS_TOOLTIPS| CBRS_FLYBY| CBRS_SIZE_DYNAMIC );
m_wndUsrMgrBar.SetWindowText( _T("User Manager Toolbar") );
m_wndUsrMgrBar.EnableDocking( CBRS_ALIGN_ANY );
if ( !m_wndStatusBar.Create( this ) ||
!m_wndStatusBar.SetIndicators( indicators,
sizeof( indicators ) / sizeof( UINT ) ) )
{
TRACE0( _T("Failed to create status bar\n") );
return( -1 ); // fail to create
}
EnableDocking( CBRS_ALIGN_ANY );
DockControlBar( &m_wndUsrMgrBar );
DockControlBarLeftOf( &m_wndMainBar, &m_wndUsrMgrBar );
LoadBarState( _T("ToolBars\\") );
// The User Manager control bar should not be visible right now.
ShowControlBar( &m_wndUsrMgrBar, FALSE, FALSE );
return( 0 );
Quote:
}
void CMainFrame::OnMove( int x, int y )
{
CMDIFrameWnd::OnMove( x, y );
// Check if user wants to save application settings.
if ( theApp.m_cfg.GetSaveSettingsFlag() )
{
// Save the main windows position.
WINDOWPLACEMENT wp;
wp.length= sizeof( wp );
if ( GetWindowPlacement( &wp ) )
{
wp.flags= 0;
if ( IsZoomed() )
{
wp.flags |= WPF_RESTORETOMAXIMIZED;
}
// and write it to the .INI file
::WriteWindowPlacement( _T("Main"), &wp );
} // if ( GetWindowPlacement( &wp ) )
} // if ( theApp.m_cfg.GetSaveSettingsFlag() )
Quote:
}
void CMainFrame::OnSize( UINT nType, int cx, int cy )
{
CMDIFrameWnd::OnSize( nType, cx, cy );
// Check if user wants to save application settings.
if ( theApp.m_cfg.GetSaveSettingsFlag() )
{
// Save the main windows position.
WINDOWPLACEMENT wp;
wp.length= sizeof( wp );
if ( GetWindowPlacement( &wp ) )
{
wp.flags= 0;
if ( IsZoomed() )
{
wp.flags |= WPF_RESTORETOMAXIMIZED;
}
// and write it to the .INI file
::WriteWindowPlacement( _T("Main"), &wp );
} // if ( GetWindowPlacement( &wp ) )
} // if ( theApp.m_cfg.GetSaveSettingsFlag() )
Quote:
}
You can also use it to save the views through their frame class.
HTH
--
=================
Frank Hickman
Computers Plus
=================