Click here to Skip to main content
15,887,915 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I’m trying to trigger DwmExtendFrameIntoClientArea on a Webbrowser which doesn't support RGBA values of 0, 0, 0, 0. My approach was to define one special color for example RGB 255, 0, 0 to be totally transparent. I got this to work in a Windows Forms Project using the TransparencyKey which made every Pixel in the chosen color showing the extended Frame but I couldn't find anything like this in non Form applications.

What I have tried:

SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
	SetLayeredWindowAttributes(hWnd, RGB(255, 0, 0), 0, LWA_COLORKEY);
	MSG msg1;

	if (message == WM_ACTIVATE)
	{
		
		// Set margins, extending the bottom margin
		//MARGINS margins = { 30,30,30,25 };
		//MARGINS margins;
		//margins.cxLeftWidth = 0;      
		//margins.cxRightWidth = 0;   
		// margins.cyBottomHeight = 30; 
		//margins.cyTopHeight = 30;  //not shure needs to be tweaked 
		   MARGINS margins = { 0,0,59,0 };
		HRESULT hr = S_OK;

		// Extend frame on the bottom of client area
		hr = DwmExtendFrameIntoClientArea(hWnd, &margins);
		if (!SUCCEEDED(hr))
		{
			// ...
		}
		return hr;

The part which should call that code is Corored by This code in css:
html {
	background-color:rgba(255, 0, 0, 1);
	height: 100%;
Posted
Updated 23-Jul-20 21:13pm

In the fields below the last value is between 0.0 for fully transparent, and 1.0 for fully opaque. The second Red row shows fully opaque, the rest are partially transparent.

Red : background-color:rgba(255,0,0,0.3)


Red : background-color:rgba(255,0,0,1.0)


Green : background-color:rgba(0,255,0,0.3)


Blue : background-color:rgba(0,0,255,0.3)


Grey : -color:rgba(192,192,192,0.3)


Yellow : background-color:rgba(255,255,0,0.3)


Cerise : background-color:rgba(255,0,255,0.3)


Part transparent Red text : color:rgba(255,0,0,0.3)



The code is:
HTML
<p style="background-color:rgba(255,0,0,0.3);">Red : background-color:rgba(255,0,0,0.3)</p>
<p style="background-color:rgba(255,0,0,1.0);">Red : background-color:rgba(255,0,0,1.0)</p>
<p style="background-color:rgba(0,255,0,0.3);">Green : background-color:rgba(0,255,0,0.3)</p>
<p style="background-color:rgba(0,0,255,0.3);">Blue : background-color:rgba(0,0,255,0.3)</p>
<p style="background-color:rgba(192,192,192,0.3);">Grey : -color:rgba(192,192,192,0.3)</p>
<p style="background-color:rgba(255,255,0,0.3);">Yellow : background-color:rgba(255,255,0,0.3)</p>
<p style="background-color:rgba(255,0,255,0.3);">Cerise : background-color:rgba(255,0,255,0.3)</p>
<p style="color:rgba(255,0,0,0.3);">Part transparent Red text : color:rgba(255,0,0,0.3)</p>
 
Share this answer
 
v2
Comments
Member 14884389 10-Aug-20 10:28am    
I think you don't quite get what I'm trying to do. That way only the html document gets transparent and not the browser itself (it's still white background even with alpha 0). Im searching for some type of C++ alternative to the Transparencykey from C++ Forms. The question isn't how to make the html document transparent it's how to make a browser transparent (which to my knowledge is impossible) or find a way around the webbrowser to show the window background which is an extended title bar like the code above shows. I already tested (in C++ Forms) that rgba(255, 0, 0, 1) html parts are showing the window background when the Transparencykey is rgba(255, 0, 0, 1).
Here is what i'm trying to do done in Forms https://stackoverflow.com/questions/20141220/how-can-i-set-a-transparent-background-colour-for-a-webbrowser-in-vb-net
Richard MacCutchan 10-Aug-20 11:18am    
I am sorry but I am getting quite confused as to exactly what you are trying to do. You seem to be mixing web browser issues with C++ issues, and it is not clear what application you are trying to make, and what part or parts you want to be transparent.
Member 14884389 10-Aug-20 15:33pm    
I'm trying to get parts of the webbrowser compleatly see-through so i can use the extend title feature to make it look like the title bar is part of the webbrowser
Richard MacCutchan 11-Aug-20 2:50am    
What webbrowser are you referring to? I am still confused as to how this may relate to C++ Windows code.
Member 14884389 12-Aug-20 14:18pm    
https://www.bilder-upload.eu/bild-e3d635-1597256412.png.html
https://www.bilder-upload.eu/bild-51bd12-1597256437.png.html
code:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices

Public Class Form1



Private mExtendedFrameMargins As MARGINS

Protected Overrides Sub _
OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
'use either one
e.Graphics.SmoothingMode = SmoothingMode.HighQuality
End Sub

Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If IsGlassEnabled() Then
'You should paint the extended frame black for proper composition, but I'm painting it white as you need it
e.Graphics.FillRectangle(Brushes.Black, 0, 0, Me.ClientRectangle.Width, mExtendedFrameMargins.cyTopHeight)
End If
End Sub

Private Function IsGlassEnabled() As Boolean
If Environment.OSVersion.Version.Major < 6 Then
Return False
End If

Dim isGlassSupported As Boolean = False
DwmIsCompositionEnabled(isGlassSupported)
Return isGlassSupported
End Function

<dllimport("dwmapi.dll")>
Private Shared Function DwmIsCompositionEnabled(<marshalas(unmanagedtype.bool)> ByRef pfEnabled As Boolean) As Integer
End Function

<dllimport("dwmapi.dll")>
Private Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef pMarInset As MARGINS) As Integer
End Function


<structlayout(layoutkind.sequential)>
Private Structure MARGINS
Public cxLeftWidth As Integer
Public cxRightWidth As Integer
Public cyTopHeight As Integer
Public cyBottomHeight As Integer
End Structure



Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.DocumentText = ""

If IsGlassEnabled() Then
mExtendedFrameMargins = New MARGINS
mExtendedFrameMargins.cyTopHeight = Me.Height 'type height here, this is going to be a number (integer)
DwmExtendFrameIntoClientArea(Me.Handle, mExtendedFrameMargins)
End If
End Sub

Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
If IsGlassEnabled() Then
mExtendedFrameMargins = New MARGINS
mExtendedFrameMargins.cyTopHeight = Me.Height 'type height here, this is going to be a number (integer)
DwmExtendFrameIntoClientArea(Me.Handle, mExtendedFrameMargins)
End If
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

WebBrowser1.Document.BackColor = Color.FromArgb(1, 255, 0, 0)

If IsGlassEnabled() Then
mExtendedFrameMargins = New MARGINS
mExtendedFrameMargins.cyTopHeight = Me.Height 'type height here, this is going to be a number (integer)
DwmExtendFrameIntoClientArea(Me.Handle, mExtendedFrameMargins)
End If
End Sub



' Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
' WebBrowser1.Document.BackColor = Color.Black

' End Sub
End Class
What you can see inside the red box is a Webbrowser with document color red and the transparency key of th form is set to red so it will trigger the extendaero api in this webbrowser where no alpha value is given. I'm trying to achive the same result in a c++ non form application but i couldn't find anything like the Transparency key in c++. The goal is to make th webbrowser control invisible
CSS Colors[^] adds the opacity value to make colors semi-transparent.
 
Share this answer
 
Comments
Member 14884389 23-Jul-20 20:59pm    
How should I use it to solve my problem? Is it possible to color a webbrowser with them and if yes how? Can you give me some syntax the website you linked isn't loading.
Richard MacCutchan 24-Jul-20 3:14am    
I am not sure why you cannot get to the W3Schools website, it works fine for me. However, see the examples below.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900