Transparent Trackbar

I need a transparent Trackbar on my map.

The underlying transparent component works fine, and is transparent, I just cannot get the background of the TTrackbar to become transparent, no matter what tricks I add from the internet.

When I put a Trackbar on a Form, and set the Form AlphaBlend, then the Trackbar is transparent (together with the whole Form of course). To me that means it should be able to do it.

This is the code I have at the moment:

{code}
TMyTrackBar = class(ComCtrls.TTrackBar)
  private
    procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message WM_EraseBkGnd;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    // procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  end;

  TBlendBar = class(TCustomControl)
	protected
		procedure Paint; override;
		procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
	private
		BlendBitmap: TBitmap;
	public
  	Value:integer;
    TrackBar: TMyTrackBar;

		constructor Create(AOwner: TComponent); override;
		destructor Destroy; override;
	end;



// ----------------------- TBlendBar --------------------------------------------

constructor TMyTrackBar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csOpaque];
end;

procedure TMyTrackBar.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
end;

procedure TMyTrackBar.WMEraseBkGnd(var Message: TWMEraseBkGnd);
begin
  SetBkMode (Message.DC, TRANSPARENT);
  Message.Result := 1;
end;

constructor TBlendBar.Create(AOwner: TComponent);
begin
	inherited;
  self.Brush.Style := bsClear;
	BlendBitmap := TBitmap.Create;
  //BlendBitmap.Height := 152;
  //BlendBitmap.Width := 24;
  TrackBar := TMyTrackBar.Create(self);
  TrackBar.Parent := Self;
  TrackBar.Orientation := trVertical;
  TrackBar.Width := Width;
  TrackBar.Height := Height;
  Trackbar.TickMarks := tmTopLeft;
  Trackbar.TickStyle := tsNone;
  Trackbar.ShowSelRange := false;
  TrackBar.ThumbLength := 20;
  TrackBar.Min := 0;
  TrackBar.Max := 255;
  TrackBar.Position := 128;
  TrackBar.OnChange := MapIntForm.BlendTrackBarChange;
  TrackBar.Hint := _('Change the transparency of Overlays which can be Blended');
  TrackBar.ShowHint := true;
end;


destructor TBlendBar.Destroy;
begin
	FreeAndNil(BlendBitmap);
  TrackBar.Free;
	inherited;
end;


procedure TBlendBar.Paint;
var
  SrcRect: TRect;
	bf: BLENDFUNCTION;
begin
	// if not assigned(BlendBitmap) then exit; // Seems to happen on shutdown.
  if not self.Visible then exit;
  if not assigned(canvas) then exit;

	with Canvas do
	begin
		Brush.Style := bsClear;
    // Brush.Style := bsSolid;
	end;

  Width := 40;
  Height := 150;
  Trackbar.Width := 25;
  Trackbar.Height := 150;

	Left := MapIntForm.MapBox.width - Self.width - 24;
	Top := MapIntForm.MapBox.Top + MapIntForm.MapBox.ClientHeight - 180;

	// Copy from MapImage what is beneath the canvas
	SrcRect.Left := Self.Left - MapIntForm.MapBox.FMapImage.Left -
		MapIntForm.MapBox.Left - 2;
	SrcRect.Top := Self.Top - MapIntForm.MapBox.FMapImage.Top -
		MapIntForm.MapBox.Top - 2;
	SrcRect.Right := SrcRect.Left + width;
	SrcRect.Bottom := SrcRect.Top + height;

	Canvas.CopyMode := cmSrcCopy;
	Canvas.CopyRect(Rect(0, 0, Self.width, Self.height),
		MapIntForm.MapBox.FMapImage.Canvas, SrcRect);

	BlendBitmap.width := Self.width;
	BlendBitmap.height := Self.height;
	BlendBitmap.Canvas.Brush.Color := clBlack; //clWhite;
	// BlendBitmap.Canvas.Rectangle(0,0,BlendBitmap.Width,BlendBitmap.Height);

	bf.BlendOp := AC_SRC_OVER;
	bf.BlendFlags := 0;
	bf.SourceConstantAlpha := 100; // AlphaValue
	bf.AlphaFormat := 0;
	AlphaBlend(Canvas.Handle, 0, 0, width, height, BlendBitmap.Canvas.Handle, 0,
		0, width, height, bf);

  Trackbar.Repaint;
