The information in this article applies to:
SUMMARYThis article describes how to ensure default command processing when subclassing the standard Windows Button control to create an MFC ActiveX control. It also discusses how to determine when a control is the default command in both design- and run-time modes so that the control is drawn correctly. Finally, the article addresses how to ensure that the ENTER key gets routed to the current default command. MORE INFORMATIONThe following files are available for download from the Microsoft
Download Center. Click the file names below to download the files: http://www.microsoft.com/downloads/search.aspand then click How to use the Microsoft Download Center. The following sections and the DefButn.exe sample code describe how to:
Make a Subclassed Control That Supports Extended PropertiesTo create a control that supports extended properties so that the container can display its extended Default property in the Property Browser window when the control is selected at design time, do the following:
Set a Control to Be the Default Command at Run TimeTo set the default command at run time in an MFC dialog-based container application that does not support extended properties, add the following call to the OnInitDialog processing:
and pass in the control ID of DefBtn. This will override any other control
that was selected as the default command at design time. You do not need to
make any modifications to the control[ASCII 146]s source code nor to its property
page.
Use the Caption Property to Display the Command TextTo display the command text both at run time and design time, do the following:
Draw Correctly Depending Upon Default Command StatusActiveX controls implement functionality that the older, pre-Ole Windows controls (such as the Button control) do not. Because the MFC method of subclassing a control is a way to support older technology, there tend to be inconsistencies in certain operations (especially drawing) between subclassed controls and those developed without subclassing. For example, the Button control does not draw its border in accordance with Windows 95 user interface guidelines for a default command.You can add logic to a subclassed control so that its border is drawn to reflect the default command status. Look at various CDC member functions such as DrawEdge to do so. Note that the DefButn.exe sample does not include the code to do this. The DefButn.exe sample does include the logic to detect any change in the default command status when overriding the CDefBtnCtrl::OnAmbientPropertyChange member function. To determine when a control has been set as the default command on a form at design time, and to draw correctly depending upon the default command status in both design- and run-time modes, do the following:
Ensure That the ENTER Key Gets Routed to the Current Default CommandThis section describes how to receive the WM_COMMAND message when the ENTER key is pressed, and the default command is a subclassed control. In Microsoft Visual C++ Books Online, "Programming with MFC: Encyclopedia," the article called "Keyboard Interface" contains the following paragraph:
If you want to do special processing within your control when the ENTER key
is pressed and your control is the default command, you must use the
ClassWizard to expose the DoClick custom method. You should send the Click
event back to the container when your control[ASCII 146]s DoClick method has been
called. Use ClassWizard to expose the Click stock event and call the
FireClick() event from within the CDefBtnCtrl::DoClick() member function
to
do this.
If no special processing is needed and you just want to ensure that the Click event gets fired back to the container, then expose the DoClick stock method and the Click stock event. In MFC's default processing, FireClick will be called for you. Additional query words: 4.20
Keywords : kbfile kbole kbsample kbMFC kbVC500 kbVC600 |
Last Reviewed: December 10, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |