Tab order with a tab control

Tab order with a tab control

Post by Christopher Smit » Tue, 04 Jan 2000 04:00:00



Hello,

I have been having problems getting the TAB key to work correctly with
my dialog box.  The dialog box contains a tab control.  The tab control
creates a child dialog box for each tab.  The tab key works correctly
for the main dialog box controls.  And if I click on a control on one of
the child dialog boxes, that works correctly.  However, I can't use the
TAB key to move between the two dialog boxes.  I'm not using MFC so
please don't provide any answers involving that.  It will just confuse
me more.

By the way, I have the DS_CONTROL and WS_CHILD styles set for the child
dialog boxes.

Thanks in advance.

--
__________________________________________________
Christopher Smith          (Direct) (408) 737-6160
Technical Staff              (Main) (408) 738-5390
EOO, Inc.                     (Fax) (408) 738-5399


 
 
 

Tab order with a tab control

Post by Chris Beck » Wed, 05 Jan 2000 04:00:00



> Hello,

> I have been having problems getting the TAB key to work correctly with
> my dialog box.  The dialog box contains a tab control.  The tab control
> creates a child dialog box for each tab.  The tab key works correctly
> for the main dialog box controls.  And if I click on a control on one of
> the child dialog boxes, that works correctly.  However, I can't use the
> TAB key to move between the two dialog boxes.  I'm not using MFC so
> please don't provide any answers involving that.  It will just confuse
> me more.

> By the way, I have the DS_CONTROL and WS_CHILD styles set for the child
> dialog boxes.

The processing the tab keys is done via the IsDialogMessage filter proc in
the dialogs message loop. If the dialog is modeless you must call it
yourself, if modal, its done for you.

Note that IsDialogMessage takes a handle to the dialog to process the
message for.

Now, IsDialogMessage will only handle a TAB keystroke is one of the controls
on a dialog currently has focus.

So, IsDialogMessage() takes the passed in hwnd, and calls GetWindow() in a
loop first with GW_CHILE and then GW_NEXT to enumerate each child window. If
it hits any child window with the DS_CONTROL style, it will recurse, and
chack all the child controls on that window.

So, some questions:

1. Is the dialog box modeless? If so, are you calling IsDialogMessage() in
your message loop, passing the handle of the dialog box?

2. What are you using as the parent of the dialog page - the TAB control, or
the dialog itself? If you are using the TAB control be aware that there is
now a seperation between the main dialog and your page - the tab control
will have to have DS_CONTROL set so that IsDialogMessage can recurse through
the control to find your dialog page. Better is to simply use the main
dialog as your pages parent.

Chris [MVP]
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://users.lia.net/chris/win32

> Thanks in advance.

> --
> __________________________________________________
> Christopher Smith          (Direct) (408) 737-6160
> Technical Staff              (Main) (408) 738-5390
> EOO, Inc.                     (Fax) (408) 738-5399




 
 
 

Tab order with a tab control

Post by Christopher Smit » Wed, 05 Jan 2000 04:00:00


Thank you.  That was one of the best responses I have ever received from a
question.  I really appreciate the effort.  I was able to fix the problem.
Basically, the tab control was the parent for the child dialog boxes.  I just
changed the parent to be the parent dialog box that contains the tab control.

By the way, I did have the IsDialogMessage call in my message loop already.  I
am using a modeless dialog box inside my main app window.



> > Hello,

> > I have been having problems getting the TAB key to work correctly with
> > my dialog box.  The dialog box contains a tab control.  The tab control
> > creates a child dialog box for each tab.  The tab key works correctly
> > for the main dialog box controls.  And if I click on a control on one of
> > the child dialog boxes, that works correctly.  However, I can't use the
> > TAB key to move between the two dialog boxes.  I'm not using MFC so
> > please don't provide any answers involving that.  It will just confuse
> > me more.

> > By the way, I have the DS_CONTROL and WS_CHILD styles set for the child
> > dialog boxes.

> The processing the tab keys is done via the IsDialogMessage filter proc in
> the dialogs message loop. If the dialog is modeless you must call it
> yourself, if modal, its done for you.

> Note that IsDialogMessage takes a handle to the dialog to process the
> message for.

> Now, IsDialogMessage will only handle a TAB keystroke is one of the controls
> on a dialog currently has focus.

