Microsoft KB Archive/190530

= FIX: ActiveX Control Events Are Not Fired in ATL Dialog =

Article ID: 190530

Article Last Modified on 12/10/2003

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q190530

<div class="symptoms_section">

SYMPTOMS
When you insert an ActiveX control on an ATL dialog box, and add event handlers for it, the event handler is not called.

<div class="cause_section">

CAUSE
This problem occurs because the sink objects have not been hooked up to the corresponding ActiveX control [IConnectionPoint::Advise has not been called for each control].

<div class="resolution_section">

RESOLUTION
For an ATL dialog box, IConnectionPoint::Advise can be called for each control on the dialog box, with associated event handlers, by calling AtlAdviseSinkMap. Add a message handler for WM_INITDIALOG in the dialog box and call AtlAdviseSinkMap. For example: LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,     BOOL& bHandled) {     // Calls IConnectionPoint::Advise for each control on the dialog // box with sink map entry. AtlAdviseSinkMap(this, TRUE);

return 1; // Let the system set the focus. } Also, make sure IConnectionPoint::Unadvise is called for all controls for which IConnectionPoint::Advise was called. This is done by calling AtlAdviseSinkMap with the value FALSE for last parameter: LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam,     BOOL& bHandled) {     // Calls IConnectionPoint::Unadvise for each control on the dialog // box with sink map entry. AtlAdviseSinkMap(this, FALSE);

return 0; }

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.

<div class="moreinformation_section">

Steps to Reproduce Behavior

 * 1) Create a default ATL AppWizard EXE.
 * 2) Using the ATL Object Wizard (on the Insert menu, click New ATL Object), insert a dialog box from the miscellaneous category.
 * 3) In the dialog box resource inserted by the above step, right-click and select "Insert ActiveX Control"; insert an ActiveX control that has an event interface.
 * 4) Right click the inserted ActiveX control and select Events. In the resulting message/event handler dialog box, add event handlers for the ActiveX control.
 * 5) Create an instance of the dialog box, and display it through a call to DoModal or Create.
 * 6) Build and run the application and cause the ActiveX control to fire the event for which the handler was added in the previous step. Note that the event handler is not called.

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Jaganathan Thangavelu, Microsoft Corporation

Additional query words: kbATL300 kbATL300bug kbATL kbVC600 kbVC600bug

Keywords: kbbug kbfix kbnoupdate kbconnpts kbdlg kbctrl KB190530

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.