Microsoft KB Archive/230587

= PRB: Can't Set Focus to an Edit Control When its Parent Is an Inactive Captioned Child Window =

Article ID: 230587

Article Last Modified on 9/22/2003

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q230587

<div class="symptoms_section">

SYMPTOMS
When an edit control is in an inactive captioned child window, you cannot set focus to it with the mouse. For example, if you have a modeless dialog box with the WS_CAPTION and WS_CHILD styles, and it has an edit control, you cannot set focus to the edit control with the mouse.

NOTE: All captioned child windows display an inactive caption bar.

<div class="cause_section">

CAUSE
The default WM_LBUTTONDOWN handler for edit controls will not set focus to the edit control if its parent is an inactive captioned child window. This code is implemented as part of the Windows API function, DefWindowProc.

<div class="resolution_section">

RESOLUTION
There are not many good ways to work around this limitation because it is Windows itself that is intentionally causing this behavior.

The best way to prevent the problem is to prevent the parent of the edit control from being an inactive captioned child. For the above example, specify the WS_POPUP style for the dialog box instead of WS_CHILD.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Create an AppWizard-generated MFC dialog box application.</li> Add a second dialog box resource to the project. Right-click the dialog resource to change the properties, and give it a Title Bar and a Child window style.</li> <li>Add an edit control to the new dialog box resource.</li> <li>Create a new class for the new dialog box resource. To do this with Visual C++ 6.0, use the class wizard. To do this with Visual C++ .NET, right-click the new dialog box resource, and then click Add Class.</li> <li> Override CDialog::PostNCDestroy for this class and add the following line: delete this; </li> <li>Add a member variable to the application dialog box class that is a type of the class created above, and name the variable m_pDlg.</li> <li> In the OnInitDialog function of the application dialog box class, create a new modeless dialog box as shown here: m_pDlg = new CModelessDlg; m_pDlg->Create(IDD_MODELESS2, this); m_pDlg->ShowWindow(SW_SHOWNORMAL); </li> <li>Try and set focus to the edit control.</li></ol>

Keywords: kbprb kbdlg kbeditctrl kbctrl KB230587

-

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

© Microsoft Corporation. All rights reserved.