Move focus to next item 
Author Message
 Move focus to next item

Hi,

Could someone tell me what's the right order
to disable a button on a dialog and move the
focus to the next one? I've tried it in many ways
but nothing seems to work properly. I always get
into a situation that the focus is on a disabled button
and pressing Enter closes the dialog (which I do
NOT want!). I've tried to move the focus FIRST,
but although it seems to move to the next item it
somehow still stays on the button that is in the beginning
of tab order (=the one focused when the dialog is opened)
and then pressing Enter closes the dialog. Any good
ideas? Thank you!

Regards,
Ilja M?ki



Tue, 31 Dec 2002 03:00:00 GMT  
 Move focus to next item
Move to a control with CWnd::SetFocus().  Disable a control with
CWnd::EnableWindow(FALSE).  There are several MSDN articles explaing the
"...focus is on a disabled button..." situation you mention.  You might also
have to temporarily assign a new default button.


Quote:

> Hi,

> Could someone tell me what's the right order
> to disable a button on a dialog and move the
> focus to the next one? I've tried it in many ways
> but nothing seems to work properly. I always get
> into a situation that the focus is on a disabled button
> and pressing Enter closes the dialog (which I do
> NOT want!). I've tried to move the focus FIRST,
> but although it seems to move to the next item it
> somehow still stays on the button that is in the beginning
> of tab order (=the one focused when the dialog is opened)
> and then pressing Enter closes the dialog. Any good
> ideas? Thank you!

> Regards,
> Ilja M?ki



Tue, 31 Dec 2002 03:00:00 GMT  
 Move focus to next item
You may find that even with the "OK" button disabled, that pressing the
"Enter" key may close your dialog.  The easiest way to prevent this behavior
is to override CDialog::OnOK() and only invoke the default behavior if/when
you want to close the dialog.

void CMyDialog::OnOK()
{
    // check a variable to see if it's acceptable to close
    // if it is, validate the data
    if ((m_bItsOkToClose) &&
        (UpdateData(TRUE))
    {
        EndDialog(IDOK);    // if we pass both tests, end the dialog
    }

Quote:
}

TFM3

Note: Spam-resistant e-mail address


Quote:
> Hi,

> Could someone tell me what's the right order
> to disable a button on a dialog and move the
> focus to the next one? I've tried it in many ways
> but nothing seems to work properly. I always get
> into a situation that the focus is on a disabled button
> and pressing Enter closes the dialog (which I do
> NOT want!). I've tried to move the focus FIRST,
> but although it seems to move to the next item it
> somehow still stays on the button that is in the beginning
> of tab order (=the one focused when the dialog is opened)
> and then pressing Enter closes the dialog. Any good
> ideas? Thank you!

> Regards,
> Ilja M?ki



Tue, 31 Dec 2002 03:00:00 GMT  
 Move focus to next item

Quote:
>Could someone tell me what's the right order
>to disable a button on a dialog and move the
>focus to the next one?

Move the focus, then disable the control. Here's what I do:

        if ( GetFocus()->m_hWnd == pCtrl->m_hWnd )
        {
                NextDlgCtrl();
        }
        pCtrl->EnableWindow( false );

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Tue, 31 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Moving the focus to the next TabIndex

2. How to move focus to next tab stop?

3. Property Page + Back & Next button Focus

4. Visual Studio.Net: how do I move to next compile error

5. Hopefully move to the next level

6. Trapping ENTER key to move to next control

7. Placing a Check Next to a Menu Item

8. Tiny bitmaps next to the menu items

9. How to check marks next to menu item.

10. Moving focus between controls

11. Can't move Focus to control error

12. PRB: Moving focus between composite controls

 

 
Powered by phpBB® Forum Software