当前位置:早雪网网络学院编程文档C/C++ → 属性表标签上的位图在MFC,CB下的实现

属性表标签上的位图在MFC,CB下的实现

减小字体 增大字体 作者:佚名  来源:supcode.com收集整理  发布时间:2005-6-24 17:30:57
属性表标签上的位图在MFC,CB下的实现
属性表标签(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 );

     }

}

[数据载入中...] [返回上一页] [打 印]