Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15210361
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: C/C++

2008-05-31 14:09:39

属性表标签(tab control)支持在每一个item上放Image 图片。在mfc下实现相当简单,可分为以下几步:
    
    step1: create a bitmap resource with the images
           
           you can also use icons or even create the images at run time.
           the size of the images should be in proportion to the height
           of the label.
    step2: add member variable of type Cimagelist
           
            protected:
                      CImagelist m_imagetab;

    step3:  Override OnInitDialog() and add code to it

            bool CmyPropSheet::OnInitDialog()
            {
                bool bresult=CProperttySheet::OnInitDialog();
                m_imagetab.create(IDB_TABIMAGES,13,1,RGB(255,255,255));
                CTabCtrl *pTab=GetTabControl();
                pTab->SetImageList(&m_imagetab);
                
                tc_item tcitem;
                tcitem.mask=tcif_image;
                
                for(int i=0;i<3;i++)
                {  
                    tcitem.iimage=i;

                     pTab->SetItem(i,&tcitem);
                }
                return bresult;
              }

C++Builder 没有提供 SetImageList,SetItem这样的函数,但我们可以直接处理WINDOWS API 消息:TCM_SETIMAGELIST,TCM_SETITEM. 看下面的代码可以体会不同的编程风格。

void __fastcall TForm1::FormPaint(TObject *Sender)
{


    TabControl1->Perform ( TCM_SETIMAGELIST, 0, ImageList1->Handle );
    TCITEM tcitem;
    tcitem.mask=TCIF_IMAGE ;
    for(int i=0;i<3;i++)
    {
        tcitem.iImage=i;
        TabControl1->Perform ( TCM_SETITEM, i,(LPARAM) (LPTCITEM)     &tcitem );

     }

}
阅读(313) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~