程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> VC >> vc教程 >> 屬性表標簽上的位圖在MFC、CB下的實現

屬性表標簽上的位圖在MFC、CB下的實現

編輯:vc教程

屬性表標簽(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 );
  }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved