如何纪录窗口的启动位置,特别是工具栏的位置和工具栏的高度和宽度,在下次运行的时候能够跟结束程序的时候一样

解决方案 »

  1.   

    Call this function to store information about each control bar owned by the frame window.void SaveBarState(
       LPCTSTR lpszProfileName 
    ) const;
    ParameterslpszProfileName 
    Name of a section in the initialization file or a key in the Windows registry where state information is stored.
     
    Res
    This information can be read from the initialization file using LoadBarState. Information stored includes visibility, horizontal/vertical orientation, docking state, and control bar position.
      

  2.   

    LPCTSTR lpszProfileName 
    阐述一下参数,英文看不懂
      

  3.   

    BOOL CMainFrame::DestroyWindow() 
    {
    CWinApp* pApp = AfxGetApp();
        
    CString strText;
        BOOL bIconic, bMaximized;    WINDOWPLACEMENT wndpl;
        wndpl.length = sizeof( WINDOWPLACEMENT );    BOOL bRet = GetWindowPlacement( &wndpl );
        if ( wndpl.showCmd == SW_SHOWNORMAL ) {
            bIconic = FALSE;
            bMaximized = FALSE;
        }
        else if ( wndpl.showCmd == SW_SHOWMAXIMIZED ) {
            bIconic = FALSE;
            bMaximized = TRUE;
        } 
        else if ( wndpl.showCmd == SW_SHOWMINIMIZED ) {
            bIconic = TRUE;
            if ( wndpl.flags ) {
                bMaximized = TRUE;
            }
            else {
                bMaximized = FALSE;
            }
        }
        strText.Format("%04d %04d %04d %04d",
                       wndpl.rcNormalPosition.left,
                       wndpl.rcNormalPosition.top,
                       wndpl.rcNormalPosition.right,
                       wndpl.rcNormalPosition.bottom);
        pApp -> WriteProfileString( s_profileHeading,
                                        s_profileRect, strText );
        pApp -> WriteProfileInt( s_profileHeading,
                                     s_profileIcon, bIconic );
        pApp -> WriteProfileInt( s_profileHeading,
                                     s_profileMax, bMaximized );
        SaveBarState( pApp -> m_pszProfileName); m_wndCoolBar.SaveToREG( "目录栏" ); pApp -> WriteProfileInt( s_profileHeading, 
    return CFrameWnd::DestroyWindow();
    }void CMainFrame::ActivateFrame(int nCmdShow) 
    {
        CString strText;
        BOOL bIconic, bMaximized;
        UINT flags;
        WINDOWPLACEMENT wndpl;
        CRect rect; CWinApp* pApp = AfxGetApp();
        if (m_bFirstTime) {
            m_bFirstTime = FALSE;
            strText = pApp -> GetProfileString( s_profileHeading,
                                                    s_profileRect );
            if ( !strText.IsEmpty() ) {
                rect.left = atoi( ( const char* ) strText );
                rect.top = atoi( ( const char* ) strText + 5 );
                rect.right = atoi( ( const char* ) strText + 10 );
                rect.bottom = atoi( ( const char* ) strText + 15 );
            }
            else {
                rect = s_rectDefault;
            }        bIconic = pApp -> GetProfileInt( s_profileHeading,
                                                 s_profileIcon, 0 );
            bMaximized = pApp -> GetProfileInt( s_profileHeading,
                                                    s_profileMax, 0 );   
            if ( bIconic ) {
                nCmdShow = SW_SHOWMINNOACTIVE;
                if ( bMaximized ) {
                    flags = WPF_RESTORETOMAXIMIZED;
                }
                else {
                    flags = WPF_SETMINPOSITION;
                }
            }
            else {
                if ( bMaximized ) {
                    nCmdShow = SW_SHOWMAXIMIZED;
                    flags = WPF_RESTORETOMAXIMIZED;
                }
                else {
                    nCmdShow = SW_NORMAL;
                    flags = WPF_SETMINPOSITION;
                }
            }
            wndpl.length = sizeof( WINDOWPLACEMENT );
            wndpl.showCmd = nCmdShow;
            wndpl.flags = flags;
            wndpl.ptMinPosition = CPoint( 0, 0 );
            wndpl.ptMaxPosition =
                CPoint( -::GetSystemMetrics(SM_CXBORDER),
                       -::GetSystemMetrics(SM_CYBORDER) );
            wndpl.rcNormalPosition = rect;
            LoadBarState( pApp -> m_pszProfileName );
            SetWindowPlacement( &wndpl );

    // 上次关闭程序时显示的视图,如果不是初始视图,转换一下
    m_nCurrentView = pApp -> GetProfileInt( s_profileHeading,
        }
    CFrameWnd::ActivateFrame(nCmdShow);
    }