Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11661

How to use the original property in my own control?

$
0
0

I have my own button, and draw an image on it, but I want to read the original property Images and ImagesIndex of the button and put it on my button.

This code is what I do to draw a bmp file onto the button:

void __fastcall Tdrawbutton::DrawImag(AnsiString path){    ::Graphics::TBitmap *bmp= new ::Graphics::TBitmap;    ::Graphics::TBitmap *newbmp= new ::Graphics::TBitmap;    bmp->Transparent = true;//是否透明    newbmp->Transparent = true;    bmp->LoadFromFile(path);    int OriginalWidth = bmp->Width;    int OriginalHeight = bmp->Height;    int TargetWidth = OriginalWidth * hor;    int TargetHeight = OriginalHeight * hor;    newbmp->SetSize(TargetWidth, TargetHeight);    newbmp->Canvas->CopyRect(TRect(0, 0, TargetWidth, TargetHeight), bmp->Canvas, TRect(0, 0, OriginalWidth, OriginalHeight));    Canvas_->Draw(0,0,newbmp);    delete bmp;}

And this is some of the code for the drawing message:

void __fastcall Tdrawbutton::CNDrawItem(TMessage &Msg){     // 获取 DRAWITEMSTRUCT     const DRAWITEMSTRUCT* pDrawItem =reinterpret_cast<DRAWITEMSTRUCT*>(Msg.LParam);     GetScreenDisplayScale();     // 保存当前状态     // 目标DC     SaveDC(pDrawItem->hDC);     // 绑定 Canvas_ 到目标 DC     Canvas_->Handle = pDrawItem->hDC;     try          {            // extract the state flags...            TOwnerDrawState state;            // 按钮具有键盘焦点            if (pDrawItem->itemState & ODS_FOCUS)            {              state = state << odFocused;            }            // 已经按下            if (pDrawItem->itemState &                ODS_SELECTED)            {              state = state << odSelected;            }            // 按钮禁用            if (pDrawItem->itemState &                ODS_DISABLED)            {              state = state << odDisabled;            }            // 画按钮            DoDrawButtonFace(state);            // 画文本            DoDrawButtonText(state);          }      catch (...)      {        // clean up        Canvas_->Handle = NULL;        RestoreDC(pDrawItem->hDC, -1);      }      // clean up      Canvas_->Handle = NULL;      RestoreDC(pDrawItem->hDC, -1);      // reply TRUE      Msg.Result = TRUE;}//---------------------------------------------------------------------------void __fastcall Tdrawbutton::DoDrawButtonFace(const TOwnerDrawState& state){  //Brush->Style = bsClear;  Canvas_->Brush = Brush;  TRect RClient = ClientRect;  if(style == 0){        if (draw_as_default_ || state.Contains(odFocused))      {         DrawImag("UI\\down.bmp");      }      // 按下中...      if (state.Contains(odSelected))      {          DrawImag("UI\\down.bmp");      }      // 按钮未按下...      else      {          DrawImag("UI\\Normal.bmp");      }  }  if(style == 1){      if (selected)      {          DrawImag("UI\\down.bmp");      }      else      {          DrawImag("UI\\Normal.bmp");      }  }

What I want to know is, how to use the original property Images and ImageIndex to draw on my button?


Viewing all articles
Browse latest Browse all 11661

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>