0

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!!

user3161924
  • 1,849
  • 18
  • 33
  • Basically the controls aren't designed for this, the border is designed to blend into the background and with a transparent background you'll see it. – Jonathan Potter Jun 06 '19 at 00:17
  • Hi, user3161924 Can you provide an example about the issue,such as code and screenshot. – Strive Sun Jun 12 '19 at 01:36
  • And what version of your windows? – Strive Sun Jun 12 '19 at 01:38
  • Vista or later only needs to be supported. Think for example adding to the MS Win7 SDK Sample for a DeskBand. – user3161924 Jun 12 '19 at 03:32
  • @user3161924 hi, I want to say that WS_EX_TRANSPARENT does not make a window transparent. It tells Windows that if a Windows is below another Window, it doesn’t need to paint its background since it is covered. The translucent window can be done by layering Windows and setting the opacity.As I pointed out in the answer – Strive Sun Jun 18 '19 at 06:43
  • ok, but the method requires owner draw. I don't need the button itself to have any transparency, just that it sitting on a transparent window works (without the white border it creates). I guess I'll need to do owner-draw, so I'll probably just create a graphic icon and just draw it. Presume the transparency in the icon will work for rounded corners. – user3161924 Jun 18 '19 at 18:02
  • Yes, according to your idea, you need transparent windows and opaque buttons, including icon on the button, which all require owner draw.All need to be done by controlling alpha color channels.Because the control button is created based on the parent window handle, it inherits the transparency of the parent window. – Strive Sun Jun 19 '19 at 03:14
  • ok, i don't need my icon to be transparent, i may just draw `RoundRect` and then `DrawState` the icon on it? Is there a code sample available of your method rather than pseudocode? – user3161924 Jun 19 '19 at 03:38
  • I've seen your latest post, and I see what you mean. Repainting the background of the button control removes what you call the white border. – Strive Sun Jun 19 '19 at 07:01
  • okay, how do I force a repaint of only the background so the control doesn't repaint over it again? – user3161924 Jun 19 '19 at 15:55
  • This is another question, I suggest you create a new post to ask. – Strive Sun Jun 20 '19 at 06:34
  • Okay, new question created [url](https://stackoverflow.com/questions/56694648/how-do-i-force-a-repaint-of-only-the-background-so-a-control-doesnt-repaint-ove) – user3161924 Jun 20 '19 at 22:30

1 Answers1

0

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

Strive Sun
  • 5,988
  • 1
  • 9
  • 26