end;


procedure TBlendBar.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
	Message.result := 1;
end;


{code}

--
Bart Kindt, CEO and developer
SARTrack Limited New Zealand
http://www.sartrack.co.nz/
0
Bart
8/15/2015 8:34:31 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

2 Replies
566 Views

Similar Articles

[PageSpeed] 40

Bart Kindt wrote:

> I need a transparent Trackbar on my map.
> 
> The underlying transparent component works fine, and is transparent,
> I just cannot get the background of the TTrackbar to become
> transparent, no matter what tricks I add from the internet.
> 
> When I put a Trackbar on a Form, and set the Form AlphaBlend, then
> the Trackbar is transparent (together with the whole Form of course).
> To me that means it should be able to do it.

You are comparing apples and peaches <g>. The alpha blending on the
form level is a Windows feature and it only works on the top window
level (including all child windows of the top window), not only on a
child window (control) level.

> This is the code I have at the moment:
> 
> {code}
> TMyTrackBar = class(ComCtrls.TTrackBar)
>   private
>     procedure WMEraseBkGnd(var Message: TWMEraseBkGnd); message
> WM_EraseBkGnd;   protected

The trackbar is a windows common control under the hood, which means
you are at Window's mercy in regard to how it draws the control. You
block the background fill, but that only works if the control actually
responds to the WM_ERASEBKGND message by drawing its background there.
The trackbar does not do that, it draws itself completely in WM_PAINT,
and it may even take shortcuts and draw while you drag the slider with
the mouse, in response to the mouse messages.

To custom draw common controls you have to use a different approach.
See
https://msdn.microsoft.com/en-us/library/windows/desktop/bb760155%28v=vs.85%29.aspx

for a start. You probably have to add a handler for WM_NOTIFY (or
CN_NOTIFY, the VCL equivalent) to modify the drawing process.

