SAMPLE: DlgTab.exe - Infinite Loop Moving Through Dialog Ctrl

ID: Q92905

The information in this article applies to:

SUMMARY

An application enters an infinite loop when you use the TAB or arrow keys to navigate through dialog box controls. The problem occurs only when the dialog box has another dialog box as a child. When you use the TAB key, the problem occurs only when the child dialog box has the WS_MAXIMIZEBOX or WS_TABSTOPS style.

This article describes the problem in detail together with two possible solutions. DlgTab.exe demonstrates the problem and one of the workarounds.

MORE INFORMATION

DLGTAB is a file in the Microsoft Software Library that demonstrates both the TAB and ARROW key problems.

The following file is available for download from the Microsoft Software Library:

 ~ DlgTab.exe (size: 32946 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from
               Online Services

To get the dialog boxes, from the File menu, choose Dialog Tab. Two dialog boxes will be displayed: one is the Parent dialog box and the other is the Child dialog box.

There are two option buttons in the Parent dialog box: one demonstrates the problem and the other the solution. When the Demo Problem option button is selected, the sample demonstrates the problem. When the Fix Problem option button is selected, the sample demonstrates the workaround. The default button is the workaround for the problem.

SYMPTOMS

Problem 1

When arrow keys are used to maneuver through a dialog box's last control (the last control in the parent dialog box), the focus is passed to the next child (in this case, the child dialog box) and the application goes into an infinite loop.

Problem 2

When the TAB key is used to maneuver through the dialog box's last control, the focus is then passed to the next child (again the child dialog box) and the application goes into an infinite loop.

The infinite loop is clearly visible when spying on the child dialog box window. The child dialog box window continually receives WM_GETDLGCODE messages.

CAUSE

The dialog box manager confuses the child dialog box window with a child control.

When maneuvering through controls in a dialog box, the dialog box manager looks through its children and checks for the next child to pass focus to. In order to do that, the dialog box manager sets the focus to the child control and generates messages to complete the process.

Using the Arrow Keys to Navigate Through Controls

WS_GROUP defines the start of a group within a dialog box. All controls defined between two WS_GROUP styles are members of a group. Arrow keys can then be used to navigate between members of a group.

Normally a dialog box does not have WS_GROUP for a style; therefore, the child dialog box does not have a WS_GROUP but a previous control does have one. Based on the definition of a group, the child dialog box is considered a member of the last group by the dialog box manager. When the arrow key is used on the last control, the dialog box manager checks for the next child control in that group to pass the focus to, in this case the child dialog box window. The dialog box manager then tries to set focus to the window and generates necessary messages to complete the process. These generated messages are meaningful to a control but not to a window. One of these generated messages is WM_GETDLGCODE, which causes the infinite loop.

Using the TAB Key to Navigate Through Controls

WS_TABSTOPS defines which control has a tab stop. When you tab through controls, the dialog box manager looks for the next child that has the WS_TABSTOPS style and changes the focus to that child.

Normally a dialog box does not use WS_TABSTOPS for a style. It is quite normal, however, to use WS_MAXIMIZEBOX for a dialog box style. The child dialog box in this case has WS_MAXIMIZEBOX. The values for WS_TABSTOPS and WS_MAXIMIZEBOX are the same in WINDOWS.H. Because the dialog box manager expects a child control and not another window, the WS_MAXIMIZEBOX is interpreted as WS_TABSTOPS. So, when you tab on the last control of the parent dialog box, the dialog box manager tries to set the focus to the next child with WS_TABSTOPS, in this case the child dialog box. Then the dialog box manager generates the necessary messages to complete the process. These generated messages are meaningful to a control but not to a window. One of these messages is WM_GETDLGCODE, which causes the infinite loop.

RESOLUTION

Workarounds are described in the MORE INFORMATION section below.

MORE INFORMATION

Additional query words: Keywords : kbfile kbsample kb16bitonly kbDlg kbGrpUser kbWinOS310

Last Reviewed: December 26, 1998