屬性表標簽上的位圖在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 );
}
}