Introduction
The glass style window in VISITA is very beautiful, what I am doing now is to bring them to WINNT5.0 + (Win2K/XP/2K3)
Background
Since WinNT5.0, M$ added two new APIs for providing semi-transparent window.
The SetLayeredWindowAttributes function can set the alpha value for an entire window.
The UpdateLayeredWindow function updates the position, size, shape, content, and translucency of a layered window.
However, when I choose the UpdateLayeredWindow, I found that there are many problems.
1. No WM_PAINT message I can get. Usually, many people use WM_TIMER to redraw their layered window, that is a bad thing I hate. Since it changed the way we are always going, and the result is not good.
2. The common controls on the layered window should be drawn by youself. It also changed the way we are always going. what I want is: just place some controls on the layered window, I do not want to write any more code to display them.
So I need a way to ride all of these ones.
How to use
#include "./ui/TransparentDialogBase.h"
using namespace UI;
class CMySampleDlg : public CTransparentDialogBase
CMySampleDlg::CMySampleDlg(CWnd* pParent )
: CTransparentDialogBase( _T("bg.png"), CMySampleDlg::IDD, pParent)
{
}
The dialog need be derived from the class CTransparentDialogBase, and the first parameter in the constructor is the PNG file name.
Then just change the layout of the dialog as what you want.
How it works
When the MySampleDlg created, we use SetLayeredWindowAttribute to make this window almost transparent.( The dialog is almost disappeared but we can still get the messages for the window, the alpha value I choose is 5)
Then it creates another window with WS_EX_LAYERED | WS_EX_TRANSPARENT options. This new window has the same size / position with the original one.
When the MySampleDlg get WM_PAINT message, it draw the fake window with UpdateLayeredWindow.
Also, for each child control on the MySampleDlg, we use WM_PRINT message to retrive its content.
History
2007-05-09 created