问题
While there are lots of variations of the question, there doesn't seem to be a specific answer to a simple case of wanting to use built-in common controls on a transparent window using Win32. I don't want the controls to be transparent, I just want the border around it to be transparent. I can't believe MS didn't update the .dll's to handle transparency when they added it, but I guess they forgot? Is there a specific method that works. A button can get close with WS_EX_TRANSPARENT, but flaky where it works most of the time but at times part of the border shows up. Edit controls, change depending on when get focus or not.
So the question is simply:
Is there a way to make common controls on transparent window so there is no white border around them?
If not, is there a good replacement library that does it via owner draw?
If some, which ones and what is the method?
Seems silly to reinvent the wheel just because of the area around the control.
TIA!!
回答1:
If I am not mistaken, you can take the following steps to achieve this effect.
1.Create a GDI+
Bitmap object with the PixelFormat32bppPARGB
pixel format.
2.Create a Graphics
object to draw in this Bitmap
object.
3.Do all your drawing into this object using GDI+
.
4.Destroy the Graphics
object created in step 2.
5.Call the GetHBITMAP
method on the Bitmap object to get a Windows HBITMAP
.
6.Destroy the Bitmap
object.
7.Create a memory DC using CreateCompatibleDC
and select the HBITMAP
from step 5 into it.
8.Call UpdateLayeredWindow
using the memory DC as a source.
9.Select previous bitmap and delete the memory DC.
10.Destroy the HBITMAP
created in step 5.
This method should allow you to control the alpha channel of everything that is drawn: transparent for the background, opaque for the button.
A similar discussion: Transparent window containing opaque text and buttons
来源:https://stackoverflow.com/questions/56469342/common-controls-on-a-transparent-window