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. Problem with SetFocus

Problem with SetFocus

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 4 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
    AnTri
    wrote on last edited by
    #1

    Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!) CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog I can see that the control get the focus, but it jumps back to listbox immediately...

    G J D 3 Replies Last reply
    0
    • A AnTri

      Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!) CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog I can see that the control get the focus, but it jumps back to listbox immediately...

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      You might try using PostMessage to send a user-defined message from the second dialog to the first in your listbox notification handler. This should let the focus handling in the list box complete, and then your user-defined message would reach the first dialog, which could then set the focus as desired.


      Software Zen: delete this;

      Fold With Us![^]

      1 Reply Last reply
      0
      • A AnTri

        Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!) CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog I can see that the control get the focus, but it jumps back to listbox immediately...

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        Where is this code located? In OnInitDialog()? If so, make sure you return FALSE from the OnInitDialog() function. If not, the system will give the first control in the dialog the focus (which may not be the control you have given focus).

        -- Nominated For Three Glemmys

        1 Reply Last reply
        0
        • A AnTri

          Hey, I've an application with 2 dialogs. The first dialog holds a couple of controls, the second dialog a listbox with handles to the controls (on the first dialog). Now I want to set the focus to the control on the first dialog by selecting an item in the listbox. My problem is that the focus jumps back to my listbox after I set it to the control. Code after selecting an item in listbox (all pointers are valid!) CWnd* pWnd = GetHandleToDialogControl(iIndex); //Get CWnd* information from selected item pWnd->SetFocus() //Set focus to my control on first dialog I can see that the control get the focus, but it jumps back to listbox immediately...

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

          Having two dialogs communicate in this fashion indicates a very bad design. They should be using PostMessage() to communicate with each other.


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          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