我想在propertysheet标签上添加位图,使与propertypage的背景相一致。请各位兄台赐教!多谢

解决方案 »

  1.   

    我想在propertysheet标签上添加位图,使与propertypage的背景相一致。参考了徐景周的深入浅出CPropertySheet,里面有在标签上添加位图的,可我运行了不能用,不知什么原因。各位兄台赐教!多谢
      

  2.   

    给你一个例子:以前写的
    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 width=rectClient.Width()*2/3;
    //移动并改变属性单窗口的尺 寸
    SetWindowPos(NULL,pt.x-width/2,pt.y-winRect.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); bitmap.LoadBitmap(IDB_BITMAP_TEST);
    imagelist.Create(16,16,ILC_COLOR8,0,4);
    imagelist.Add(&bitmap,RGB(0,0,0));
    pTab->SetPadding(CSize(5,5)); pTab->SetImageList(&imagelist); TCITEM tm;
    tm.mask=TCIF_IMAGE;
    for(int index=0;index<=2;index++)
    {
    pTab->GetItem(index,&tm);
    tm.iImage=index;
    pTab->SetItem(index,&tm);
    } //激活每个属性页,防止重画
    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
    }
      

  3.   

    关键代码: bitmap.LoadBitmap(IDB_BITMAP_TEST);//装载位图
    imagelist.Create(16,16,ILC_COLOR8,0,4);//分割位图
    imagelist.Add(&bitmap,RGB(0,0,0));//添加位图
    pTab->SetPadding(CSize(5,5));//扩展标签 pTab->SetImageList(&imagelist);//设置位图列表 TCITEM tm;
    tm.mask=TCIF_IMAGE;
    for(int index=0;index<=2;index++)
    {
    pTab->GetItem(index,&tm);
    tm.iImage=index;
    pTab->SetItem(index,&tm);//设置标签位图
    } //激活每个属性页,防止重画
    int nCurPos=GetActiveIndex();
    for(int i=0;i<GetPageCount();i++)
      SetActivePage(i);
    SetActivePage(nCurPos);
      

  4.   

    其中IDB_BITMAP_TEST为48X16的位图
    CFontSheet 具有三个属性页:
    CFontPage
    CEffectPage
    CColorPage
    -----------------
    class CFontSheet : public CPropertySheet{
    .....
    public:
    CFontPage m_FontPage;
    CEffectPage m_EffectPage;
    CColorPage m_ColorPage;
    ...
    };
    ------------------------
    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);//设置标签为滚动显示方式!
    }