Link to home
Start Free TrialLog in
Avatar of Bindza
Bindza

asked on

Control transparency - temporary bmp

I'm trying to make my hexagon color picker XP
compatible, but since I'm drawing to a bmp and then using canvas.draw -
the parent background isn't painted (gets overpainted), and if I use
bmp.transparent the thing is tooo slow and flickery. I tried
DrawParentBackGround(Handle, bmp.canvas.handle, nil, false), but
nothing happends. What should I do, it looks terrible with WinXP (at least on a TTabControl)?

You can take a look at the screenshot at: http://mxs.topcities.com/hexa.png

Any help GREATLY appreciated!!!
Avatar of EKIM
EKIM

Hi bindza,
as far as I remember, the transparent color It the color of the Lower-left pixel.
When you draw the bmp, set the lower left pixel to the needed color (I your case, parent color).

@+
Ekim
Avatar of Bindza

ASKER

You didn't understand, if I use bmp.transparent and the thing is resized there's unbearable flickering and very very bad system performance. Also, I can fill the bmp with the parent's color, but then I will end up with a solid back, but what if the parent is gradient - take a look at the screenshot - TTabSheet with XPMan. The bottom line is: the painting procedure doesn't touch the back, it only draws the haxagons, so I think I should either find a super-fast way to make bmp back transparent or draw the parent back onto the bmp before the hexagons are drawn (i tried with ThemeServices.DrawParentBackground, but didn't get anything painted).
erm... try capturing a Rect of the Parent's background first, then draw whatever you want on it and finally blt it back to the parent?
Avatar of Bindza

ASKER

Can you give me some code, I don't know hot to "capture a Rect of the parent's background", I did think of it, but didn't know exactly how to do it.

[What do you mean by "blt it back to the parent"? I've got my component and all I wanna do is draw a parent background to a bmp, then draw the control over it and put it onto the screen via canvas.draw, I'm not trying to draw onto the parent...]
Avatar of Bindza

ASKER

Never mind, a friend helped me solve it, here it is:

uses Themes;

procedure TLColorPicker.PaintParentBack;
var
 OffScreen: TBitmap;
 MemDC: HDC;
 OldBMP: HBITMAP;
begin
 Offscreen := TBitmap.Create;
 try
  Offscreen.Width := Width;
  Offscreen.Height := Height;
  Offscreen.Canvas.Brush.Color := Color;
  Offscreen.Canvas.FillRect(Offscreen.Canvas.ClipRect);
  if ParentBackground then
   with ThemeServices do
    if ThemesEnabled then
     begin
      MemDC := CreateCompatibleDC(0);
      OldBMP := SelectObject(MemDC, OffScreen.Handle);
      DrawParentBackground(Handle, MemDC, nil, False);
      if OldBMP <> 0 then SelectObject(MemDC, OldBMP);
      if MemDC <> 0 then DeleteDC(MemDC);
     end;
  Canvas.Draw(0, 0, Offscreen);
 finally
  Offscreen.Free;
 end;
end;
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial