Transparent window containing opaque text and buttons

I am creating a non-intrusive popup to notify the user when a time consuming operation is being processed. At the moment, I am setting transparency by calling SetLayeredWindowAttributes

, which gives me a reasonable result:

alt text http://img6.imageshack.us/img6/3144/transparentn.jpg

However, I want the text and close button to appear opaque (this doesn't look quite right with white text) while keeping the background transparent - is there a way to do this?

+2


source to share


3 answers


To make the "correct" alpha in a layered window, you need to give the window manager a bitmap with a PARGB call UpdateLayeredWindow

.

The cleanest way to achieve this that I know of is the following:

  • Create a GDI + object Bitmap

    with format PixelFormat32bppPARGB

    .
  • Create an object Graphics

    to draw this object Bitmap

    .
  • Make all your drawings on this object using GDI +.
  • Destroy the object Graphics

    created in step 2.
  • Call the GetHBITMAP

    object's method Bitmap

    to get Windows HBITMAP

    .
  • Destroy the object Bitmap

    .
  • Create a DC memory using CreateCompatibleDC

    and select HBITMAP

    from step 5 into it.
  • Call UpdateLayeredWindow using the DC as source.
  • Select the previous raster map and delete the DC memory.
  • Destroy the ones HBITMAP

    created in step 5.


This method should allow you to control the alpha channel of whatever is drawn: transparent for the background, opaque for the text and buttons.

Also, since you are going to display text, I recommend that you call SystemParametersInfo

to get the default anti-aliasing setting ( SPI_GETFONTSMOOTHING

), and then SetTextRenderingHint

on the Graphics object, set the anti-aliasing type to the same type as configured by the user for a smoother viewing experience.

+10


source


I suspect you will want two top-level windows, not one, one with an alpha blend and the other above the first with opaque text and a button, but with a transparent background. To accomplish this with a single window, you will need to use the UpdateLayeredWindow API , but using this will result in your buttons not being redrawn when they interact with (focus, focus, etc.).



It is possible that if this application is only for Vista, there is a new API call that you can use, but I don't think it is available in XP or earlier.

+3


source


I can't say for sure if you need to try it, but since this is all a window, you can try setting multi-level attributes for your button to make it opaque.

As for the text, you can place it in your own frame with the background and foreground color set, and change its layered attributes to make the background color transparent ...

But since these are child windows and not a top-level window, I really don't know this will work.

0


source







All Articles