Results 1 to 4 of 4

Thread: [RESOLVED] How to make transparent window ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2021
    Posts
    2

    Resolved [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 );
    Name:  153027-window.jpg
Views: 286
Size:  6.6 KB

    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);
    }

  2. #2

    Thread Starter
    New Member
    Join Date
    Nov 2021
    Posts
    2

    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

  3. #3
    New Member
    Join Date
    Apr 2022
    Posts
    1

    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?

  4. #4
    New Member
    Join Date
    Dec 2022
    Posts
    1

    Re: [RESOLVED] How to make transparent window ?

    Hey could guide a bit on where and which file we have to make such edits? I have some sort or ui made in unreal and wants it to be transparent overlay. Please guide on how and where such edits we need to make.
    Replies are highly appreciated!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width