Introduction
This article introduces a CExtWndShadow
class, which should enable you to easily draw compound shadows anywhere you want.
The class is partially based on the CExtWndShadow
class presented in the freeware version of the Prof-UIS library available here.
How to use it
The CExtWndShadow
class is simple to use. To add it to your project, please follow the steps below:
- Put its source files (CExtWndShadow.cpp and CExtWndShadow.h) into the proper folder and add their file names to your Visual Studio project.
- Include its header to the appropriate header file. If you plan to use
CExtWndShadow
in more than one place, it's reasonable to add it to the stdafx.h file. #include "CExtWndShadow.h"
Method description
bool Paint(
CDC & dc,
const CRect & rcWndArea,
UINT nShadowSize = DEF_SHADOW_SIZE,
UINT nBr0 = DEF_BRIGHTNESS_MIN,
UINT nBr1 = DEF_BRIGHTNESS_MAX,
bool bEnablePhotos = true
);
Draws the shadow.
Parameters
CDC & dc
Reference to the device context that is used for drawing the shadow.
const CRect & rcWndArea
Reference to the rectangular area in which the shadow is drawn.
UINT nShadowSize
Size of the shadow in pixels, which is the same for the width and height.
UINT nBr0
Minimum brightness of the shadow, which must be in the range 0 to 10.
UINT nBr1
Maximum brightness of the shadow, which must be in the range 0 to 10.
bool bEnablePhotos
If bEnablePhotos
is set to true
, specifies that the shadow algorithm is used at first and then the image is just displayed; otherwise, the shadow algorithm is used every time.
Return Value
Usage
For instance, if you want to draw a shadow for an edit control, use the following code:
CRect rcEdit;
m_Edit.GetWindowRect(&rcEdit);
ScreenToClient(&rcEdit);
rcEdit.InflateRect( 2, 2, 0, 0 );
CExtWndShadow _shadow;
_shadow.Paint(
dcPaint, rcEdit,
5,
CExtWndShadow::DEF_BRIGHTNESS_MIN,
CExtWndShadow::DEF_BRIGHTNESS_MAX,
false
);
Sample
The ShadowsTest sample project shows how to apply the class to some controls.
Reporting bugs
Your questions, suggestions, and bug reports may be posted either to the forum below or to the forum at the Prof-UIS website.