You also have to keep in mind that, for a control to act transparent,
its *parent* control has to draw the area under the transparent
control, which it will not do by default (the child window area is
excluded from the parent's drawing region automatically). The VCL has a
mechanism to handle that for pure VCL controls (like a TPanel, see the
ParentBackground property), but this cannot be easily retrofitted to a
Windows control. The best strategy here is usually to trap
WM_ERASEBKGND and there use the parent's PaintTo method to get it to
draw the part of itself covered by the control to the control's HDC.



-- 
Peter Below (TeamB)
0
Peter
8/15/2015 9:55:30 AM
> {quote:title=Peter Below wrote:}{quote}

> To custom draw common controls you have to use a different approach.
> See
> https://msdn.microsoft.com/en-us/library/windows/desktop/bb760155%28v=vs.85%29.aspx

At first sight, I do not see how this helps me, but I will study it some more.

> 
> for a start. You probably have to add a handler for WM_NOTIFY (or
> CN_NOTIFY, the VCL equivalent) to modify the drawing process.
> 
> You also have to keep in mind that, for a control to act transparent,
> its *parent* control has to draw the area under the transparent
> control,

I do this manually, I copy the original background, and paint this back in the control. This works fine.
The problem is that the Trackbar's background then completely overwrites this again. 
This despite the fact that I tried this as well:
{code}
ABlendBar := TBlendBar.Create(Self);
  ABlendBar.Parent := Self;
  SetWindowLong(ABlendBar.Handle, GWL_STYLE, GetWindowLong
      (ABlendBar.Handle, GWL_STYLE) and not WS_ClipChildren);
{code}

Which is supposed to deal with the issue of the parent not painting the area under the control, as I understand it. But it has no effect. 
I don't think this is in fact relevant because I manually paint the background in TBlendBar.Paint; After which I call the paint of the TrackBar, which then overwrites the lot again.

> Peter Below (TeamB)

--
Bart Kindt, CEO and developer
SARTrack Limited New Zealand
http://www.sartrack.co.nz/
0
Bart
8/15/2015 12:35:40 PM
Reply:

Similar Artilces:

delphi.general
Sorry if this is "out of topic"! but since some days ago I can't read the group *embarcadero.public.delphi.language.delphi.general* Does anybody know if there's something wrong with it? Or maybe is my reader? (Thunderbird) I get this messagge when I try to read the latest messages: Error! newsgroup server responded:no such article found Perhaps the article has expired <692702@forums.embarcadero.com> (33145) Click here to remove all expired articles sergio wrote: > Sorry if this is "out of topic"! but since some days ago I can'...

What generals generally do
Reading a McChrystal thread elsewhere, I came across someone quoting a US general http://en.wikipedia.org/wiki/Smedley_Butler > I spent 33 years and four months in active military service and > during that period I spent most of my time as a high class thug for > Big Business, for Wall Street and the bankers. In short, I was a > racketeer, a gangster for capitalism. I helped make Mexico and > especially Tampico safe for American oil interests in 1914. I helped > make Haiti and Cuba a decent place for the National City Bank boys to > collect revenues in. I ...

Delphi Transparency [Edit]
Here's a project with images that demonstrates Delphis inability to properly render alpha transparent PNGs in a TToolbar. Se related post in Delphi/Graphics forum https://forums.embarcadero.com/thread.jspa?threadID=70056 regards Fredrik Edited by: Fredrik Vestin on Apr 3, 2012 10:54 PM Added link to related post ...

Transparent DBGrid for Delphi
Can anyone here help me with a transparent DBGrid? The first thread got no replies, or is this not the correct forum to target. Maybe I should try some other forums. Any good forums out there? vcl.components.using would be a better group. or perhaps the 3rd party group if the standard DBgrid can't do what you want. <Sihaam Kiraam> wrote in message news:146846@forums.codegear.com... > Can anyone here help me with a transparent DBGrid? The first thread got no replies, or is this not the correct forum to target. Maybe I should try some other forums. Any good forums out th...

Delphi 2010 Transparent
Hi, I'm using Delphi 2010 for the first time and I found a problem, it seem that a TCheckBox back color is normal when I'm on desing time, but it sets to transparent at runtime, is there any property I need to change? The image is on the attachments thks for any help I've found the problem, this is because of the use of DoubleBuffered, that makes the components transparent like the form, why? thks ...

delphi.general Timer
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_202d5.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" For Paolo Valle --JivePart=_202d5.zeB8CwDOH5aMJzMl Content-Type: application/octet-stream; name="SubroutineTimer.pas" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="SubroutineTimer.pas" dW5pdCBTdWJyb3V0aW5lVGltZXI7DQoNCmludGVyZmFjZQ0KDQpwcm9jZWR1cmUgU3RhcnRTdWJy b3V0aW5lVGltZXI7DQpmdW5jdGlvbiBHZXRTdWJSb...

Delphi 2010 TcheckBox transparent?
Any transparent property for Delphi 2010 TCheckBox and TradioButton ? Thanks. <richard poulin> wrote in message news:157190@forums.codegear.com... > Any transparent property for Delphi 2010 TCheckBox and TradioButton ? Nope. -- Remy Lebeau (TeamB) OK thanks - i will wait for 2011 ;) richard poulin wrote: > OK thanks - i will wait for 2011 ;) What exactly do you mean by "transparent" checkbox? You want it alpha-blended 50% invisible? Warren > Any transparent property for Delphi 2010 TCheckBox and TradioButton ? I think you might find...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

