Setting Initial Focus in a Wizard CPropertyPage
Paul D. Bartholomew -- PaulDB@datastorm.com
Friday, August 30, 1996
Environment: VC++ 4.0 Win95
I have a situation where I'm trying to set the initial focus of a
CPropertyPage that's part of a wizard to be something other than the
number one item in the tab order. The page has the following layout:
Country Code: [a combo box with various country codes]
Area Code: [an edit field]
Phone Number: [an edit field]
Since I don't anticipate the first two items changing, I'd like the focus
to be set to the phone number edit field when the user reaches this page
in the wizard. If I set the tab order to be (starting with the Country
Code text field) 3, 4, 5, 6, 1, 2, then the focus is indeed set to the
phone number edit field. Unfortunately, if the user presses Shift+Tab,
the focus doesn't shift to the area code edit field because the property
sheet buttons have been added to the end of the tab order. Pressing
Shift+Tab sends the user to the Cancel button, which is a bit
disconcerting. To fix that problem, I have to set the tab order to be
what you'd expect--1, 2, 3, 4, 5, 6. The trouble is that the country
code combo box now has the focus when you activate that page of the
wizard.
I've tried the obvious solutions. I overrode OnInitDialog for my
property page; did a PhoneNumber.SetFocus() from there and returned zero,
just as the documentation says. This didn't work. The focus was still
set to the combo box.
I next overrode OnSetActive and did a PhoneNumber.SetFocus() from there.
This also didn't work. The focus was still set to the combo box.
I added a message handler for ON_EN_KILLFOCUS for the phone number edit
field to see what was happening and it appears that something is calling
SetFocus for the combo box *after* the OnSetActive and the OnInitDialog.
The call stack, though, indicates that this call came from the kernel,
not from something I can get a handle on.
Any suggestions?
Paul Bartholomew
pauldb@datastorm.com
LeRoy Baxter -- lbaxter@transport.com
Sunday, September 01, 1996
Try setting the focus in the OnActivate() function.
----------
From: Paul D. Bartholomew[SMTP:PaulDB@datastorm.com]
Sent: Friday, August 30, 1996 11:52 AM
To: MFC Mailing List
Subject: Setting Initial Focus in a Wizard CPropertyPage
Environment: VC++ 4.0 Win95
I have a situation where I'm trying to set the initial focus of a
CPropertyPage that's part of a wizard to be something other than the
number one item in the tab order. The page has the following layout:
Country Code: [a combo box with various country codes]
Area Code: [an edit field]
Phone Number: [an edit field]
Since I don't anticipate the first two items changing, I'd like the focus
to be set to the phone number edit field when the user reaches this page
in the wizard. If I set the tab order to be (starting with the Country
Code text field) 3, 4, 5, 6, 1, 2, then the focus is indeed set to the
phone number edit field. Unfortunately, if the user presses Shift+Tab,
the focus doesn't shift to the area code edit field because the property
sheet buttons have been added to the end of the tab order. Pressing
Shift+Tab sends the user to the Cancel button, which is a bit
disconcerting. To fix that problem, I have to set the tab order to be
what you'd expect--1, 2, 3, 4, 5, 6. The trouble is that the country
code combo box now has the focus when you activate that page of the
wizard.
I've tried the obvious solutions. I overrode OnInitDialog for my
property page; did a PhoneNumber.SetFocus() from there and returned zero,
just as the documentation says. This didn't work. The focus was still
set to the combo box.
I next overrode OnSetActive and did a PhoneNumber.SetFocus() from there.
This also didn't work. The focus was still set to the combo box.
I added a message handler for ON_EN_KILLFOCUS for the phone number edit
field to see what was happening and it appears that something is calling
SetFocus for the combo box *after* the OnSetActive and the OnInitDialog.
The call stack, though, indicates that this call came from the kernel,
not from something I can get a handle on.
Any suggestions?
Paul Bartholomew
pauldb@datastorm.com
Steini -- stein@itn.is
Monday, September 02, 1996
At 11:52 30.8.1996 PDT, you wrote:
>
>Environment: VC++ 4.0 Win95
>
>I have a situation where I'm trying to set the initial focus of a
>CPropertyPage that's part of a wizard to be something other than the
>number one item in the tab order. The page has the following layout:
>
> Country Code: [a combo box with various country codes]
>
> Area Code: [an edit field]
>
> Phone Number: [an edit field]
>
>Since I don't anticipate the first two items changing, I'd like the focus
>to be set to the phone number edit field when the user reaches this page
>in the wizard. If I set the tab order to be (starting with the Country
>Code text field) 3, 4, 5, 6, 1, 2, then the focus is indeed set to the
>phone number edit field. Unfortunately, if the user presses Shift+Tab,
>the focus doesn't shift to the area code edit field because the property
>sheet buttons have been added to the end of the tab order. Pressing
>Shift+Tab sends the user to the Cancel button, which is a bit
>disconcerting. To fix that problem, I have to set the tab order to be
>what you'd expect--1, 2, 3, 4, 5, 6. The trouble is that the country
>code combo box now has the focus when you activate that page of the
>wizard.
>
>I've tried the obvious solutions. I overrode OnInitDialog for my
>property page; did a PhoneNumber.SetFocus() from there and returned zero,
>just as the documentation says. This didn't work. The focus was still
>set to the combo box.
>
>I next overrode OnSetActive and did a PhoneNumber.SetFocus() from there.
> This also didn't work. The focus was still set to the combo box.
>
>I added a message handler for ON_EN_KILLFOCUS for the phone number edit
>field to see what was happening and it appears that something is calling
>SetFocus for the combo box *after* the OnSetActive and the OnInitDialog.
> The call stack, though, indicates that this call came from the kernel,
>not from something I can get a handle on.
>
>Any suggestions?
>
>Paul Bartholomew
>pauldb@datastorm.com
>
>
I use this:
BOOL CMyClass::OnInitDialog()
{
...
bfFirstTime = TRUE; // bfFirstTime is BOOL
}
void CMyClass::OnSetfocusEldriVisitolur()
{
if ( bfFirstTime )
{
PhoneNumber.SetFocus();
bfFirstTime = FALSE;
}
}
Steini
stein@itn.is http://www.itn.is/~stein
Steingrimur Jonsson, Software Engineer
Home phone (354)553 1006
Work phone (354)569 2500
Direct line (354)569 2510
Fax (354)568 9507
beriksen@cda.com
Tuesday, September 03, 1996
[Mini-digest: 2 responses]
Paul,
My experience is that with CPropertyPage derived objects you cannot
seem to set the focus during OnInit like you can with plain old
CDialog derived objects. I've tried at least 20 ways (not including
the one described below) and have yet to succeed. (I don't know if
Steini's approach was just prattled off or was something actually in
use. Seeing as he called it MyClass, etc., I reserve the right to be
skeptical.)
Brian Eriksen
beriksen@cda.com
______________________________ Reply Separator _________________________________
Subject: Re: Setting Initial Focus in a Wizard CPropertyPage
Author: mfc-l@netcom.com at Internet_Mail
Date: 9/3/96 8:39 AM
At 11:52 30.8.1996 PDT, you wrote:
>
>Environment: VC++ 4.0 Win95
>
>I have a situation where I'm trying to set the initial focus of a
>CPropertyPage that's part of a wizard to be something other than the
>number one item in the tab order. The page has the following layout:
>
> Country Code: [a combo box with various country codes]
>
> Area Code: [an edit field]
>
> Phone Number: [an edit field]
>
>Since I don't anticipate the first two items changing, I'd like the focus
>to be set to the phone number edit field when the user reaches this page
>in the wizard. If I set the tab order to be (starting with the Country
>Code text field) 3, 4, 5, 6, 1, 2, then the focus is indeed set to the
>phone number edit field. Unfortunately, if the user presses Shift+Tab,
>the focus doesn't shift to the area code edit field because the property
>sheet buttons have been added to the end of the tab order. Pressing
>Shift+Tab sends the user to the Cancel button, which is a bit
>disconcerting. To fix that problem, I have to set the tab order to be
>what you'd expect--1, 2, 3, 4, 5, 6. The trouble is that the country
>code combo box now has the focus when you activate that page of the
>wizard.
>
>I've tried the obvious solutions. I overrode OnInitDialog for my
>property page; did a PhoneNumber.SetFocus() from there and returned zero,
>just as the documentation says. This didn't work. The focus was still
>set to the combo box.
>
>I next overrode OnSetActive and did a PhoneNumber.SetFocus() from there.
> This also didn't work. The focus was still set to the combo box.
>
>I added a message handler for ON_EN_KILLFOCUS for the phone number edit
>field to see what was happening and it appears that something is calling
>SetFocus for the combo box *after* the OnSetActive and the OnInitDialog.
> The call stack, though, indicates that this call came from the kernel,
>not from something I can get a handle on.
>
>Any suggestions?
>
>Paul Bartholomew
>pauldb@datastorm.com
>
>
-----From: Gonzalo Isaza
This is not a bug in MFC. It looks like a bug in windows common
control's code. The workaround for this problem is the following:
For your property sheet, create a new class derived from CPropertySheet.
Override OnInitDialog in your new class and make it look like this:
BOOL CMySheet::OnInitDialog()
{
CPropertySheet::OnInitDialog();
CPropertyPage* pPage;
VERIFY((pPage = GetActivePage()) != NULL);
pPage->SetInitialFocus();
return FALSE;
}
For each one of the pages in your property sheet, create a virtual
function SetInitialFocus. The code should look something like this:
(an inline function will work just fine)
void CMyPage::SetInitialFocus()
{
GetDlgItem(IDC_FIRSTCONTROLWITHFOCUS)->SetFocus();
}
Make sure the call to GetDlgItem does not return a NULL. You may want
to place an ASSERT.
Good luck.
Gonzalo
I speak for myself. I am not speaking for Microsoft.
| Вернуться в корень Архива
|