属性表标签上的位图在MFC,CB下的实现
2019-09-06 23:33:56
供稿:网友
属性表标签(tab control)支持在每一个item上放Image 图片。在mfc下实现相当简单,可分为以下几步:
step1: create a bitmap resource with the images
/t
/t you can also use icons or even create the images at run time.
/t the size of the images should be in proportion to the height
/t of the label.
step2: add member variable of type Cimagelist
/t
/t protected:
/t/t CImagelist m_imagetab;
step3: Override OnInitDialog() and add code to it
/t bool CmyPropSheet::OnInitDialog()
/t {
/t/tbool bresult=CProperttySheet::OnInitDialog();
/t/tm_imagetab.create(IDB_TABIMAGES,13,1,RGB(255,255,255));
/t/tCTabCtrl *pTab=GetTabControl();
/t/tpTab->SetImageList(&m_imagetab);
/t/t
/t/ttc_item tcitem;
/t/ttcitem.mask=tcif_image;
/t/t
/t/tfor(int i=0;i<3;i++)
/t/t{
/t/t tcitem.iimage=i;
/t/t pTab->SetItem(i,&tcitem);
/t/t}
/t/treturn bresult;
/t }
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++)
{
/ttcitem.iImage=i;
/tTabControl1->Perform ( TCM_SETITEM, i,(LPARAM) (LPTCITEM) &tcitem );
}
}