The information in this article applies to:
SUMMARYThe Control Development Kit (CDK) provides a set of standard properties that you can use in your custom control. Most of these standard properties do not need any additional code. All you need to do is include these properties in your property list. A few of the standard properties, however, do require some additional work on the part of the developer. For example, to implement the BackColor property, you need to write some additional code. This article shows by example how to do it. MORE INFORMATIONThe CDK documentation states that to support the BackColor property, you must send a WM_CTLCOLOR message to get a brush that contains the background color. (See page 39 of the CDK documentation for more information.) However, the CDK documentation does not specifically describe where you need to put this code or how it should be structured. The Circ3 example implements a functional BackColor property, but the code is not very generic. ExampleThe following sample code demonstrates how to add a generic BackColor property to your custom control. Essentially, you add code to your Control Procedure to monitor the following messages:VBM_SETPROPERTY - so you can determine when the backcolor changes.Process VBM_SETPROPERTY so that you can determine when the BackColor property is set. When the property is set, invalidate the window. You can do this by calling InvalidateRect. Be sure to specify TRUE as the third argument so that the background will be repainted. When a section of the window is invalidated, a WM_PAINT message is posted to the window. In your handling of the WM_PAINT message, you will usually call BeginPaint. BeginPaint will send a WM_ERASEBKGND message to your application if the InvalidateRect call specified that the background needed to be erased. Handle the painting of the background in your WM_ERASEBKGND handler. Send a WM_CTLCOLOR message to the parent window. The parent window will return a handle to a brush of the correct color. Then you can use that brush to paint your window. NOTE: Do not delete the brush. Sample Code - Example Implementation of BackColor PropertyBelow is a code snippet taken from a control procedure that implements the BackColor property:
Sample Code - Example PaintRoutineHere is some code for an example PaintRoutine:
Additional query words: 3.00
Keywords : |
Last Reviewed: August 19, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |