Click to See Complete Forum and Search --> : Switch focus


joscollin
January 23rd, 2004, 05:01 AM
Hi,

I have a tab dialog with child dialogs in my program.
My problem is that I cannot switch control focus in a child dialog.
When I press tab key to switch focus to next control in a child dialog it goes to a button in the parent dialog.

Myself dot NET
January 23rd, 2004, 07:33 AM
I was working on this same problem earlier today. I found the following method to work, without having to write custom message loop processing for the dialog.

First, the reason the problem is happening is because when you press tab (or shift-tab), the message loop processing for the dialog box calls IsDialogMessage(), which sets keyboard focus on the next (or previous) tab-stop child control. If you have a bunch of child dialogs which themselves have child controls, these child controls will not be included in the navigation handling by default.

To solve this problem, set the WS_EX_CONTROLPARENT extended style on each of the child dialogs. When IsDialogMessage() is called, it will notice this style and switch focus through the child controls on the child dialogs.

If you set the child dialogs' parent window to be the tab control, the tab control must have this style as well. I wouldn't recommend this, for then the tab control itself is not included in the navigation handling (for selecting/switching tabs with the keyboard).

To solve this problem, make the child dialogs' parent window be the main dialog, and give the tab control the WS_TABSTOP and WS_CLIPSIBLINGS styles. This way, users can navigate though the tab control and through each of the child dialogs with the keyboard.

joscollin
January 23rd, 2004, 12:23 PM
The first method works, but the cpu usage becomes 100% when the focus reaches the parent dialog. And for the second method cpu reaches 100% when I press tab button from the child dialog.

Myself dot NET
January 23rd, 2004, 05:34 PM
That's odd. Mine runs at 0-1% CPU usage the entire time. What does your message loop processing look like? Do you call DialogBox() to display your main dialog? Or CreateDialog() and your own loop?

joscollin
January 23rd, 2004, 10:05 PM
Originally posted by Myself dot NET
does your message loop processing look like? Do you call DialogBox() to display your main dialog? Or CreateDialog() and your own loop?

I dont use my own message loop.
I use DialogBox() to display main dialog and CreateDialog() for child dialogs and procs for main dialog and each child dialog.

please reply....

Myself dot NET
January 23rd, 2004, 11:03 PM
Well, I don't know what else might be causing the problem then. Maybe post some of your code or something, otherwise I don't know what else to check.

joscollin
January 24th, 2004, 05:40 AM
Originally posted by Myself dot NET
Well, I don't know what else might be causing the problem then. Maybe post some of your code or something, otherwise I don't know what else to check.

The attached file contains the code.
I think the main dialog is receiving the messages for child dialogs

Myself dot NET
January 25th, 2004, 02:04 AM
From briefly glancing at your code, it looks like you mixed the two things that I mentioned. You give the tab control the WS_CLIPSIBLINGS style (but not the WS_TABSTOP style), but the child dialogs' parent window is not set to the main dialog.

Try changing the line:

hWndSheet = CreateWindow(..., WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, ...);

to:

hWndSheet = CreateWindow(..., WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE, ...);


And change the lines:

hWndPage[...] = CreateDialog(..., hWndSheet, ...);

to:

hWndPage[...] = CreateDialog(..., hWnd, ...);


You will also need to adjust your SetWindowPos() positioning code appropriately. I am assuming, because I cannot see your resource script, that your child dialogs have the WS_EX_CONTROLPARENT extended style set. If they do, then all of this should work. Try, and let me know.

joscollin
January 26th, 2004, 02:40 AM
Hi,
It works. I got confused with your first reply and I was working with resource script , adding window styles.

Now I made changes in the cpp code.
Thank you...