Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Transparent color value malfunction ?


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 12 - Last Post: Jun 5, 2015 10:10 AM Last Post By: Remy Lebeau (Te...
Massimo Bisazza

Posts: 5
Registered: 11/7/01
Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 28, 2015 2:03 PM
Setting the "TransparentColorValue" property of a Form leads to a different working operations.
Only clWhite, clBlack and system values, like clBtnFace are working (i didn't try but i .think that also a pure green may works).
Other values are not working in the right way.

Open a new VCL project (WIN32 or WIN64)
Try to setting this value (that is a BGR coding ) $00FDEEE3 as property Color of a Form and the same value in the property TransparentColorValue of the Form.
Enable TransparentColor property.

Run the project, you'll see correctly the client area of the Form in transparent way, but you can't access with a mouse to the background (Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form, but ...... you can access to the background with a mouse (Windows desktop).

I try this with a Windows 8.1 SO and Delphi XE8.

Some solutions ?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent color value malfunction ?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 28, 2015 2:22 PM   in response to: Massimo Bisazza in response to: Massimo Bisazza
Massimo wrote:

Run the project, you'll see correctly the client area of the Form in
transparent way, but you can't access with a mouse to the background
(Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property
TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form,
but ...... you can access to the background with a mouse (Windows
desktop).

I can reproduce it in XE2.

I would say blame Microsoft, not Embarcadero. The VCL simply passes the
TransparentColorValue as-is (well, system colors are translated to RGB values
first) to the SetLayeredWindowAttributes() function. It handles the actual
transparency after WM_PAINT draws the window (using the TForm.Color as the
background). TForm does not handle hit testing messages at runtime by default,
those messages are passed on to the default Windows message handler. So
it has to be Windows, not the VCL, that is passing mouse events through the
clietn area based on its color and transparency, and obviously doing it incorrectly
for some colors.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 28, 2015 2:47 PM   in response to: Massimo Bisazza in response to: Massimo Bisazza
Massimo wrote:

Run the project, you'll see correctly the client area of the Form in
transparent way, but you can't access with a mouse to the background
(Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property
TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form,
but ...... you can access to the background with a mouse (Windows
desktop).

I can reproduce it in XE2.

I would say blame Microsoft, not Embarcadero. The VCL simply passes the
TransparentColorValue as-is (well, system colors are translated to RGB values
first) to the SetLayeredWindowAttributes() function. It handles the actual
transparency after WM_PAINT draws the window (using the TForm.Color as the
background). TForm does not handle hit testing messages at runtime by default,
those messages are passed on to the default Windows message handler. So
it has to be Windows, not the VCL, that is passing mouse events through the
clietn area based on its color and transparency, and obviously doing it incorrectly
for some colors.

--
Remy Lebeau (TeamB)
Massimo Bisazza

Posts: 5
Registered: 11/7/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2015 2:07 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Sorry for reply delay but i had difficult to use EDN.
I tried with MVS and the problems are the same. I also tried with different PC, and with most of them the transparency works. The Windows 7 (x86 and x64) with video card at 24 bpp always worked, with 32 bpp some systems were not work. In Windows 8.x the transparency have always problems. because, i think they have 32 bpp of colour.

For Remy, i don't think that system colors are converted in RGB or BGR (almost in VCL) because you can simulate the system colors with they base values ($FF0000xx) and "sending" directly to windows API. This is the 'cause of tranparency always works with system colors.

I try to contact Microsoft, but i'm sure that they know about transparency bug.
Thanks for your quickly response.

Bye

Remy Lebeau (TeamB) wrote:
Massimo wrote:

Run the project, you'll see correctly the client area of the Form in
transparent way, but you can't access with a mouse to the background
(Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property
TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form,
but ...... you can access to the background with a mouse (Windows
desktop).

I can reproduce it in XE2.

I would say blame Microsoft, not Embarcadero. The VCL simply passes the
TransparentColorValue as-is (well, system colors are translated to RGB values
first) to the SetLayeredWindowAttributes() function. It handles the actual
transparency after WM_PAINT draws the window (using the TForm.Color as the
background). TForm does not handle hit testing messages at runtime by default,
those messages are passed on to the default Windows message handler. So
it has to be Windows, not the VCL, that is passing mouse events through the
clietn area based on its color and transparency, and obviously doing it incorrectly
for some colors.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2015 3:19 PM   in response to: Massimo Bisazza in response to: Massimo Bisazza
Massimo wrote:

For Remy, i don't think that system colors are converted in RGB or BGR
(almost in VCL) because you can simulate the system colors with they
base values ($FF0000xx) and "sending" directly to windows API. This is
the 'cause of tranparency always works with system colors.

The VCL converts TColor values to absolute RGB values when passing them to
API functions. The TransparentColorValue is no exception to that:

VCL.Forms.pas:

procedure TCustomForm.SetTransparentColorValue(const Value: TColor);
begin
  if FTransparentColorValue <> Value then
  begin
    FTransparentColorValue := Value;
    SetLayeredAttribs;
  end;
end;
 
procedure TCustomForm.SetLayeredAttribs;
...
begin
  ...
  SetLayeredWindowAttributes(Handle, ColorToRGB(FTransparentColorValue), 
...);
  ...
end;


VCL.Graphics.pas:

function ColorToRGB(Color: TColor): Longint;
begin
  if Color < 0 then
    Result := GetSysColor(Color and $000000FF) else
    Result := Color;
end;


TColor values that represent system colors (clBtnFace, etc) are converted
to RGB via the Win32 API GetSysColor() function, whereas TColor values that
represent specific colors (clRed, $00E3EEFD, etc) are used as-is.

--
Remy Lebeau (TeamB)
Massimo Bisazza

Posts: 5
Registered: 11/7/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2015 3:54 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
My fault Remy, i didn't go in depth.
Not all system colors work too ........

Colors or system colors work only if the trasformation between RGB and BGR give the same color value (for example, clBtnFace works 'cause in RGB or BGR it is normally $F0F0F0))

It Seems that is something wrong between RGB and BGR (or rappresentation of color space in a 32 bpp system), like if some Microsoft Windows internal functions work with RGB and others work in BGR.

I'm waiting for Microsoft answer.

Thanks again.

Remy Lebeau (TeamB) wrote:
Massimo wrote:

For Remy, i don't think that system colors are converted in RGB or BGR
(almost in VCL) because you can simulate the system colors with they
base values ($FF0000xx) and "sending" directly to windows API. This is
the 'cause of tranparency always works with system colors.

The VCL converts TColor values to absolute RGB values when passing them to
API functions. The TransparentColorValue is no exception to that:

VCL.Forms.pas:

procedure TCustomForm.SetTransparentColorValue(const Value: TColor);
begin
  if FTransparentColorValue <> Value then
  begin
    FTransparentColorValue := Value;
    SetLayeredAttribs;
  end;
end;
 
procedure TCustomForm.SetLayeredAttribs;
...
begin
  ...
  SetLayeredWindowAttributes(Handle, ColorToRGB(FTransparentColorValue), 
...);
  ...
end;


VCL.Graphics.pas:

function ColorToRGB(Color: TColor): Longint;
begin
  if Color < 0 then
    Result := GetSysColor(Color and $000000FF) else
    Result := Color;
end;


TColor values that represent system colors (clBtnFace, etc) are converted
to RGB via the Win32 API GetSysColor() function, whereas TColor values that
represent specific colors (clRed, $00E3EEFD, etc) are used as-is.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2015 11:59 AM   in response to: Massimo Bisazza in response to: Massimo Bisazza
Massimo wrote:

Colors or system colors work only if the trasformation between RGB and
BGR give the same color value (for example, clBtnFace works 'cause in
RGB or BGR it is normally $F0F0F0))

If you set both TForm.Color and TForm.TransparentColorValue to the same value,
whether that be clBtnFace or whatever, they will resolve to the same RGB.
AFAIK, Windows APIs do not use RGB in some places and BGR in other places,
everything is pretty consistent by using either COLORREF, RGBTRIPLE, or RGBQUAD.
Are you saying you ran into an API that is acting differently?

--
Remy Lebeau (TeamB)
Massimo Bisazza

Posts: 5
Registered: 11/7/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 5, 2015 3:40 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Something in Windows library GDI o DWM (Desktop Windows Manager) is acting in different way in transparency.
Send to API SetLayeredWindowAttributes a color in RGB format will result in a transparent optical form, but not transparent to mouse action.
Send to API the same color in BGR format will result in transparent mouse action and opaque form.
This happens if the value of the color in BGR and RGB is different (like $00FDEEE3 for example), in Win 8.x.

So i think that Microsoft has done a little bit confusiong. Some aspect of layered window in win 8.1 is under the control of DWM and DWM APIs are in BGR, and DWM in win 8.1 is locked (you cannot disable it) and work only in 32 bpp, this may be the problem.
For sure is that in Windows 7 if you disable DWM (AKA aero), the transparency works also with 32 bpp display, and with display setting at 24 bpp with or without aero the transparency always works (almost that i tried).

You can take some around measures, but in generally i didn't find any pratically solutions to this, expecially if you have a complex program with normal form. Of course if you construct a direct3d application you will not find these problems.

I didn't go in deep with these argoments, 'cause of limited time. Now i resolved the situation in a simple way: i modified all form colors and other graphics object with the background color $00F1F1F1. So the transparency is working in all systems (by now......will'see in Windows 10).

Bye

Remy Lebeau (TeamB) wrote:
Massimo wrote:

Colors or system colors work only if the trasformation between RGB and
BGR give the same color value (for example, clBtnFace works 'cause in
RGB or BGR it is normally $F0F0F0))

If you set both TForm.Color and TForm.TransparentColorValue to the same value,
whether that be clBtnFace or whatever, they will resolve to the same RGB.
AFAIK, Windows APIs do not use RGB in some places and BGR in other places,
everything is pretty consistent by using either COLORREF, RGBTRIPLE, or RGBQUAD.
Are you saying you ran into an API that is acting differently?

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 5, 2015 10:10 AM   in response to: Massimo Bisazza in response to: Massimo Bisazza
Massimo wrote:

Some aspect of layered window in win 8.1 is under the control of DWM
and DWM APIs are in BGR

I found this in the DWM documentation, at least in regards to glass composition:

DwmGetColorizationColor function
https://msdn.microsoft.com/en-us/library/windows/desktop/aa969513.aspx

Retrieves the current color used for Desktop Window Manager (DWM) glass composition.

...

pcrColorization [out]
A pointer to a value that, when this function returns successfully, receives
the current color used for glass composition. The color format of the value
is 0xAARRGGBB.

...

Remarks

The value pointed to by pcrColorization is in an 0xAARRGGBB format. Many
Microsoft Win32 APIs, such as COLORREF, use a 0x00BBGGRR format. Be careful
to assure that the intended colors are used.

And I also found this:

Performance Considerations and Best Practices
https://msdn.microsoft.com/en-us/library/windows/desktop/aa969536.aspx

Application Practices for DWM
...
Top-level WS_EX_TRANSPARENT windows should be combined with a WS_EX_LAYERED
style **for the purposes of hit testing**.

So, when using TransparentColorValue, you might need to override CreateParams()
to enable the WS_EX_TRANSPARENT window style.

--
Remy Lebeau (TeamB)
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 28, 2015 3:34 PM   in response to: Massimo Bisazza in response to: Massimo Bisazza
Massimo Bisazza wrote:
Setting the "TransparentColorValue" property of a Form leads to a different working operations.
Only clWhite, clBlack and system values, like clBtnFace are working (i didn't try but i .think that also a pure green may works).
Other values are not working in the right way.

Open a new VCL project (WIN32 or WIN64)
Try to setting this value (that is a BGR coding ) $00FDEEE3 as property Color of a Form and the same value in the property TransparentColorValue of the Form.
Enable TransparentColor property.

Run the project, you'll see correctly the client area of the Form in transparent way, but you can't access with a mouse to the background (Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form, but ...... you can access to the background with a mouse (Windows desktop).

I try this with a Windows 8.1 SO and Delphi XE8.

Some solutions ?

Sounds as designed (by MS) to me if I go to the trouble of creating a transparent background I want it to be transparent to the mouse as well - the fact that some colors do allow Mouse interaction sounds like a developer hack to me
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2015 5:11 PM   in response to: Linden ROTH in response to: Linden ROTH
Linden ROTH wrote:
Massimo Bisazza wrote:
Setting the "TransparentColorValue" property of a Form leads to a different working operations.
Only clWhite, clBlack and system values, like clBtnFace are working (i didn't try but i .think that also a pure green may works).
Other values are not working in the right way.

Open a new VCL project (WIN32 or WIN64)
Try to setting this value (that is a BGR coding ) $00FDEEE3 as property Color of a Form and the same value in the property TransparentColorValue of the Form.
Enable TransparentColor property.

Run the project, you'll see correctly the client area of the Form in transparent way, but you can't access with a mouse to the background (Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form, but ...... you can access to the background with a mouse (Windows desktop).

I try this with a Windows 8.1 SO and Delphi XE8.

Some solutions ?

Sounds as designed (by MS) to me if I go to the trouble of creating a transparent background I want it to be transparent to the mouse as well - the fact that some colors do allow Mouse interaction sounds like a developer hack to me
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"


Just reread you initial issue and I misunderstood "access with a mouse to the background" as you wanted to get the mouse to act on YOUR apps transparent BG ... my appologies for the out of context reply

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2015 5:11 PM   in response to: Linden ROTH in response to: Linden ROTH
Linden ROTH wrote:
Massimo Bisazza wrote:
Setting the "TransparentColorValue" property of a Form leads to a different working operations.
Only clWhite, clBlack and system values, like clBtnFace are working (i didn't try but i .think that also a pure green may works).
Other values are not working in the right way.

Open a new VCL project (WIN32 or WIN64)
Try to setting this value (that is a BGR coding ) $00FDEEE3 as property Color of a Form and the same value in the property TransparentColorValue of the Form.
Enable TransparentColor property.

Run the project, you'll see correctly the client area of the Form in transparent way, but you can't access with a mouse to the background (Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form, but ...... you can access to the background with a mouse (Windows desktop).

I try this with a Windows 8.1 SO and Delphi XE8.

Some solutions ?

Sounds as designed (by MS) to me if I go to the trouble of creating a transparent background I want it to be transparent to the mouse as well - the fact that some colors do allow Mouse interaction sounds like a developer hack to me
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"


Just reread your initial issue and I misunderstood "access with a mouse to the background" as you wanted to get the mouse to act on YOUR apps transparent BG ... my appologies for the out of context reply

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Massimo Bisazza

Posts: 5
Registered: 11/7/01
Re: Transparent color value malfunction ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2015 4:03 AM   in response to: Linden ROTH in response to: Linden ROTH
Don't worry, i understand. My question is about difforming working between applications in Win7 and Win8. The transparency is a foundamental in some applications, of course i can change the working but i'm pleasure to know what's the origin of the problem.

Bye.

Linden ROTH wrote:
Linden ROTH wrote:
Massimo Bisazza wrote:
Setting the "TransparentColorValue" property of a Form leads to a different working operations.
Only clWhite, clBlack and system values, like clBtnFace are working (i didn't try but i .think that also a pure green may works).
Other values are not working in the right way.

Open a new VCL project (WIN32 or WIN64)
Try to setting this value (that is a BGR coding ) $00FDEEE3 as property Color of a Form and the same value in the property TransparentColorValue of the Form.
Enable TransparentColor property.

Run the project, you'll see correctly the client area of the Form in transparent way, but you can't access with a mouse to the background (Windows desktop for example).

Now try to put the RGB coding color $00E3EEFD in the property TransparentColorValue of the Form (do not change the COLOR property).

Run the project and you will see the colored client area of the Form, but ...... you can access to the background with a mouse (Windows desktop).

I try this with a Windows 8.1 SO and Delphi XE8.

Some solutions ?

Sounds as designed (by MS) to me if I go to the trouble of creating a transparent background I want it to be transparent to the mouse as well - the fact that some colors do allow Mouse interaction sounds like a developer hack to me
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"


Just reread your initial issue and I misunderstood "access with a mouse to the background" as you wanted to get the mouse to act on YOUR apps transparent BG ... my appologies for the out of context reply

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02