You are currently offline, waiting for your internet to reconnect

PRB: Child CPropertySheet Hangs If Focus Is Switched

This article was previously published under Q149501
This article has been archived. It is offered "as is" and will no longer be updated.
SYMPTOMS
If a modeless CPropertySheet is a child of a CDialog or anotherCPropertySheet, the program will hang in the following situations:

  • The focus is switched back to a PropertyPage that previously had the focus.
  • The focus is placed on a control on a PropertyPage, and then the focus is switched to another window (for example, Program Manager).
  • The focus is on a control on a PropertyPage and the PropertySheet is closed.
The program hangs because the child CPropertySheet continuously receives aWM_GETDLGCODE message.
CAUSE
By default, CPropertyPages have a WS_EX_CONTROLPARENT style. However,CPropertySheets do not have this style. This style allows a user to pressthe TAB key to move from a control inside the page to one in the sheet.

When the focus is switched from the CPropertyPage, code that handlesdefault command buttons loops through all the controls in the pages and thesheet. Cycling through controls is done using GetNextDlgTabItem(). The loopcycles through controls in the page in the child CPropertySheet and findsits way to controls in the parent page or parent dialog. At this point,GetNextDlgTabItem() is not able to find controls inside the childCPropertySheet because it doesn't have a WS_EX_CONTROLPARENT style. Theloop never ends because it never finds the original control that had thefocus.
RESOLUTION
Override OnInitDialog() for the child CPropertySheet, and add theWS_EX_CONTROLPARENT style.
STATUS
This is a problem with the implementation of the Property Sheet commoncontrol, and not MFC's CPropertySheet wrapper.
MORE INFORMATION

Sample Code

   // CMySheet is derived from CPropertySheet   BOOL CMySheet::OnInitDialog()   {             ModifyStyleEx (0, WS_EX_CONTROLPARENT);             return CPropertySheet::OnInitDialog();   }   /* Compile options needed: default   */ 				
WS_CHILD Property Sheet lock freeze page modal
Properties

Article ID: 149501 - Last Review: 12/04/2015 14:30:11 - Revision: 2.1

Microsoft Foundation Class Library 4.2, Microsoft Visual C++ 4.0 Standard Edition

  • kbnosurvey kbarchive kbprb kbpropsheet kbuidesign KB149501
Feedback