简体   繁体   English

如何创建子窗口透明而父窗口不透明?

[英]How to create a child window is transparent and the parent window is not transparent?

I want to create a window with two child windows.我想创建一个带有两个子窗口的窗口。 Only the background of the top child window is transparent.只有顶部子窗口的背景是透明的。 I can directly see the background of the parent window and not the content of other child windows.Like the picture, A is parent, B is child 1, C is child 2.The background of child 2 is the same as parent.可以直接看到父窗口的背景,看不到其他子窗口的内容。如图,A为父,B为子1,C为子2,子2的背景与父相同。 enter image description here在此处输入图片说明

Aam,啊,

You paint background on child window by yourself.您自己在子窗口上绘制背景。 There is method OnPaint (in MFC) or message WM_PAINT.有方法 OnPaint(在 MFC 中)或消息 WM_PAINT。 And you should draw transparent background (it means to draw nothing).你应该画透明背景(这意味着什么都不画)。 Does it work?它有效吗?

If you use non-standart framework to create windows, you should specify background is painted programmatically.如果您使用非标准框架创建窗口,则应指定以编程方式绘制背景。

A few options to experiment with:一些可供试验的选项:

If in your open source UI framework you can remove the WM_PAINT handler entry in the DefWindowProc then you could do that.如果在您的开源 UI 框架中您可以删除 DefWindowProc 中的 WM_PAINT 处理程序条目,那么您可以这样做。

Handle the WM_PAINT message yourself and do nothing in the handler except clear any flag that indicates that the client area needs to be re-drawn.自己处理 WM_PAINT 消息,并且在处理程序中除了清除任何指示需要重新绘制客户区的标志外什么都不做。 You'll need to find something equivalent to ValidateRect.您需要找到与 ValidateRect 等效的东西。

Both of these methods MIGHT cause non client areas like the window frame to artifact within the client area as you move window C around but I can't be sure.当您移动窗口 C 时,这两种方法都可能导致非客户区域(如窗口框架)在客户区域内出现伪影,但我无法确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM