Having a hard time putting a skin on a WTL Dialog, or want to create transparent dialogs?
From here on you'll have to write three odd lines of code! You can create dialogs
with the same shape of the supplied bitmap with a transparency feature.
Earlier, if you wanted to skin a dialog you had to handle
WM_ERASEBKGND message and then write the paint routine by yourself.
CDialogRegionT template takes all of the burden from the
programmer and does everything by itself. There are a couple of more
messages which are taken care by this template class. These are
WM_NCHITTEST message in our case allows us to drag the dialog by
clicking anywhere on the dialog; this is done by returning
HTCAPTION in this routine.
LRESULT OnNCHitTest(UINT , WPARAM , LPARAM ,
bHandled = m_bIsRgnSet;
Using the code
I attempted to make the code usage as simple as possible. After
including the DialogRegion.h in your WTL dialog class you just have to follow
these three steps:
- Inherit the WTL dialog from
CDialogRegionT template class.
class CMainDlg : public CDialogImpl<CMainDlg>, public CUpdateUI<CMainDlg>,
public CMessageFilter, public CIdleHandler, CDialogRegionT<CMainDlg>
- In the message map add CHAIN_MSG_MAP entry to chain messages to this class
SetBkBitmap method in the
routine to specify the skin file. SetBkBitmap is an overloaded function and takes
the color which is to be set as transparent (
default transparent color)
Things to note
In the background section I did not discuss the
WM_CTLCOLORSTATIC message. The
template class uses this message to return the color for the static controls. In
our case we will be using any color bitmap so the static controls needs to be
drawn as transparent. So when the static controls are to be colored we set the
background color as transparent and return hollow brush.
LRESULT OnCtlColorStatic(UINT , WPARAM wParam, LPARAM lParam,
bHandled = m_bIsRgnSet;
return (LRESULT) GetStockObject (HOLLOW_BRUSH);
I came across one problem: if I add the manifest for common controls 6, the
static controls are drawn black. So you have to ensure that you are not using
the common controls 6 in your project. You can choose not to add common
controls manifest when you are creating the project using the WTL project
wizard. If you already have a WTL project and upon adding
CDialogRegionT class make the static controls to be drawn black,
you can remove the common controls manifest from the .rc file.