INFO: Responding to Mouse Events with MFC ActiveX Controls

Last reviewed: February 18, 1998
Article ID: Q165020
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2, 5.0
    
    ---------------------------------------------------------------------

SUMMARY

MFC-based ActiveX controls capture mouse input by calling SetCapture in response to a mouse-button message. This can cause unexpected problems, but the behavior is by design.

MORE INFORMATION

If you need to perform an action in response to a mouse button message when implementing an ActiveX control, and that action involves the use of the mouse (for example, displaying a message box or modal dialog box), you need to perform the action after the call to the base class implementation of the handler. Performing such actions prior to calling the base class may result in mouse capture problems.

REFERENCES

Sample Code

   void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
   {
       // Handle default first so that the mouse capture is resolved.
       COleControl::OnLButtonDown(nFlags, point);

       // Then, add your own hander code afterwards.
       MessageBox(_T("No more problem!"));
   }
Keywords          : MfcOLE
Technology        : kbole kbMfc
Version           : Winnet:4.0,4.1,4.2,5.0
Issue type        : kbinfo


================================================================================


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 18, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.