castorix / WinUI3_SwapChainPanel_Layered

47 stars 2 forks source link

How to embed a child window into the window in WinUI3 #3

Closed Poker-sang closed 1 year ago

Poker-sang commented 1 year ago

I'm sorry to ask a question that isn't very relevant. I've heard that Winui3 windows have two layers(?), so that when I simply call SetParent() in Win32API, I cannot see a thing through WinUI3 Window. Are there any ways to remove or make the upper layer transparent? Or other efficient way to embed a child window? Thanks.

castorix commented 1 year ago

I don't see exactly what you want to do, but I often use Win32 child windows in samples like CMediaEngine.cs (code at _mhWndContainer = CreateWindowEx...) and I had to make them layered too, otherwise they are covered by the black/white background which has been added in Windows app SDK 1.1.0 (XAML controls are drawn by a child window (DesktopChildSiteBridge) with Windows Composition)

Poker-sang commented 1 year ago

Thanks for reply.❤️ But the example is too long that I couldn't catch the point after hours of reading. I'm wandering if it is really necessary to use SwapChainPanel here when I just want to embed a child window?

I mean I'm using a library, that provide an method to create a window. But I'd like to use this window as a control in the WinUI3 window.

In short, I want to set an pre-existing window as a child window (or control). Do I have to use SwapChainPanel?

castorix commented 1 year ago

The code in MediaEngine is just the line with CreateWindowEx which creates a child Win32 "Static" control , then I change opacity with SetOpacity (calls SetLayeredWindowAttributes) to make it visible (I don't use SwapChainPanel there)

Poker-sang commented 1 year ago

Thank you! I managed to make it a child window finally. And I have a last problem that, can I make input into the "child" window? Thus, I can use it as a control.

castorix commented 1 year ago

Thank you! I managed to make it a child window finally. And I have a last problem that, can I make input into the "child" window? Thus, I can use it as a control.

Maybe you can see another sample , https://github.com/castorix/WinUI3_DesktopDuplication, where I used a Win32 Hot Key control as child to register an Hot Key

Poker-sang commented 1 year ago

Thanks. I will check it soon.