Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Set focus automatically to the last focus item after clossinga modal dialog

Set focus automatically to the last focus item after clossinga modal dialog

Scheduled Pinned Locked Moved C / C++ / MFC
c++
13 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aks
    wrote on last edited by
    #1

    1. I set tab order for control in a MFC dialog. 2. Started the application. 3. Clicked a button in dialog, whose tab order is 3. 4. A modal dialog displayed. 5. Closed the modal dialog. Now the focus automatically moved to the control having tab order 0. Since the focus was on the button just before the click, I would like to retain the selection on the same button.

    aks

    L D 2 Replies Last reply
    0
    • A aks

      1. I set tab order for control in a MFC dialog. 2. Started the application. 3. Clicked a button in dialog, whose tab order is 3. 4. A modal dialog displayed. 5. Closed the modal dialog. Now the focus automatically moved to the control having tab order 0. Since the focus was on the button just before the click, I would like to retain the selection on the same button.

      aks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      aks. wrote:

      3. Clicked a button in dialog, whose tab order is 3.

      But did this button actually have the focus at this point?

      A 1 Reply Last reply
      0
      • L Lost User

        aks. wrote:

        3. Clicked a button in dialog, whose tab order is 3.

        But did this button actually have the focus at this point?

        A Offline
        A Offline
        aks
        wrote on last edited by
        #3

        Yes. Before button click, even if the last focus is on another control( say tab order 2 ), after closing the Modal dialog the focus move to control having Tab order 0.

        aks

        L 1 Reply Last reply
        0
        • A aks

          Yes. Before button click, even if the last focus is on another control( say tab order 2 ), after closing the Modal dialog the focus move to control having Tab order 0.

          aks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I have a similar application (Win32 rather than MFC), but the focus stays in the correct place on return from the second dialog. I can only suggest you do some debugging to try to see what is happening under the covers.

          1 Reply Last reply
          0
          • A aks

            1. I set tab order for control in a MFC dialog. 2. Started the application. 3. Clicked a button in dialog, whose tab order is 3. 4. A modal dialog displayed. 5. Closed the modal dialog. Now the focus automatically moved to the control having tab order 0. Since the focus was on the button just before the click, I would like to retain the selection on the same button.

            aks

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            aks. wrote:

            Now the focus automatically moved to the control having tab order 0.

            How are you verifying this?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            A 1 Reply Last reply
            0
            • D David Crow

              aks. wrote:

              Now the focus automatically moved to the control having tab order 0.

              How are you verifying this?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              A Offline
              A Offline
              aks
              wrote on last edited by
              #6

              Yes. I think the default MFC application created using the VS2010 wizard has this behavior.

              aks

              L 1 Reply Last reply
              0
              • A aks

                Yes. I think the default MFC application created using the VS2010 wizard has this behavior.

                aks

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                There is a world of difference between thinking something and actually checking it. If this was the default behaviour it is likely that many programs would not work.

                A 1 Reply Last reply
                0
                • L Lost User

                  There is a world of difference between thinking something and actually checking it. If this was the default behaviour it is likely that many programs would not work.

                  A Offline
                  A Offline
                  aks
                  wrote on last edited by
                  #8

                  Nice quote :) Could you please suggest a solution!

                  aks

                  L 1 Reply Last reply
                  0
                  • A aks

                    Nice quote :) Could you please suggest a solution!

                    aks

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Solution to what? We have no idea what your code is doing, or what you are doing when you run it, beyond your belief that the focus moves after you run some dialog. The only way to move forward with this is to write a very simple test program to demonstrate the problem and run some tests until you can isolate exactly what is happening.

                    A 1 Reply Last reply
                    0
                    • L Lost User

                      Solution to what? We have no idea what your code is doing, or what you are doing when you run it, beyond your belief that the focus moves after you run some dialog. The only way to move forward with this is to write a very simple test program to demonstrate the problem and run some tests until you can isolate exactly what is happening.

                      A Offline
                      A Offline
                      aks
                      wrote on last edited by
                      #10

                      please find the source shared at https://www.dropbox.com/s/w8pv31dhxy88h5p/Focus_Test.zip?dl=0[^]

                      aks

                      L D 2 Replies Last reply
                      0
                      • A aks

                        please find the source shared at https://www.dropbox.com/s/w8pv31dhxy88h5p/Focus_Test.zip?dl=0[^]

                        aks

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Sorry, I don't have MFC.

                        1 Reply Last reply
                        0
                        • A aks

                          please find the source shared at https://www.dropbox.com/s/w8pv31dhxy88h5p/Focus_Test.zip?dl=0[^]

                          aks

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #12

                          The onus is on you to narrow the problem down to just the relevant code. Sane folks aren't going to chase links around and pull unrelated code from a project.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          A 1 Reply Last reply
                          0
                          • D David Crow

                            The onus is on you to narrow the problem down to just the relevant code. Sane folks aren't going to chase links around and pull unrelated code from a project.

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                            A Offline
                            A Offline
                            aks
                            wrote on last edited by
                            #13

                            I did not done any specific code for the setting the focus. I just shared the framework generated code for easily reproducing the issue, so that you can understand the issue clearly.

                            aks

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups