在非透明父窗口(win32)顶部创建透明子窗口 [英] Creating a Transparent Child window on top of non-transparent Parent Window (win32)

查看:69
本文介绍了在非透明父窗口(win32)顶部创建透明子窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不是我编写的程序.我没有消息来源,该程序的开发人员正在独立开发.他给了我该程序的 HWND HINSTANCE 句柄.

I have a program which is not written by me. I dont have its source and the developer of that program is developing independently. He gives me the HWND and HINSTANCE handles of that program.

我已经使用 win32 API在他的窗口上创建了一个子窗口.

I have created a child window ON his window, using win32 api.

我需要做的第一件事是使此子窗口在某些区域具有透明性,而在其他区域具有不透明性(例如游戏的抬头显示器(HUD)),以便用户可以在两个窗口中看到事物.

First thing I need is to make this child window have transparency on some area and opaque on other area(like a Heads up display(HUD) for a game), so that the user may see things in both windows.

第二件事是将所有输入定向到父窗口.我的子窗口不需要输入.

The second thing that I need is to direct all the input to the parent window. My child window needs no input.

我知道 WS_EX_TRANSPARENT 只能像绘画算法中那样使孩子画在最后.

I know that WS_EX_TRANSPARENT only makes the child draw at the end like in painters algorithm.

我不能使用 WS_EX_LAYERED ,因为它是一个子窗口.

I cant use WS_EX_LAYERED because its a child window.

p.s.

尽管互联网上存在类似的问题,但我无所不在,但找不到任何解决方案.

I have looked everywhere but didn't find any solution though there were similar questions around the internet.

实际上,这是该游戏的HUD之类的事情.由于多线程的复杂性以及其他许多原因,我无法直接在父窗口上绘制.

Actually this is a HUD like thing for that game. I can't draw directly on parent window because of the complexity with multi-threads any many other reasons.

-编辑---------------------------

-- EDIT ---------------------------

我仍在努力.我对大家的建议都尝试了不同的方式.有没有一种方法可以将 directX SetWindowRgn()函数或 directx BitBlt()函数结合在一起?我认为这可以解决问题.目前,我正在将所有内容作为子窗口和分层窗口进行测试.

I am still working on it. I am trying different ways with what you all suggested. Is there a way to combine directX and SetWindowRgn() function or directx with BitBlt() function? I think that will do the trick. Currently I am testing all the stuff as a child window and a Layered window.

推荐答案

好的朋友们,最后我做了一些疯狂的事情来实现它.但它效率不高,就像直接使用DirectX进行绘制一样.

OK friends, finally I did some crazy things to make it happen. but its not very efficient, like using DirectX directly for drawing.

我的病:

  • CreateWindowEx
  • 上使用(WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_ TOOLWINDOW)()
  • 创建窗口后,从窗口样式中删除(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE),并且还从窗口样式中删除了(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EXcodes>
  • 这给了我一个没有边界的窗口,它现在也显示在任务栏中.命中测试也将传递到我窗口后面的所有内容.
  • 子类化另一个窗口的窗口过程,并获得
    • WM_CLOSE WM_DESTROY ,分别将 WM_CLOSE WM_DESTROY 发送到我的窗口
    • WM_SIZE WM_MOVE ,以根据另一个窗口调整大小并移动我的窗口
    • WM_LBUTTONUP WM_RBUTTONUP WM_MBUTTONUP ,以使我的窗口显示在顶部,并且仍将焦点放在另一个窗口上,以便我的窗口没有隐藏在另一个窗口的后面
    • Used (WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_ TOOLWINDOW) and () on CreateWindowEx
    • After creating the window, removed (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE) from window styles, and also removed (WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_APPWINDOW) from extended window styles.
    • This gives me a window with no borders and its also now shown in the taskbar. also the hittest is passed to whatever that is behind my window.
    • Subclassed the window procedure of the other window and got the
      • WM_CLOSE,WM_DESTROY, to send the WM_CLOSE or WM_DESTROY respectively to my window
      • WM_SIZE,WM_MOVE, to resize and move my window according to the other window
      • WM_LBUTTONUP,WM_RBUTTONUP,WM_MBUTTONUP, to make my window brought to the top, and still keep focus on the other window, so that my window doesn't get hidden behind the other window
      • 在第一遍中,它将所有黑色元素绘制在白色背景之上,然后将后缓冲数据复制到另一个表面(这样就得到了黑白图像的二进制图像).
      • 在第二遍中,它正常绘制东西.

      这是完美的工作,唯一的事情是使事情变得不透明不是很好.

      This is working perfectly, the only thing is it's not very good at making things transparent.

      另一个问题是为绘制的对象提供alpha混合.

      And the other issue is giving alpha blending to the drawn objects.

      但是您可以使用 SetLayeredWindowAttributes()函数轻松设置总的alpha(透明度).

      But you can easily set the total alpha (transparency) using the SetLayeredWindowAttributes() function.

      感谢你们提供的所有帮助,你们告诉我的所有东西都被使用了,他们指导了我,正如您所看到的.:)

      Thanks for all the help you guys gave, all the things you guys told me was used and they guided me, as you can see. :)

      可悲的是,由于效率问题,我们决定不使用此方法:(

      The sad thing is we decided not to use this method because of efficiency problems :(

      但是我学到了很多东西,这真是很棒的经历.这对我来说很重要:)

      But I learned a lot of things, and it was an awesome experience. And that's all that matters to me :)

      谢谢:)

      这篇关于在非透明父窗口(win32)顶部创建透明子窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