一个属性框,肯定有sheet与page把。怎么样给page添加标题呢?
以及如果sheet的大小变了,怎么样让page的大小也跟着变呢?

解决方案 »

  1.   

    page的标题就在那些标签上嘛。让page改变大小可以用MoveWindow或者SetWindowPos.
      

  2.   

    我是想动态的给page添加标题。改变大小,我试过MoveWindow,setWindowPos
    ,不行!运行时coredump!
      

  3.   

    1:改变page的标题:
    CString sCaption = _T("New Caption");
    TC_ITEM tcItem;
    tcItem.mask = TCIF_TEXT;
    tcItem.pszText = (LPTSTR)((LPCTSTR)sCaption);
    GetTabControl()->SetItem(0, &tcItem );     //第一个标签
    2:移动page:
    http://www.codeguru.com/propertysheet/move_resize_page.shtml
      

  4.   

    webber84,你上面的代码,放在哪个文件?我试了好像不行啊!
    说清楚点可以吗?
      

  5.   

    放在CPropertySheet的某一个成员函数中。当然要等属性框显示以后再调用这些代码。
      

  6.   

    void CPropView::OnLButtonDblClk(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CFontSheet dlg("Test the font property sheet!"); //设置属性页的标题
    CString strFontPage;
    strFontPage.Format("Font (%d,%d)",point.x,point.y);
    dlg.GetPage(0)->m_psp.pszTitle=strFontPage;
    dlg.GetPage(0)->m_psp.dwFlags|=PSP_USETITLE;
    CString strEffectPage;
    strEffectPage.Format("Effect (%d,%d)",point.x+10,point.y+10);
    dlg.GetPage(1)->m_psp.pszTitle=strEffectPage;
    dlg.GetPage(1)->m_psp.dwFlags|=PSP_USETITLE; CString strColorPage;
    strColorPage.Format("Color (%d,%d)",point.x+20,point.y+20);
    dlg.GetPage(2)->m_psp.pszTitle=strColorPage;
    dlg.GetPage(2)->m_psp.dwFlags|=PSP_USETITLE; dlg.DoModal();
    CView::OnLButtonDblClk(nFlags, point);
    }
      

  7.   

    上面是设置属性页的标题随着鼠标双击位置而改变
    BOOL CFontSheet::OnInitDialog() 
    {
    CPropertySheet::OnInitDialog();

    // TODO: Add extra initialization here //改变属性单的大小
    //测试程序是在视图类中进行的
    //设置属性单的宽度]为当前视图的宽的二分之一!
    //不改变属性单的高度,可以省去移动属性页中的控件的麻烦!
    CTabCtrl *pTab=this->GetTabControl();
    CRect rectPage;
    pTab->GetWindowRect(rectPage);
    pTab->ScreenToClient(rectPage); //计算属性单和标签控件之间的间距
    CRect winRect;
    GetWindowRect(winRect);
    int dx=winRect.Width()-rectPage.Width();
    int dy=winRect.Height()-rectPage.Height(); CRect rectClient;
    CMainFrame  *pFrame=(CMainFrame*)AfxGetMainWnd();
    CPropView *pView=(CPropView*)pFrame->GetActiveView();
    pView->GetClientRect(rectClient);
    pView->ClientToScreen(rectClient);
    CPoint pt=rectClient.CenterPoint();
    int height=rectClient.Height()*1/3;
    int width=rectClient.Width()*2/3;
    //移动并改变属性单窗口的尺 寸
    SetWindowPos(NULL,pt.x-width/2,pt.y-height/2,width,winRect.Height(),SWP_NOZORDER|SWP_NOACTIVATE); //移动并改变标签控件的尺寸
    pTab->SetWindowPos(NULL,0,0,width-dx,winRect.Height()-dy,SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE); //设置按钮的显示
    CButton *pButtonOK,*pButtonCancel,*pButtonApply;
    pButtonOK=(CButton*)GetDlgItem(IDOK);
    pButtonCancel=(CButton*)GetDlgItem(IDCANCEL);
    pButtonApply=(CButton*)GetDlgItem(ID_APPLY_NOW); GetClientRect(rectClient);
    // 使各个按钮均匀分布在客户区
    int left,right,middle,nSpace;
    CRect rcOK,rcCancel,rcApply;

    pButtonOK->GetWindowRect(rcOK);
    ScreenToClient(rcOK);
    pButtonCancel->GetWindowRect(rcCancel);
    ScreenToClient(rcCancel);
    pButtonApply->GetWindowRect(rcApply);
    ScreenToClient(rcApply); nSpace=(rectClient.Width()-60-3*rcOK.Width())/2;
    left=rectClient.left+30;
    middle=left+nSpace+rcOK.Width();
    right=middle+nSpace+rcCancel.Width();
    pButtonOK->SetWindowPos(NULL,left,rcOK.top,0,0,
      SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
    pButtonApply->SetWindowPos(NULL,right,rcApply.top,0,0,
      SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
    pButtonCancel->SetWindowPos(NULL,middle,rcCancel.top,0,0,
      SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
    //激活每个属性页,防止重画
    int nCurPos=GetActiveIndex();
    for(int i=0;i<GetPageCount();i++)
      SetActivePage(i);
    SetActivePage(nCurPos); return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }
    这是自动调整属性页大小的代码-----调整为视图窗口的宽度的2/3
    ---------------------------------
    说明一下:
    class CFontSheet : public CPropertySheet
    {
    }
    class CFontPage : public CPropertyPage
    {
    }
    class CEffectPage : public CPropertyPage
    {
    }
    class CColorPage : public CPropertyPage
    {
    }
    CFontSheet::CFontSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
    :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
    {
      //page 0;
    AddPage(&m_FontPage);
    //page 1;
    AddPage(&m_EffectPage);
    //page 2
    AddPage(&m_ColorPage);
    EnableStackedTabs(false);//设置标签为滚动显示方式!
    }
    -----------------------
    必须在OnInitDialog()中设置属性页的位置。在别的地方没用!