Skip to content

Win32 child window not shown initially if created outside of the WinUI3 Windows constructor #1

@gmgallo

Description

@gmgallo

Using your sample code I was able to host an OpenGL page inside a WinUI3 window. However I ran into an issue which I'm not sure if it is a Windows bug or a missing step. I'm creating the child window the same way as shown in your code.

   IntPtr hchild = CreateWindowEx(WS_EX_LAYERED , "Static", "",
       WS_VISIBLE | WS_CHILD, x, y, width, height, hwndParent, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

 SetLayeredWindowAttributes(hchild, 0, (byte)(255 * nOpacity / 100), LWA_ALPHA);

 ShowWindow(hchild, SW_SHOWNORMAL);

If created in the parent window constructor, the child window displays precisely overlayed as expected. However, if the child window creation is delayed and created later by a by a member function of the parent class, it doesn't show until the parent window is moved or resized!, either by user interaction or programatically.

image
Create button already pressed, The counter on top shows OpenGL renders on the child window.

image
After moving the parent window by hand.

The same can be accomplished by calling MoveWindow() on the parent just one pixel in any direction. I've tried several Wind32 calls on the child to bring it to the front without success. Adding the flag WS_EX_TOPMOST to the child window makes no difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions