microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.25k stars 671 forks source link

WinUI3 uses the CreateWindow function #8289

Open ClearSeve opened 1 year ago

ClearSeve commented 1 year ago

Through get_WindowHandle method gets the window handle and creates the window

    void SetOpacity(HWND hWnd, int nOpacity)
    {
        SetLayeredWindowAttributes(hWnd, 0, (BYTE)(255 * nOpacity / 100), LWA_ALPHA);
    }

    MainWindow::MainWindow()
    {
        InitializeComponent();

        auto windowNative{ this->try_as<IWindowNative>() };
        HWND hWnd{ 0 };
        windowNative->get_WindowHandle(&hWnd);

        GdiplusStartupInput gdiplusStartupInput;
        ULONG_PTR gdiplusToken;
        GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

        auto sImage = GetFullPathToAsset(L"butterfly.png");
        HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, &sImage[0], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        Bitmap bmp(&sImage[0], true);
        Status status = bmp.GetHBITMAP(Gdiplus::Color(0, 0, 0), &hBitmap);

        HWND hWndChild = CreateWindowEx(WS_EX_TRANSPARENT | WS_EX_LAYERED, L"static", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_BITMAP | SS_REALSIZEIMAGE /*SS_REALSIZECONTROL*/, 10, 10, 400, 400, hWnd, NULL, NULL, NULL);
        SetOpacity(hWndChild, 100);
        SendMessage(hWndChild, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
    }

image You can see that the window has successfully created and displayed a picture, but this button is below the window just created. Is there any way to put the button before the window just created. It can be changed as long as it can be realized reference material: https://learn.microsoft.com/en-us/answers/questions/1115740/can-we-use-both-winui3-controls-and-win32-controls

ClearSeve commented 1 year ago

image It feels like this is the drawing area created using createwindow

image My own display is incomplete

AzAgarampur commented 1 year ago

Xaml islands for WinUI 3 aren't supported yet, you can use WinUI 2 XAML islands to do what you want and have a separate child HWND for xaml content.