Microsoft KB Archive/186472

= PRB: MFC Subclassed Static Control Does Not Work in VB5 =

Article ID: 186472

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Foundation Class Library 4.2, when used with:
 * Microsoft Visual C++ 5.0 Standard Edition

-



This article was previously published under Q186472



SYMPTOMS
When an MFC control that subclasses a Static Window class is placed on a Visual Basic form, two unexpected behaviors occur:
 * The MFC ActiveX control does not respond to Windows messages, such as WM_LBUTTONDOWN.
 * When you double-click the control while the Visual Basic client is in run-time mode, the control's Property Page dialog box appears.



RESOLUTION
To work around this problem, add a message handler for WM_NCHITTEST:

 Open the Control Workspace (.dsw) file in Developer Studio.  Use the Class wizard to add a message handler for WM_NCHITTEST. Edit the code to return HTCLIENT. Change your code to look like the following: UINT CMySubClCtrl::OnNcHitTest(CPoint point) {       // TODO: Add your message handler code here and/or call default.

//Return COleControl::OnNcHitTest(point); return HTCLIENT; }                    Rebuild the control.



STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Create an ActiveX Control with the MFC ActiveX Control Wizard. Select the STATIC Window class to subclass.  Use the Class wizard to add a message handler for WM_LBUTTONDOWN. Change your code to look like the following: void CMySubClCtrl::OnLButtonDown(UINT nFlags, CPoint point) {       AfxMessageBox("StaticSubclass"); COleControl::OnLButtonDown(nFlags, point); }                   </li> Build this control.</li> Launch Visual Basic and create a new Standard EXE project.</li> Click Components on the Project menu and select the ActiveX Control you just created.</li> Place the ActiveX control on Form1.</li> Run the project.</li> Click the ActiveX control. Notice that no MessageBox appears and that if you double-click the control, the control's property page appears.

NOTE: In step 1, if the EDIT Window class is subclassed instead of the STATIC Window class, the MFC ActiveX control works as expected. The information in this article is specific to the STATIC Window class.</li></ol>

Keywords: kbctrl kbctrlcreate kbinterop kbpending kbprb KB186472

-

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

© Microsoft Corporation. All rights reserved.