The information in this article applies to:
SUMMARYThe following is copied from the Visual C++ online documentation regarding the usage of the ON_EVENT_RANGE macro: PfnHandler Pointer to a member function that handles the event. This function should have a BOOL return type, a first parameter of type UINT (for the control ID), and additional parameter types that match the event's parameters (see vtsParams). The function should return TRUE to indicate the event was handled; otherwise FALSE.According to this specification, the pfnHandler should have at least one parameter. In addition, the first parameter must be a UINT data type for the control ID. Therefore, the first VTS_ constant for vtsParams must be VTS_I4 (UINT data type). If pfnHandler has some additional parameters besides the UINT of the control ID, then each VTS_ constant for vtsParams after VTS_I4 must match the data types of these additional parameters of pfnHandler. To better illustrate the usage of the ON_EVENT_RANGE macro, a simple sample is shown below. MORE INFORMATIONThe sample code below illustrates the use of the ON_EVENT_RANGE() macro in an MFC dialog-based application. CTestDlg is a CDialog-derived class. In the sample code below, TestOnProblem is the pfnHandler and it has two parameters: a control ID of type UINT and an additional parameter of type short. Thus, vtsParams should be:
VTS_I4 and VTS_I2 match the data type of the first and second parameters of
TestOnProblem(), respectively.For instance, the function prototype for pfnHandler is below:
Then, the event map should look similar to the following:
It is important to note that ON_EVENT_RANGE must be added outside of
ClassWizard's comment ("//") lines. Otherwise, ClassWizard will give you an
error message box whenever you open the dialog box resource template. This
is because ClassWizard doesn't recognize the syntax of the ON_EVENT_RANGE
macro.Also, make sure the controls whose events are being handled have IDs within the contiguous range of IDs listed in ON_EVENT_RANGE. Check the Ids by clicking View on the Resource Symbols toolbar in Visual C++ 5.0. Note that the IDs of the controls may be different than expected, depending on the order in which they were created on the dialog box template. Although one can't create an ON_EVENT_RANGE handler using ClassWizard, it is possible to create an ON_EVENT handler using ClassWizard. Please be aware that in creating an ON_EVENT handler using ClassWizard, the return type of the handler created may be void. This is a bug in ClassWizard. The documentation for both ON_EVENT and ON_EVENT_RANGE is still correct when it says "This function should have a BOOL return type." Returning void usually works correctly, however, so this is not a big problem. (c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Yeong- Kah Tam, Microsoft Corporation. Additional query words: event sink ocx map
Keywords : kbole kbMFC kbVC kbVC500 kbVC600 |
Last Reviewed: July 26, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |