SAMPLE: Infinite Loop When Moving Through Dialog Box ControlLast reviewed: February 15, 1996Article ID: Q92905 |
The information in this article applies to:
SUMMARYAn 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. A sample is also provided that demonstrates the problem and one of the workarounds.
SYMPTOMS
Problem 1When 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 2When 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.
CAUSEThe 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 ControlsWS_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 ControlsWS_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.
RESOLUTIONWorkarounds are described in the MORE INFORMATION section below.
MORE INFORMATION
Download DLGTAB.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
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.
|
Additional reference words: 3.10 softlib DLGTAB.EXE
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |