B
bestwarrior
Guest
Hi, I am working with UnrealEngine and I want to make the window 100% transparent and the object in the scene opaque. According to these guys (https://forum.unity.com/threads/sol...dow-with-opaque-contents-lwa_colorkey.323057/) I should use this code but it's not working.:
SetWindowLong(HWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
SetWindowLong(HWnd, -20, 524288 | 32);//GWL_EXSTYLE=-20; WS_EX_LAYERED=524288=&h80000, WS_EX_TRANSPARENT=32=0x00000020L
SetLayeredWindowAttributes(HWnd, 0, 255, 2);// Transparency=51=20%, LWA_ALPHA=2
SetWindowPos(HWnd, HWND_TOPMOST, 0, 0, fWidth, fHeight, 32 | 64);
MARGINS Margins = { -1 };
verify(SUCCEEDEDwmExtendFrameIntoClientArea(HWnd, &Margins)));
The Hwnd it's created like this:
const bool bApplicationSupportsPerPixelBlending =
#if ALPHA_BLENDED_WINDOWS
Application->GetWindowTransparencySupport() == EWindowTransparency:erPixel;
#else
false;
#endif
if( !Definition->HasOSWindowBorder )
{
WindowExStyle = WS_EX_WINDOWEDGE;
if( Definition->TransparencySupport == EWindowTransparency:erWindow )
{
WindowExStyle |= WS_EX_LAYERED;
}
#if ALPHA_BLENDED_WINDOWS
else if( Definition->TransparencySupport == EWindowTransparency:erPixel )
{
if( bApplicationSupportsPerPixelBlending )
{
WindowExStyle |= WS_EX_COMPOSITED;
}
}
#endif
WindowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
if ( Definition->AppearsInTaskbar )
{
WindowExStyle |= WS_EX_APPWINDOW;
}
else
{
WindowExStyle |= WS_EX_TOOLWINDOW;
}
if( Definition->IsTopmostWindow )
{
// Tool tips are always top most windows
WindowExStyle |= WS_EX_TOPMOST;
}
if ( !Definition->AcceptsInput )
{
// Window should never get input
WindowExStyle |= WS_EX_TRANSPARENT;
}
}
else
{
// OS Window border setup
WindowExStyle = WS_EX_APPWINDOW;
WindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION;
if (IsRegularWindow())
{
if (Definition->SupportsMaximize)
{
WindowStyle |= WS_MAXIMIZEBOX;
}
if (Definition->SupportsMinimize)
{
WindowStyle |= WS_MINIMIZEBOX;
}
if (Definition->HasSizingFrame)
{
WindowStyle |= WS_THICKFRAME;
}
else
{
WindowStyle |= WS_BORDER;
}
}
else
{
WindowStyle |= WS_POPUP | WS_BORDER;
}
// X,Y, Width, Height defines the top-left pixel of the client area on the screen
// This adjusts a zero rect to give us the size of the border
RECT BorderRect = { 0, 0, 0, 0 };
::AdjustWindowRectEx(&BorderRect, WindowStyle, false, WindowExStyle);
//::AdjustWindowRectEx(&BorderRect, WS_VISIBLE | WS_POPUP, false, WS_EX_LAYERED);
// Border rect size is negative - see MoveWindowTo
WindowX += BorderRect.left;
WindowY += BorderRect.top;
// Inflate the window size by the OS border
WindowWidth += BorderRect.right - BorderRect.left;
WindowHeight += BorderRect.bottom - BorderRect.top;
}
// Creating the Window
HWnd = CreateWindowEx(
WindowExStyle,
AppWindowClass,
*Definition->Title,
WindowStyle,
WindowX, WindowY,
WindowWidth, WindowHeight,
( InParent.IsValid() ) ? static_cast<HWND>( InParent->HWnd ) : NULL,
NULL, InHInstance, NULL);
I used this code too but it's not working
SetWindowLongPtr(HWnd, GWL_EXSTYLE, WS_EX_LAYERED);
SetLayeredWindowAttributes(HWnd, RGB(0, 0, 0), 255, LWA_ALPHA); // | LWA_COLORKEY);
MARGINS Margins = { -1 };
verify(SUCCEEDEDwmExtendFrameIntoClientArea(HWnd, &Margins)));
::SetWindowPos(HWnd, nullptr, 0, 0, WindowWidth, WindowHeight, SWP_DRAWFRAME | SWP_FRAMECHANGED);//OnTransparencySupportChanged(EWindowTransparency:erPixel);
Only thing thats working is
SetLayeredWindowAttributes( HWnd, 0, FMath::TruncToInt( InOpacity * 255.0f ), LWA_ALPHA);
but this is making whole window transparent including objects.
This affects and the editor too, not only the game window. I tried also to use Direct composition like in this link(Windows with C++ - High-Performance Window Layering Using the Windows Composition Engine)
Any help would be apreciated. Thankyou.
Continue reading...
SetWindowLong(HWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
SetWindowLong(HWnd, -20, 524288 | 32);//GWL_EXSTYLE=-20; WS_EX_LAYERED=524288=&h80000, WS_EX_TRANSPARENT=32=0x00000020L
SetLayeredWindowAttributes(HWnd, 0, 255, 2);// Transparency=51=20%, LWA_ALPHA=2
SetWindowPos(HWnd, HWND_TOPMOST, 0, 0, fWidth, fHeight, 32 | 64);
MARGINS Margins = { -1 };
verify(SUCCEEDEDwmExtendFrameIntoClientArea(HWnd, &Margins)));
The Hwnd it's created like this:
const bool bApplicationSupportsPerPixelBlending =
#if ALPHA_BLENDED_WINDOWS
Application->GetWindowTransparencySupport() == EWindowTransparency:erPixel;
#else
false;
#endif
if( !Definition->HasOSWindowBorder )
{
WindowExStyle = WS_EX_WINDOWEDGE;
if( Definition->TransparencySupport == EWindowTransparency:erWindow )
{
WindowExStyle |= WS_EX_LAYERED;
}
#if ALPHA_BLENDED_WINDOWS
else if( Definition->TransparencySupport == EWindowTransparency:erPixel )
{
if( bApplicationSupportsPerPixelBlending )
{
WindowExStyle |= WS_EX_COMPOSITED;
}
}
#endif
WindowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
if ( Definition->AppearsInTaskbar )
{
WindowExStyle |= WS_EX_APPWINDOW;
}
else
{
WindowExStyle |= WS_EX_TOOLWINDOW;
}
if( Definition->IsTopmostWindow )
{
// Tool tips are always top most windows
WindowExStyle |= WS_EX_TOPMOST;
}
if ( !Definition->AcceptsInput )
{
// Window should never get input
WindowExStyle |= WS_EX_TRANSPARENT;
}
}
else
{
// OS Window border setup
WindowExStyle = WS_EX_APPWINDOW;
WindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION;
if (IsRegularWindow())
{
if (Definition->SupportsMaximize)
{
WindowStyle |= WS_MAXIMIZEBOX;
}
if (Definition->SupportsMinimize)
{
WindowStyle |= WS_MINIMIZEBOX;
}
if (Definition->HasSizingFrame)
{
WindowStyle |= WS_THICKFRAME;
}
else
{
WindowStyle |= WS_BORDER;
}
}
else
{
WindowStyle |= WS_POPUP | WS_BORDER;
}
// X,Y, Width, Height defines the top-left pixel of the client area on the screen
// This adjusts a zero rect to give us the size of the border
RECT BorderRect = { 0, 0, 0, 0 };
::AdjustWindowRectEx(&BorderRect, WindowStyle, false, WindowExStyle);
//::AdjustWindowRectEx(&BorderRect, WS_VISIBLE | WS_POPUP, false, WS_EX_LAYERED);
// Border rect size is negative - see MoveWindowTo
WindowX += BorderRect.left;
WindowY += BorderRect.top;
// Inflate the window size by the OS border
WindowWidth += BorderRect.right - BorderRect.left;
WindowHeight += BorderRect.bottom - BorderRect.top;
}
// Creating the Window
HWnd = CreateWindowEx(
WindowExStyle,
AppWindowClass,
*Definition->Title,
WindowStyle,
WindowX, WindowY,
WindowWidth, WindowHeight,
( InParent.IsValid() ) ? static_cast<HWND>( InParent->HWnd ) : NULL,
NULL, InHInstance, NULL);
I used this code too but it's not working
SetWindowLongPtr(HWnd, GWL_EXSTYLE, WS_EX_LAYERED);
SetLayeredWindowAttributes(HWnd, RGB(0, 0, 0), 255, LWA_ALPHA); // | LWA_COLORKEY);
MARGINS Margins = { -1 };
verify(SUCCEEDEDwmExtendFrameIntoClientArea(HWnd, &Margins)));
::SetWindowPos(HWnd, nullptr, 0, 0, WindowWidth, WindowHeight, SWP_DRAWFRAME | SWP_FRAMECHANGED);//OnTransparencySupportChanged(EWindowTransparency:erPixel);
Only thing thats working is
SetLayeredWindowAttributes( HWnd, 0, FMath::TruncToInt( InOpacity * 255.0f ), LWA_ALPHA);
but this is making whole window transparent including objects.
This affects and the editor too, not only the game window. I tried also to use Direct composition like in this link(Windows with C++ - High-Performance Window Layering Using the Windows Composition Engine)
Any help would be apreciated. Thankyou.
Continue reading...