I'd like to create a CWnd based class that will introduce a control with transparent background.
There is no big deal for me to create a control and draw its content with transparent background as long as the content is static.
The problem is when I want to create a control with changing content. It's becaue I don't know how to erase content of control with parent's background (which in general case may not be just a solid color).
So the goal I want to achieve is to erase control before painting its conent as the control was never there (parent, and maybe other controls may appear), and than paint control in this place.
Roel answer is fine if you want to create a top-level window. If you need to crate a child window (which must be the case if you are creating a control) you cannot use WS_EX_LAYERED (I think this has changed from Windows 8 on).
The easy trick is to draw parent as the control backgroud. So in the OnEraseBkgnd you can add this code:
Not sure if afxGlobalData global variable is just for MFC 2008 Feature Pack. If you are using a previous version of MFCs then you can use the code from DrawParentBackground:
You use WS_EX_LAYERED and the UpdateLayeredWindow() API to draw your window. See http://msdn.microsoft.com/en-us/library/ms997507.aspx .
I used below code for my custom Static control: