INFO: Responding to Mouse Events with MFC ActiveX Controls (165020)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++, 32-bit Editions 4.0
    • Microsoft Visual C++, 32-bit Editions 4.1
    • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
    • Microsoft Visual C++, 32-bit Professional Edition 4.2
    • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
    • Microsoft Visual C++, 32-bit Professional Edition 5.0
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q165020

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!"));
   }
				

Modification Type:MajorLast Reviewed:12/10/2003
Keywords:kbCtrl kbinfo KB165020