-
Nov 27th, 2021, 11:06 AM
#1
Thread Starter
New Member
[RESOLVED] How to make transparent window ?
Hi, I hope you are doing good.
I am working in UnrealEngine and I want to make a transparent background by color, for example black color. I have tryed in two different ways.
1. I get a result like in the picture below.
Code:
HDC hdc = GetDC(hwnd);
HDC hdc1 = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
HBITMAP hBmpOld = (HBITMAP)SelectObject(hdc, hBitmap);
FillRect(hdc,&rect,CreateSolidBrush(RGB(0,0,0)));
SelectObject ( hdc, hBitmap );
TransparentBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hdc1, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0x00000000);
const MARGINS margins{ -1 };
DwmExtendFrameIntoClientArea(hwnd, &margins);
LONG nExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, nExStyle | WS_EX_LAYERED);
SetLayeredWindowAttributes( hwnd, 0x00000000, FMath::TruncToInt( 0.2 255.0f ), LWA_ALPHA );
or
//SetLayeredWindowAttributes( hwnd, 0x00000000, FMath::TruncToInt( 0.2 255.0f ), LWA_COLORKEY );

2. I get a full transparent window
TransparentBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hdc1, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0x00000000);
if (hdc)
{
HGDIOBJ hPrevObj = 0;
POINT ptDest = {rect.left, rect.top};
POINT ptSrc = {0, 0};
SIZE client = {rect.right - rect.left, rect.bottom - rect.top};
BLENDFUNCTION blendFunc = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
UpdateLayeredWindow(hwnd, hdc1, &ptDest, &client, hdc, &ptSrc, RGB(0, 0, 0), &blendFunc, ULW_COLORKEY);
//AlphaBlend(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hdc1, 0, 0, rect.right - rect.left, rect.bottom - rect.top, blendFunc);
SelectObject(hdc, hBmpOld);
DeleteObject(hBitmap);
DeleteDC(hdc);
ReleaseDC(NULL, hdc1);
}
-
Nov 27th, 2021, 01:25 PM
#2
Thread Starter
New Member
Re: [RESOLVED] How to make transparent window ?
So the problem I was facing had nothing to do with alpha-blending, after so many days I have managed to find the solution. I had to change from directx to ES3.1
-
Apr 3rd, 2022, 05:35 PM
#3
New Member
Re: [RESOLVED] How to make transparent window ?
Hey did you implement this in the windowswindow.cpp or create a new blank class of the engine?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|