在WinUI3中,已经实现了使用CreateWindow方法创建窗口,但是这个窗口被放在前面,遮挡了xaml控件,有没有办法让xaml控件在窗口前面?
感觉这是使用createwindow创建的绘图区域
我自己的显示不完整
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);
}
需要把传统的win32程序改成CreateWindow的窗口WinUI3,算法处理非常复杂,这个问题困扰我很久了,不管怎么实现,谢谢
参考材料:https://learn.microsoft.com/en-us/answers/questions/1115740/can-we-use-both-winui3-controls-and-win32-controls
在此期间,我查阅了大量的相关资料,但没有任何收获,在WinUI3中使用CreateWindow的相关问题很少
1条答案
按热度按时间voase2hg1#
简单地说,使用CreateWindow创建一个不会遮挡Winui3控件的窗口