CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    [RESOLVED] Know the direction of the navigation on a dialog

    I´m developing an Application that I need to know if the user is going forward or backward on a dialog. For exemple: Supouse I have a dialog with ten edit boxes. The focus is on the 5th Edit. So the user clicked with the mouse on the 3rd edit or on the 7th Edit box.
    On the killfocus of the 5th edit box I need to know if the user is going backwards (3rd edit) or upwards (7th Edit). the Edit ID are on crescent order. I have looked on the net and haven´t seen a solution. I´m looking, for exemple, for a windows message with any parameter telling me where the focus is going to.

    Any help will be appreciated.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Know the direction of the navigation on a dialog

    On the killfocus of the 5th edit box I need to know if the user is going backwards (3rd edit) or upwards (7th Edit)
    The EN_KILLFOCUS notification identifies which control is losing the focus. You don't know which control is gaining the focus until a EN_SETFOCUS notification is received later which identifies the control gaining the focus. Once you have received EN_SETFOCUS then you can determine whether the user is going backwards or forwards.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Know the direction of the navigation on a dialog

    I'm not sure what "crescent order" is, but if the resource IDs are sequential, you can get the resource ID of the control that was left and the control that has the focus and compare them numerically.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Know the direction of the navigation on a dialog

    Quote Originally Posted by Rabelo View Post
    I´m developing an Application that I need to know if the user is going forward or backward on a dialog. For exemple: Supouse I have a dialog with ten edit boxes. The focus is on the 5th Edit. So the user clicked with the mouse on the 3rd edit or on the 7th Edit box.
    On the killfocus of the 5th edit box I need to know if the user is going backwards (3rd edit) or upwards (7th Edit). the Edit ID are on crescent order. I have looked on the net and haven´t seen a solution. I´m looking, for exemple, for a windows message with any parameter telling me where the focus is going to.

    Any help will be appreciated.
    Well, one of the possible solution would be:
    1. derive a new class (say, CMyEdit) from CEdit and handle WM_KILLFOCUS in this derive class. Note that wParam of WM_KILLFOCUS is "a handle to the window that receives the keyboard focus";
    2. Subclass all of your edit controls to be of the type of this new CMyEdit.
    3. Implement a user defined message with two parameters (its own handle and the handle of the window receiving focus) that this CMyEdit will send/post to the dialog.
    4. handle this user defined message in the dialog and decide what to do...
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: Know the direction of the navigation on a dialog

    thank you for the replies.

    I did exatly what Victor said only in the 5th edit box. It is working but I don´t want to subclass all the edit box, there are many other classes and messages envolved and this will increase the complexity. As EN_SETFOCUS is sent only to the Edit that is gainng the focus (Is this right?) this seem to be the only solution... I´d prefer to know which edit is gainng the focus before the control that has the focus (the 5th) loose it.
    Last edited by Rabelo; October 12th, 2017 at 11:49 PM.

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Know the direction of the navigation on a dialog

    I´d prefer to know which edit is gainng the focus before the control that has the focus (the 5th) loose it.
    AFAIK this isn't possible as the sequence is loose then gain. The loose doesn't know where the focus is going and the gain doesn't know from where the focus came. It's only possible to know from where the gain came from (in EN_SETFOCUS) by saving the loose (in EN_KILLFOCUS) which is then checked in gain.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: Know the direction of the navigation on a dialog

    As VictorN said:

    Note that wParam of WM_KILLFOCUS is "a handle to the window that receives the keyboard focus";

    This was a great hint. I got the Id of the edit calling GetDlgCtrlID() with the pointer recieved as parameter on KillFocus(). So I got the next ctrl id number before get out of the control that has the focus, just like I needed.


    Problem solved.

    Thank you.
    Last edited by Rabelo; October 13th, 2017 at 06:53 AM.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Know the direction of the navigation on a dialog

    Quote Originally Posted by Rabelo View Post
    ...
    Problem solved.

    Thank you.
    You are welcome!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured