gpt4 book ai didi

c++ - 如何在 LayeredWindow 上显示静态控件元素

转载 作者:行者123 更新时间:2023-11-28 07:21:44 25 4
gpt4 key购买 nike

我创建窗口hwnd = CreateWindowEx(WS_EX_LAYERED, szWindowClass, szTitle,0,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

然后我显示png图像

CImage img;
img.Load(Path);
int iWidth = img.GetWidth();
int iHeight = img.GetHeight();
HDC hdcScreen = GetDC(NULL);
HDC hDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmp = CreateCompatibleBitmap(hdcScreen, iWidth, iHeight);
HBITMAP hBmpOld = (HBITMAP)SelectObject(hDC, hBmp);
img.Draw(hDC,0, 0, iWidth, iHeight, 0, 0, iWidth, iHeight);
BLENDFUNCTION blend = {0};
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags=0;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = AC_SRC_ALPHA;
POINT ptPos = {0, 0};
SIZE sizeWnd = {iWidth, iHeight};
POINT ptSrc = {0, 0};
UpdateLayeredWindow(hWnd, hdcScreen, &ptPos, &sizeWnd, hDC, &ptSrc, 0, &blend, ULW_ALPHA);
SelectObject(hDC, hBmpOld);
DeleteObject(hBmp);
DeleteDC(hDC);
ReleaseDC(NULL, hdcScreen);

我想在这个窗口上创建一些静态控件元素,例如进度条。

#define ID_MainProgressBar 2000
HWND MainProgressBar=CreateWindowEx(WS_EX_LAYERED,PROGRESS_CLASS,NULL,WS_CHILD|WS_VISIBLE|PBS_SMOOTH,200,200,180,100,hwnd1,(HMENU)ID_MainProgressBar,hInst,NULL);

而且我看不到这个元素。另外一个问题,回调主窗口或者创建主窗口的时候需要在什么地方调用HWND MainProgressBar=CreateWindowEx?

最佳答案

当您使用UpdateLayeredWindow()时,您负责将整个窗口的内容绘制成位图,然后每次将该位图交给UpdateLayeredWindow()窗口内容改变。不用说,当涉及到 child 控制时,这是行不通的。相反,使用 SetLayeredWindowAttributes() 在其他正常窗口上激活 alpha/透明度(这样您就可以正常使用子控件)并根据标准 WM_PAINT< 将 PNG 绘制到窗口上 消息。

关于c++ - 如何在 LayeredWindow 上显示静态控件元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19358712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com