SAMPLE: Drawing a Custom Border Around a Control Window

Last reviewed: February 15, 1996
Article ID: Q66992
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

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.

There is a sample application in the Microsoft Software Library called DROPSHAD that demonstrates this technique. This program shows 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.

Download DROPSHAD.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download DROPSHAD.EXE (size: 21448 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get DROPSHAD.EXE (size: 21448 bytes) 
    

MORE INFORMATION

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 reference words: 3.00 3.10 softlib DROPSHAD.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrCtl


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.