SAMPLE: DropShad.exe Draws Custom Border Around Control Window

ID: Q66992

The information in this article applies to:

SUMMARY

DropShad.exe demonstrates how to create an edit control with a "drop shadow." The parent window of the edit control draws the drop shadow on the control's behalf.

Microsoft Windows is not designed to allow a control to draw its own custom border. If an application subclasses the control and draws a border during the processing of the WM_PAINT message, the control will not be clipped properly because the control does not determine the clipping when it draws outside its client area.

The proper approach is to have the parent of the control draw the border during the processing of a WM_PAINT message. In this case, Windows will perform the appropriate clipping automatically.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ DropShad.exe (size: 21448 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from
               Online Services

The following three steps draw the drop shadow:

1. During the processing of the parent window's WM_CREATE message, the

   parent creates the edit control and sets a static variable to the
   edit control's HWND (which will be needed to draw the shadow).

2. The parent windows draws the drop shadow during the processing of a
   WM_PAINT message. The parent window uses GetWindowRect() to
   determine the rectangle of the edit control in screen coordinates.
   The ScreenToClient() function converts this data to local
   coordinates, then OffsetRect() offsets the rectangle to determine
   the bounds of the shadow. (The code for this step would go very
   nicely into a DrawShadow() procedure if the application had more
   than one edit control to shadow.)

3. The parent window calls Rectangle() to draw the two rectangles that
   create the drop shadow.

The width of the drop shadow, how far the drop shadow is offset from the corners of the edit control, and the color of the brush used to paint the drop shadow can be varied to achieve a particular control appearance.

Additional query words: Keywords : kbfile kbsample kb16bitonly kbCtrl kbGrpUser kbWinOS310 kbWndw kbWinOS300

Last Reviewed: December 12, 1998