Creating transparent parent window without using LWA_COLORKEY or effecting child windows

huangapple go评论79阅读模式
英文:

c++ | Creating transparent parent window without using LWA_COLORKEY or effecting child windows

问题

我正在尝试让我的父窗口变成透明,但不影响我的子窗口的透明度。
我尝试使用LWA_ALPHA,但这也改变了子窗口的透明度,这不是我想要的。
LWA_COLORKEY 有效,但我意识到你不能拥有半透明的效果,而且会降低你的帧速率,所以我不想使用这个,因为它不适用于我想要实现的效果。

我还尝试了dwextendmargin,但似乎没有任何作用。

任何帮助都将不胜感激。
这是我的窗口和窗口类的代码:

//注册窗口类
WNDCLASSEX wc = {
	sizeof(WNDCLASSEX),
	CS_CLASSDC | CS_HREDRAW | CS_VREDRAW,
	WndProc,
	0L,
	0L,
	hInst,
	NULL,
	NULL, NULL,
	NULL,
	_T("    "),
	NULL
};

RegisterClassExA(&wc);

//创建窗口

wnd = CreateWindowExA( //父窗口
	WS_EX_TOPMOST,
	wc.lpszClassName,
	"",
	WS_POPUP | WS_VISIBLE | WS_EX_TRANSPARENT | WS_CLIPCHILDREN,
	0, 0, //位置
	sInfo->Width, sInfo->Height, //大小
	NULL,
	NULL,
	hInst,
	NULL);

child = CreateWindowA(
	wc.lpszClassName, 
	"",
	WS_CHILD | WS_VISIBLE, 
	0, 0, 
	sInfo->Width, sInfo->Height, 
	wnd, 
	NULL, 
	hInst, 
	NULL);
英文:

I am trying to have my parent window transparent and my child window not effected by this transparency.
I did use LWA_alpha but that changed the transparency of the child window aswell which I do not want.
LWA_colorkey was working but I realised you cannot have something semi transparent, and it also halfs your fps so i dont want to use this as it doesnt work for what I want to make.

I have also used the dwextendmargin thing but this didnt seem to do anything.

Any help would be appriciated.
Here is the code for my windows and window's class

//Register Window Class
	WNDCLASSEX wc = {
	sizeof(WNDCLASSEX),
	CS_CLASSDC | CS_HREDRAW | CS_VREDRAW,
	WndProc,
	0L,
	0L,
	hInst,
	NULL,
	NULL, NULL,
	NULL,
	_T("    "),
	NULL
	};

	RegisterClassExA(&wc);

	//Create Window

	wnd = CreateWindowExA( //parent window
		WS_EX_TOPMOST,
		wc.lpszClassName,
		"",
		WS_POPUP | WS_VISIBLE | WS_EX_TRANSPARENT | WS_CLIPCHILDREN,
		0, 0, //Pos
		sInfo->Width, sInfo->Height, //Size
		NULL,
		NULL,
		hInst,
		NULL);

child = CreateWindowA(
		wc.lpszClassName, 
		"",
		WS_CHILD | WS_VISIBLE, 
		0, 0, 
		sInfo->Width, sInfo->Height, 
		wnd, 
		NULL, 
		hInst, 
		NULL);

答案1

得分: 0

我最终决定切换到OpenGL,因为这样做会容易得多。

英文:

I ended up just switching to opengl as it was alot easier to do this task.

答案2

得分: -2

使用以下代码:
SetLayeredWindowAttributes(hwnd, RGB(255,0,0), 0, LWA_COLORKEY);

英文:

Use this
SetLayeredWindowAttributes(hwnd, RGB(255,0,0), 0, LWA_COLORKEY);

huangapple
  • 本文由 发表于 2023年2月27日 01:55:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75573962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定