简体   繁体   English

VCL TImage + TImageList,透明功能不起作用,或者我在做什么错?

[英]VCL TImage + TImageList, transparent feature doesn't work or what am I doing wrong?

Using Borland C++ Builder 2009 使用Borland C ++ Builder 2009

I screen-captured three buttons from a W7 Windows dialog and put them in a TImageList. 我从W7 Windows对话框中捕获了三个按钮,并将它们放在TImageList中。 I load the 3 variants in a TImage, when appropriate. 适当时,我将3个变体加载到TImage中。

Image->Picture->Bitmap = NULL ; // Clear previous state
ImageList->GetBitmap(2, Image->Picture->Bitmap) ;

PS: Image->Transparent = True PS:图像- Image->Transparent = True

On Windows 7 and Windows 10 this seems to work properly. 在Windows 7和Windows 10上,这似乎可以正常工作。 BUT I just realized, only because the TForm the TImage is placed on has the exact same background color . 但是我只是意识到,只是因为放置了TImage的TForm具有完全相同的背景color (confirmed not to work after I changed the background to lime) (确认将背景更改为石灰后不起作用)

On Windows XP the button doesn't look so great. 在Windows XP上,该按钮看起来不太好。 Since XP seems to have slightly different background color. 由于XP似乎具有略有不同的背景色。 Mind you, it's also clBtnFace 提醒您,它也是clBtnFace

XP: XP: XP . . . Windows 7: Windows 7的: Windows 7的

I have also experimented with setting BlendColor and DrawingStyle of the TImageList control, combined with Image->Transparent = true or false . 我还尝试过设置BlendColorDrawingStyle ,并结合Image->Transparent = truefalse

But I can't get it to work. 但是我无法正常工作。

I captured the Image->Picture->Bitmap->Canvas->Pixels[0][0] value on W7 and put it in ImageList->BlendColor ( ImageList->DrawingStyle = dsFocus or dsSelected ) and so forth, without success. 我在W7上捕获了Image->Picture->Bitmap->Canvas->Pixels[0][0]值,并将其放入ImageList->BlendColorImageList->DrawingStyle = dsFocusdsSelected ),依此类推,但没有成功。

I also have experimented with explicitly setting Image->Transparent = True again after a ImageList->GetBitmap(2, Image->Picture->Bitmap) and even tried 我还尝试过在ImageList->GetBitmap(2, Image->Picture->Bitmap)之后再次显式设置Image->Transparent = True ,甚至尝试过

Image->Picture->Bitmap->TransparentColor =
Image->Picture->Bitmap->Canvas->Pixels[0][0]

without a noticeable effect. 没有明显的效果。

Your thoughts ? 你的意见 ?

How I said on my comment instead of capture the image from the screen you can try drawing the expand button using the DrawThemeBackground method passing the TDLG_EXPANDOBUTTON part and one of the valid states ( TDLGEBS_NORMAL , TDLGEBS_HOVER , TDLGEBS_PRESSED , etc) . 我在评论中怎么说,而不是从屏幕上捕获图像,您可以尝试使用DrawThemeBackground方法绘制扩展按钮,该方法传递TDLG_EXPANDOBUTTON部分和有效状态之一( TDLGEBS_NORMALTDLGEBS_HOVERTDLGEBS_PRESSED等)。 And for Windows XP you can use EBP_NORMALGROUPEXPAND part and one of these states ( EBHC_NORMAL , EBHC_HOT , EBHC_PRESSED ) 对于Windows XP,您可以使用EBP_NORMALGROUPEXPAND部分和以下状态之一( EBHC_NORMALEBHC_HOTEBHC_PRESSED

Check this sample which drawn the expando button in a TImage. 检查此示例,该示例在TImage中绘制了expando按钮

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "Vsstyle.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------


__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Image1->Canvas->Brush->Color = clBtnFace;
  Image1->Canvas->FillRect(Image1->ClientRect);

  OSVERSIONINFO verwin;
  verwin.dwOSVersionInfoSize=sizeof(verwin);
  if (GetVersionEx(&verwin))
  {
    //Check  the Windows version
    if (verwin.dwMajorVersion >= 6) // is Vista at least?
    {
      HTHEME hTheme = OpenThemeData(Handle, VSCLASS_TASKDIALOG);
      if (hTheme)
      {
          SIZE s;
          //get the size of the  TDLG_EXPANDOBUTTON
          if (GetThemePartSize(hTheme, Image1->Canvas->Handle, TDLG_EXPANDOBUTTON, TDLGEBS_NORMAL, NULL, TS_TRUE, &s) == S_OK)
          {
              TRect pRect = Rect(0, 0, s.cx, s.cy);
              DrawThemeBackground(hTheme, Image1->Canvas->Handle, TDLG_EXPANDOBUTTON, TDLGEBS_NORMAL, &pRect, NULL);
           }
      }
    }
    else
    {
      HTHEME hTheme = OpenThemeData(Handle, VSCLASS_EXPLORERBAR);
      if (hTheme)
      {
          SIZE s;
          //get the size of the  EBP_NORMALGROUPEXPAND
          if (GetThemePartSize(hTheme, Image1->Canvas->Handle, EBP_NORMALGROUPEXPAND, EBHC_NORMAL, NULL, TS_TRUE, &s) == S_OK)
          {
              TRect pRect = Rect(0, 0, s.cx, s.cy);
              DrawThemeBackground(hTheme, Image1->Canvas->Handle, EBP_NORMALGROUPEXPAND, EBHC_NORMAL, &pRect, NULL);
           }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM