怎样在CFormView中加一个属性表?该属性表不是弹出的,而是一直在CFormView的界面上的.请问这样的属性表怎样做?且怎样添加各个页?

解决方案 »

  1.   

    《Creating a Property Sheet Inside a Form View》:
    http://www.codeguru.com/propertysheet/inside_formview.shtml
      

  2.   

    《Creating a Property Sheet Inside a Form View》一文中有详细的介绍呀
      

  3.   

    给你提供三个辅助函数,我刚测试完,比较好用
    需要的话可以给你源代码
    [email protected]//#if !defined EMBEDED_PAGE_H
    #define EMBEDED_PAGE_H#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000// EmbededPage.h : header file
    //BOOL CreateEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,DWORD dwStyle=WS_CHILD|WS_VISIBLE,DWORD dwStyleEx=0);
    void PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,CRect rectPosition);
    BOOL PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,UINT nIDIndicatorArea);#endif
    ////
    #include "stdafx.h"
    #include "UsePropertySheet.h"//include the resource
    #include "EmbededPage.h"BOOL CreateEmbededSheet(
    CWnd *pWndParent,
    CPropertySheet *pSheet,
    DWORD dwStyle,
    DWORD dwStyleEx)
    {
    ASSERT_VALID(pWndParent);
    ASSERT_VALID(pSheet); //Create the  Sheet at the specified Parent window
    if(!pSheet->Create(pWndParent,dwStyle,dwStyleEx))
    {
    TRACE0("Failed to create the embeded sheet\n");
    return FALSE;
    } //The sheet should have the style to access the TAB
    pSheet->ModifyStyle(0,WS_TABSTOP);

    //  Allows the user to navigate among the child windows of 
    //the window by using the TAB key.
    pSheet->ModifyStyleEx(0,WS_EX_CONTROLPARENT); //Assert the parent window have the style:WS_EX_CONTROLPARENT
    pWndParent->ModifyStyleEx(0,WS_EX_CONTROLPARENT); return TRUE;
    }void PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,CRect rectPosition)
    {
    ASSERT_VALID(pWndParent);
    ASSERT_VALID(pSheet); //Get the tab control associated with the sheet
    CTabCtrl *pTabCtrl=pSheet->GetTabControl();
    ASSERT_VALID(pTabCtrl); CRect rectTab;
    pTabCtrl->GetWindowRect(rectTab);
    pWndParent->ScreenToClient(rectTab); CRect rectSheet;
    pSheet->GetWindowRect(rectSheet);
    pWndParent->ScreenToClient(rectSheet); //calculate the margin's size to right side
    int cx=rectSheet.Width()-rectTab.Width();
    int cy=rectSheet.Height()-rectTab.Height(); //Shift the sheet to appropriate pos
    pSheet->MoveWindow(rectPosition.left,rectPosition.top,rectPosition.Width(),rectPosition.Height()); //shift the tab
    pTabCtrl->SetWindowPos(NULL,0,0,rectPosition.Width()-cx,rectPosition.Height()-cy,SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);

    //activate all the pages ,avoid redrawing,just update it
    int nCurrentPage=pSheet->GetActiveIndex();
    for(int i=0;i<pSheet->GetPageCount();i++)
    {
    pSheet->SetActivePage(i);
    }
    pSheet->SetActivePage(nCurrentPage);}BOOL PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,UINT nIDIndicatorArea)
    {
    ASSERT_VALID(pWndParent);
    ASSERT_VALID(pSheet);

    //get the indicator's rect
    CRect rectPos;
    CWnd *pIndicatorCtrl=pWndParent->GetDlgItem(nIDIndicatorArea);
    if(pIndicatorCtrl!=NULL)
    {
    pIndicatorCtrl->GetWindowRect(rectPos);
    pWndParent->ScreenToClient(rectPos);
    ::PositionEmbededSheet(pWndParent,pSheet,rectPos);
    return TRUE;
    } return FALSE;
    }
    用法举例:
    //BOOL CSheetDialog::OnInitDialog() 
    {
    CDialog::OnInitDialog();

    // TODO: Add extra initialization here
    ::CreateEmbededSheet(this,&m_sheet);
    ::PositionEmbededSheet(this,&m_sheet,IDC_STATIC_SHEET_AREA);

    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }//----------------------------------------------------
    void CUsePropertySheetView::OnInitialUpdate()
    {
    CFormView::OnInitialUpdate(); ::CreateEmbededSheet(this,&m_sheet);
    ::PositionEmbededSheet(this,&m_sheet,IDC_SHEET_AREA);

    //change the size of the formview to contain the sheet
    GetParentFrame()->RecalcLayout();
    this->ResizeParentToFit(FALSE);
    this->ResizeParentToFit(TRUE);

    // set the focus to first control with the tabstop 
    CWnd *pChild=this->GetWindow(GW_CHILD);
    while(pChild!=NULL&&(pChild->GetStyle()&WS_TABSTOP)==0)
    {
    pChild=pChild->GetNextWindow();
    } if(pChild!=NULL)
    {
    pChild->SetFocus();
    }}
    void CUsePropertySheetView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
    {
    // TODO: Add your specialized code here and/or call the base class

    // update data in here 
    //interview with CDocument
    //UpdateData(FALSE);
    //if(m_sheet.GetSafeHwnd()!=NULL)
    //m_sheet.GetActivePage()->UpdateData(FALSE);

    }
    void CUsePropertySheetView::OnApply( ) 
    {
    // TODO: Add your specialized code here and/or call the base class
    this->UpdateData(true);
    //m_sheet.GetActivePage()->UpdateData(true);
    //interview with CDocument
    //UpdateData(TRUE);
    //pDoc->SetModifiedFlag(TRUE);
    //pDoc->UpdateAllViews(this);
    }