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. Focus Problem

Focus Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
5 Posts 5 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
    Abhijeet Pathak
    wrote on last edited by
    #1

    I've a MFC dialog with two edit boxes... By default focus in on first text box. I want that during dialog load if first edit box contains some text, then second edit box should have focus... I've tried SetFocus() in InitDialog() but it's not working... focus still remains on first control. How should I do it? Please Help!

    C N M G 4 Replies Last reply
    0
    • A Abhijeet Pathak

      I've a MFC dialog with two edit boxes... By default focus in on first text box. I want that during dialog load if first edit box contains some text, then second edit box should have focus... I've tried SetFocus() in InitDialog() but it's not working... focus still remains on first control. How should I do it? Please Help!

      C Offline
      C Offline
      chandu004
      wrote on last edited by
      #2

      make sure that Set focus() is the last statement in the init dialog. if it is so, just post a sample of your init dialog code, i shall solve it

      1 Reply Last reply
      0
      • A Abhijeet Pathak

        I've a MFC dialog with two edit boxes... By default focus in on first text box. I want that during dialog load if first edit box contains some text, then second edit box should have focus... I've tried SetFocus() in InitDialog() but it's not working... focus still remains on first control. How should I do it? Please Help!

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        You have to return FALSE from OnInitDialog if you need to set the focus to a particular control by yourself.

        - NS -

        1 Reply Last reply
        0
        • A Abhijeet Pathak

          I've a MFC dialog with two edit boxes... By default focus in on first text box. I want that during dialog load if first edit box contains some text, then second edit box should have focus... I've tried SetFocus() in InitDialog() but it's not working... focus still remains on first control. How should I do it? Please Help!

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          In addition to what NS17 stated, you should also use GotoDlgCtrl() instead of SetFocus() when setting the focus to edit controls. Mark

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          • A Abhijeet Pathak

            I've a MFC dialog with two edit boxes... By default focus in on first text box. I want that during dialog load if first edit box contains some text, then second edit box should have focus... I've tried SetFocus() in InitDialog() but it's not working... focus still remains on first control. How should I do it? Please Help!

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

            If you change the focus in OnInitDialog() to something other than the first control, make sure that your OnInitDialog() handler returns FALSE. If it returns TRUE, the default Window handler sets the focus for you, overriding anything you did.


            Software Zen: delete this;

            Fold With Us![^]

            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