How to change window style for hwnd ?

Hi, do you know how to change the windows style to WS_EX_LAYERED | WS_EX_TRANSPARENT and change the opacity? There seems to be some changes on w 11 that prevent that. I am using UE 4.27 and w 11. Thankyou in advance!

This is not your exact solution but I think you have to use Unreal Source code (because this kind of modifications require engine based changes) and look at this header or maybe SWindow & SNew.

https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Core/Public/Windows/MinWindows.h

Because when I tried to implement two way window scroll (not widget based), I found “NOSCROLL” definations in here.

It is possible to change the style without editing the source code like here:

The problem is that SetLayeredWindowAttributes works only with LWA_ALPHA, not with LWA_COLORKEY.

1 Like

According to Microsoft’s documentation, that function accept LWA_COLORKEY as DWORD. But you say that you can’t use LWA_COLORKEY with Unreal Engine.

As I mentioned ony my problem, are you sure that there were not any define or other stuffs to prevent that modifications ? Because normally, I should be able to enable scrollbars on pages with correct DWORDS. But in order to delete that preventation, I had to use source code. I mean it wasn’t about winuser.h’s code. It was about Unreal.

Are you sure that you don’t have same problem ?

1 Like

I tried as you said to replace LWA_COLORKEY, same result, and LWA_ALPHA is working. Thankyou anyway!

I think I solved it

BUT
It lost click focus :smiley: I will try couple things.

//

TSharedPtr<SWindow> WidgetWindow;
WidgetWindow = SNew(SWindow)
.SupportsTransparency(EWindowTransparency::PerWindow)
.InitialOpacity(InOpacity)

and
SetWindowOpacity()

work without UpdateLayeredWindow or SetLayeredWindowAttributes if we use WS_EX_LAYERED on SetWindowLongPtr but as mentioned on other topic, it loose click focus. not entire focus because widgets can detect hovering.

maybe is there a bug about UE’s set opacity and initial opacity functions ?

//
we can solve it like this. TSharedPtr<SWindow>.ToSharedRef().Get().IsHovered() can detect hovering even if there is WS_EX_LAYERED and mouse can’t click.

So, we can open and close that layer with an additional function if there is a hover or not.

I have a plugin about these kind of stuffs. It detects hovering at every 0.5 second with SetTimerByEvent. I can implement this open and close thing.

I know that it won’t be a real transperancy. but it is better than nothing.

//

finished implementation. If you want, I can share my repo.

2 Likes

I don’t think this is what I was looking for. Is that a blueprint actor or a widget blueprint ? Here is the effect (url) I am trying to achieve, it worked on w 8 before, I forgot the settings.

Nope it’s not a widget. It is a real window which created by SNew(SWindow).

SNew(SWindow) has its own api and classes based on CreateWindowEx

but also has additional functions to carry UMG widgets inside. Also my implementation has runtime file drag drop support to import things in runtime.

But yes, I saw an effect like this. You want transparent window background but contents should be visible.

SetOpacity and initial opacity changes whole window and its inside.

1 Like

So I was thinking of making a new window on top of the original, copy content based on alpha, and hide the original window …

it works with vulkan

1 Like

This code can change SWindow based window’s background color. There are more and FSlateBrush related detailed functions, too. But if I set alpha values to 0, window becomes completely black.

At your case, directx or windows 11 can be the problem but for me maybe there is an engine code to give default color for window’s background.

FWindowStyle TempStyle = FCoreStyle::Get().GetWidgetStyle<FWindowStyle>("Window");
TempStyle.SetOutlineColor(BGColor);
TempStyle.SetBackgroundColor(BGColor);
TempStyle.SetBorderColor(BGColor);
static FWindowStyle WindowStyle = TempStyle;

SNew(SWindow)
.Style(&WindowStyle );
1 Like

Not sure if we are talking about same things. Let’s say you have an empty map with a cube, I want to see only the cube, the background should be fully transparent. Anyway, as I said, I fixed with vulkan and this answer. Maybe I will look later into your solution for something else. I will give you the right answer because you put so much effort into helping me. Thankyou!

We are talking same thing with different solutions.

At first I thought you want complete transparent (a ghost like) window. It is done.

but when I saw some samples at reddit, I understood your goal. you want a somekind of masking. Only content should be visible but not borders and other stuffs.

I went with SWindow solution, because I don’t want to put only a bitmap to that window. I wanted to put a whole UMG widget.

Vulkan can solve some problems but it is not an exact solution. For example, if you want to create a window for VR project, (I don’t speak about 3D widgets or VR interacted interfaces. I mean spectator/supervisor control windows for simulation or virtual production projects), you should use directx as target RHI.

Anyway, I am glad if you solve yout problem but I will meddling with this stuff just a little more :smiley:

2 Likes

I am trying to this on android now, I made a new question
Would your solution work ? :sweat_smile:

Why do you need a “window” on android ? :smiley: I need a window system because I wanted to move that windows to another screen. Can’t we just create a drag drop widget ? :smiley:

I want to see 3d objects above android screen.

Actually you need two things.
1- A window with masking support
2- Runtime gizmo system. Because (probably) you need to rotate that model sometimes. (I am thinking this kind of stuff on main view. https://help.autodesk.com/cloudhelp/2023/ENU/3DSMax-Basics/images/GUID-EF5722FC-D0E1-42D2-A12A-34C312F9F73B.png)

My solution doesn’t support masking at all.
But I would use ScreenCapture2D if I was in your shoes.

  1. Put your model to unreachable and unvisible location which has a black background (there are some background sample for virtual production usages)

  2. Capture that view and use that captured texture in a material.

  3. Mask background

  4. Put it into to a widget

  5. (BONUS) if you need gizmo, write your mechanics to rotate that ScreenCapture2D.

For performance, you can toggle ScreenCapture2D’s capture with blueprints. When you don’t want to rotate it, just disable capture and only open it when you rotate it.

Other than that maybe you can try to integrate ImGui to Unreal for creating new windows , gizmo system and model rendering on Android. I saw some ImGui usages on Android but they weren’t related with Unreal.

Well, it is possible to capture only the object as you say, but it remains the background like in this picture.
Screenshot 2023-05-23 233548

  1. Disable floor
  2. Use that texture in material. Not directly in a widget.
  3. Set Material Domain to “User Interface” and Blend Mode to “Masked”
  4. Attach RGBA output of texture to material’s Opacity Mask input.

This will masks all black color.
But be careful. Your model’s material shouldn’t contain any black color in it.

This is my test view. (It is cube with DefaultColorCalibration texture of Unreal. It has some blacks in it)

this is masking. If there wasn’t any black in model’s material, we could see a better 3d-ish view)

//
Or you can put your model to correct relative location based on camera in player character.
And you can change it’s location with only changing its X-Y axis.

I think creating another window is overkill for that.

Well yea, I don’t want to mask the cube, but the black environment behind it so it would show android screen where is black in that picture.