EVarriantTypeCast error delphi language general
I uploaded above subject to the attachment space.with test.zip. If somebody coul have a look at the test i prepared. Since overall QuickReport does work, i could not guess what is going on here. Thanks in advance to have a look at the attached test i made and hopefully somebody can find the issue. Regards. Lieven Hi xxx, If nothing works, it could mean that somewhere a mistake was made.lol. For the uploaded to public attachment test.zip solution below. Regards Lieven {Sql code} QryPtDat1.Sql.Clear; QryPtDat1.Sql.Add('SELECT D."Names", ...

Delphi XE and shaped transparent form
Hi, I have just switched to DelphiXE and wondering if possible to make a completely transparent form with a shaped transparent image? I have done this with Delphi2007 by using a overlay form but, the same way doesn't work because of unsupported PNG image components I had. thanks > {quote:title=Daniel Christian Ceker wrote:}{quote} > Hi, > I have just switched to DelphiXE and wondering if possible to make a completely transparent form with a shaped transparent image? > I have done this with Delphi2007 by using a overlay form but, > the same way doesn't work be...

form transparent for png image Delphi 7
Hello dear friends, does anyone know any method to make transparent the bottom of the form, I want to use a png image, it has shadow, I saw several methods on the Internet, but the method that I saw only ruins the shadow image, someone does not know a method of leaving the bottom of the form transparent without spoiling the outline or background image? thanks ...

General bootstrap questions: Delphi 7, pascal
Hi, This might be a bit inchoherant. I am sorry of that is the case but I have inherited a collection of languishing Delphi Projects in Pascal. I do not know Pascal and this is nearly my into to Delphi. Delphi 7 is running in a Windows XP VirtualMachine instance. The project in question uses several third party libraries / tools. Basically, I don't know where to start so I'll start at the beginning and hope you guys can help. I first inherited these projects almost two years ago. For the most part they work. There is one project, however, that needs to have a few "mag...

borland.public.delphi.database.general not fond
Hello. My problem is I am trying to connect to a newsgroup that I have configured in Outlook Express 6, under Windows XP and appears this as follows mistake : 411 Group borland.public.delphi.database.general not found. Setup: Count: newsgroups.borland.com Server: newsgroups.borland.com Protocol: NNTP Port: 119 Security (SSL): 0 Error Number: 411 Code: 800ccca5 With the newsgroup of Newsgroups.borland.com before it could enter the group borland.public.delphi.database.general, This is for all groups that begin with borland. I hope you can hel...

Delphi component for computing general linear mixed models ??
Are there any statistical software available for Delphi for computing General linear mixed models so that having a data sampler and analyser also may run statistics directly on group of humans observed pr minute basis that should be compared together ?? For you old-timers here is a hint as to what the subject is about: http://www.google.com/search?hl=en&q=%22General+linear+mixed+models%22 --JohnH Have you looked at http://www.dewresearch.com/ which has some useful code for that sort of thing? /Matthew Jones/ Alf Christophersen wrote: > Are there any statistical softw...

Web resources about - Transparent Trackbar - embarcadero.delphi.general

The Transparent Society - Wikipedia, the free encyclopedia
The Transparent Society (1998) is a non-fiction book by the science-fiction author David Brin in which he forecasts social transparency and some ...

Should EU Governments Be More Transparent, Flexible When Requesting Facebook User Data?
Facebook received about 8,500 requests for user data from governments of countries in the European Union during the first six months of 2013, ...

Transparent (@transparent_tv) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Transparent @ transparent_tv ...

CutOut Studio - Background Eraser, Cut Out Photo : Chop photo and Erase the background to be transparent ...
Get CutOut Studio - Background Eraser, Cut Out Photo : Chop photo and Erase the background to be transparent on the App Store. See screenshots ...

Transparent chemistry glass tubes filled with substances - Flickr - Photo Sharing!
Several chemistry tubes made from transparent glass filled either with water or blue and red substances. Some of the recipients have white gradations ...

[Tutorial][Linux] Transparent gnome-terminal HOW TO ( Debian, Ubuntu, Fedora, Mint, GNOME ) - YouTube ...
After watching this video you will be able to do: - Changing font color, background color - Image as background - Transparent background I dont ...

Jaguar Land Rover reveals transparent pillars
... new technology that will endow motorists with an uninterrupted 360-degree view of their surroundings from the driver's seat. The Transparent ...

Expect a budget full of transparent fudging - Business Spectator
There is just as much massaging of the numbers in Joe Hockey’s recent comments as in any of the budgets that Labor claimed were a 'pathway to ...

Transparent's warmth and intelligence infuses its comedy
x TRANSPARENT **** www.stan.com.au Stan, one of a bevy of new streaming services, launched a month ago with a couple of fabulous pieces of ...

Transparent house - Real Estate - Property and Real Estate - - Perth Now
IT&#8217;s not the type of house where you can do a quick nude rush from the bedroom to the bathroom, in fact it&#8217;s not the kind of house ...

Resources last updated: 12/11/2015 10:58:33 PM