Creating transparent parent window without using LWA_COLORKEY or effecting child windows

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

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

问题

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

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

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

  1. //注册窗口类
  2. WNDCLASSEX wc = {
  3. sizeof(WNDCLASSEX),
  4. CS_CLASSDC | CS_HREDRAW | CS_VREDRAW,
  5. WndProc,
  6. 0L,
  7. 0L,
  8. hInst,
  9. NULL,
  10. NULL, NULL,
  11. NULL,
  12. _T(" "),
  13. NULL
  14. };
  15. RegisterClassExA(&wc);
  16. //创建窗口
  17. wnd = CreateWindowExA( //父窗口
  18. WS_EX_TOPMOST,
  19. wc.lpszClassName,
  20. "",
  21. WS_POPUP | WS_VISIBLE | WS_EX_TRANSPARENT | WS_CLIPCHILDREN,
  22. 0, 0, //位置
  23. sInfo->Width, sInfo->Height, //大小
  24. NULL,
  25. NULL,
  26. hInst,
  27. NULL);
  28. child = CreateWindowA(
  29. wc.lpszClassName,
  30. "",
  31. WS_CHILD | WS_VISIBLE,
  32. 0, 0,
  33. sInfo->Width, sInfo->Height,
  34. wnd,
  35. NULL,
  36. hInst,
  37. 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

  1. //Register Window Class
  2. WNDCLASSEX wc = {
  3. sizeof(WNDCLASSEX),
  4. CS_CLASSDC | CS_HREDRAW | CS_VREDRAW,
  5. WndProc,
  6. 0L,
  7. 0L,
  8. hInst,
  9. NULL,
  10. NULL, NULL,
  11. NULL,
  12. _T(" "),
  13. NULL
  14. };
  15. RegisterClassExA(&wc);
  16. //Create Window
  17. wnd = CreateWindowExA( //parent window
  18. WS_EX_TOPMOST,
  19. wc.lpszClassName,
  20. "",
  21. WS_POPUP | WS_VISIBLE | WS_EX_TRANSPARENT | WS_CLIPCHILDREN,
  22. 0, 0, //Pos
  23. sInfo->Width, sInfo->Height, //Size
  24. NULL,
  25. NULL,
  26. hInst,
  27. NULL);
  28. child = CreateWindowA(
  29. wc.lpszClassName,
  30. "",
  31. WS_CHILD | WS_VISIBLE,
  32. 0, 0,
  33. sInfo->Width, sInfo->Height,
  34. wnd,
  35. NULL,
  36. hInst,
  37. 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:

确定