> So, IsDialogMessage() takes the passed in hwnd, and calls GetWindow() in a
> loop first with GW_CHILE and then GW_NEXT to enumerate each child window. If
> it hits any child window with the DS_CONTROL style, it will recurse, and
> chack all the child controls on that window.

> So, some questions:

> 1. Is the dialog box modeless? If so, are you calling IsDialogMessage() in
> your message loop, passing the handle of the dialog box?

> 2. What are you using as the parent of the dialog page - the TAB control, or
> the dialog itself? If you are using the TAB control be aware that there is
> now a seperation between the main dialog and your page - the tab control
> will have to have DS_CONTROL set so that IsDialogMessage can recurse through
> the control to find your dialog page. Better is to simply use the main
> dialog as your pages parent.

> Chris [MVP]
> --
> VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
> My Win32 Page: http://users.lia.net/chris/win32

> > Thanks in advance.

> > --
> > __________________________________________________
> > Christopher Smith          (Direct) (408) 737-6160
> > Technical Staff              (Main) (408) 738-5390
> > EOO, Inc.                     (Fax) (408) 738-5399



--
__________________________________________________
Christopher Smith          (Direct) (408) 737-6160
Technical Staff              (Main) (408) 738-5390
EOO, Inc.                     (Fax) (408) 738-5399


 
 
 

Tab order with a tab control

Post by Christopher Smit » Wed, 05 Jan 2000 04:00:00


I do have another question about the tab control.  Right now I have made a
few changes and the tab control is the only control within my modeless
dialog box.  The dialog box is a child of my main app window.  Anyway, when
the app starts, I'd like to give the first tab the focus.  Right now,
nothing has the focus, and I have to click something in order to start
TABBING around.

I tried to use TabCtrl_SetCurFocus, but it wasn't working.  What I think
maybe happening is somewhere the focus is being changed after I do the
TabCtrl_SetCurFocus call.  I don't know what has the current focus when the
app starts up.  I'm guessing either the main window or the dialog box.

Thanks again in advance.


> Hello,

> I have been having problems getting the TAB key to work correctly with
> my dialog box.  The dialog box contains a tab control.  The tab control
> creates a child dialog box for each tab.  The tab key works correctly
> for the main dialog box controls.  And if I click on a control on one of
> the child dialog boxes, that works correctly.  However, I can't use the
> TAB key to move between the two dialog boxes.  I'm not using MFC so
> please don't provide any answers involving that.  It will just confuse
> me more.

> By the way, I have the DS_CONTROL and WS_CHILD styles set for the child
> dialog boxes.

> Thanks in advance.

> --
> __________________________________________________
> Christopher Smith          (Direct) (408) 737-6160
> Technical Staff              (Main) (408) 738-5390
> EOO, Inc.                     (Fax) (408) 738-5399



--
__________________________________________________
Christopher Smith          (Direct) (408) 737-6160
Technical Staff              (Main) (408) 738-5390
EOO, Inc.                     (Fax) (408) 738-5399


 
 
 

Tab order with a tab control

Post by Chris Beck » Thu, 06 Jan 2000 04:00:00



> I do have another question about the tab control.  Right now I have made a
> few changes and the tab control is the only control within my modeless
> dialog box.  The dialog box is a child of my main app window.  Anyway,
when
> the app starts, I'd like to give the first tab the focus.  Right now,
> nothing has the focus, and I have to click something in order to start
> TABBING around.

1. The tab control has been given WS_TABSTOP?

2. What are you returning from WM_INITDIALOG? (that is where you are
attempting to set the focus right?) A TRUE return indicates you want the
system to set the initial focus, FALSE means you did it yourself. return
FALSE.

Quote:> I tried to use TabCtrl_SetCurFocus, but it wasn't working.  What I think
> maybe happening is somewhere the focus is being changed after I do the
> TabCtrl_SetCurFocus call.  I don't know what has the current focus when
the
> app starts up.  I'm guessing either the main window or the dialog box.

The dialog box *should* give focus to the topmost item in the initial
z-order that has the WS_TABSTOP style.

I remember long ago the focus behaving in bad ways if you hide a control
that currently has focus. focus can be lost entirely, and only recovered by
explicitly giving focus to a control via a mouse click.

Chris.
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://users.lia.net/chris/win32

 
 
 

Tab order with a tab control

Post by Christopher Smit » Thu, 06 Jan 2000 04:00:00


Quote:

> 1. The tab control has been given WS_TABSTOP?

Yes, it has the WS_TABSTOP set

Quote:

> 2. What are you returning from WM_INITDIALOG? (that is where you are
> attempting to set the focus right?) A TRUE return indicates you want the
> system to set the initial focus, FALSE means you did it yourself. return
> FALSE.

I was already returning FALSE in INITDIALOG

Quote:

> The dialog box *should* give focus to the topmost item in the initial
> z-order that has the WS_TABSTOP style.

> I remember long ago the focus behaving in bad ways if you hide a control
> that currently has focus. focus can be lost entirely, and only recovered by
> explicitly giving focus to a control via a mouse click.

This sounds like what is happening.  I don't think I'm hiding a control though.

I did finally get it to work by calling SetFocus(hTabs) in my INITDIALOG
handler.  That seems to have done the trick.  But I don't know why it wouldn't
default to that.  It was set as the first control in the dialog box.  I'd
appreciate any more info you can provide.

Thanks again for the continued help.
--
__________________________________________________
Christopher Smith          (Direct) (408) 737-6160
Technical Staff              (Main) (408) 738-5390
EOO, Inc.                     (Fax) (408) 738-5399


 
 
 

Tab order with a tab control

Post by Chris Beck » Fri, 07 Jan 2000 04:00:00


"Christopher Smith"

Quote:> I was already returning FALSE in INITDIALOG

exactly.

If you return FALSE from WM_INITDIALOG you *have* to call SetFocus
yourself - as you mention below.

If on the otherhand you returned TRUE from WM_INITDIALOG - the system would
have set the focus for you.

Quote:> I did finally get it to work by calling SetFocus(hTabs) in my INITDIALOG
> handler.  That seems to have done the trick.  But I don't know why it
wouldn't
> default to that.  It was set as the first control in the dialog box.  I'd
> appreciate any more info you can provide.

Chris.
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://users.lia.net/chris/win32
 
 
 

Tab order with a tab control

Post by Christopher Smit » Fri, 07 Jan 2000 04:00:00


You, my friend, are a genius.  I lost the SetFocus and set the return to TRUE
and it works.  Thanks again.


> "Christopher Smith"
> > I was already returning FALSE in INITDIALOG

> exactly.

> If you return FALSE from WM_INITDIALOG you *have* to call SetFocus
> yourself - as you mention below.

> If on the otherhand you returned TRUE from WM_INITDIALOG - the system would
> have set the focus for you.

> > I did finally get it to work by calling SetFocus(hTabs) in my INITDIALOG
> > handler.  That seems to have done the trick.  But I don't know why it
> wouldn't
> > default to that.  It was set as the first control in the dialog box.  I'd
> > appreciate any more info you can provide.

> Chris.
> --
> VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
> My Win32 Page: http://users.lia.net/chris/win32

--
__________________________________________________
Christopher Smith          (Direct) (408) 737-6160
Technical Staff              (Main) (408) 738-5390
EOO, Inc.                     (Fax) (408) 738-5399


 
 
 

1. How to control the tab order in dialog with a tab control?

I have a dialog which has a tab control and several other controls -- some
buttons and edit boxes.  A couple of the edit boxes are above the tab
control and a couple are below it.  The problem I have is with the tabbing
order.  When you tab through the controls in the dialog, the focus first
goes through the other controls in the dialog (the ones above and below
the tab control) and then the controls inside the tab control -- even
though the tab control is in the proper position in the dialog template.

I think what's happening is probably because the controls inside the tab
control in a dialog which is a child of the main dialog.  (I believe
that's the recommended way of doing it).  But it's very confusing for the
user for the tab order to work this way.

Is there an easy way of fixing this problem?  I know I could subclass the
appropriate controls in the dialog and handle the tab key myself, but I'd
prefer a more global solution (I have several dialogs like this).

I suspect that using property sheets would solve my problem, but switching
to property sheets isn't really practical for me.

Thanks for any assistance.
- Eric S.

2. Samba Party

3. Tab navigation between a tab control and the displayed controls

4. Panasonic kx-p6100 - sumomon.dll error problem

5. Capturing Cntrl-Tab in place of Tab for tab indexing

6. WHY?

7. Tabbing in the tab common control

8. matrix output into text file

9. Article: Implementing drag 'n drop tab sorting in a tab control

10. Disabling tabs in a tab control

11. tabbing in subdialog of tab control of CDialog blows up

12. Ctrl-tab and tab control in a dialog

13. Tab controls and Ctrl-Tab