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. How can I set the focus to an specific item?

How can I set the focus to an specific item?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 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.
  • P Offline
    P Offline
    pantao551
    wrote on last edited by
    #1

    :) I have just asked a question the day before yesterday, And thanks to Alok and Jörgen Sigvardsson who gave me nice ways to solve my last question. Now I have got a new question to ask. Can I set the keyboard focus on a radio button when the dialog pop up? I use GetDlgItem(IDC_RADIO1)->SetFocus(); in the OnInitDialog(). But it didn't work. //IDC_RADIO1 is the ID of the radio button in the dialog //where I wish the keyboard focus to stay at when the dialog pop up Thanks!

    G 1 Reply Last reply
    0
    • P pantao551

      :) I have just asked a question the day before yesterday, And thanks to Alok and Jörgen Sigvardsson who gave me nice ways to solve my last question. Now I have got a new question to ask. Can I set the keyboard focus on a radio button when the dialog pop up? I use GetDlgItem(IDC_RADIO1)->SetFocus(); in the OnInitDialog(). But it didn't work. //IDC_RADIO1 is the ID of the radio button in the dialog //where I wish the keyboard focus to stay at when the dialog pop up Thanks!

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

      If you set the focus in OnInitDialog(), you must return FALSE from OnInitDialog(). If you don't, the normal Windows dialog handling will set the focus to the first control in the tab order.


      Software Zen: delete this;

      P 1 Reply Last reply
      0
      • G Gary R Wheeler

        If you set the focus in OnInitDialog(), you must return FALSE from OnInitDialog(). If you don't, the normal Windows dialog handling will set the focus to the first control in the tab order.


        Software Zen: delete this;

        P Offline
        P Offline
        pantao551
        wrote on last edited by
        #3

        Thanks! I tried the method you told me, And it did work in the dialog. But when I tried this in a fromview, which contains the item I want to set the keyboard focus at, it didn't work. Because the OnInitialUpdate() function in the CFormView class doesn't have a return value. What can I do in this case? Thanks!

        B 1 Reply Last reply
        0
        • P pantao551

          Thanks! I tried the method you told me, And it did work in the dialog. But when I tried this in a fromview, which contains the item I want to set the keyboard focus at, it didn't work. Because the OnInitialUpdate() function in the CFormView class doesn't have a return value. What can I do in this case? Thanks!

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          You could try to post your form view a special message, that once recieved, will set the focus for you, after the formview has initialized. Once you are out of an 'init' handler, like OnInitDialog it is easy to set the focus to any control you want. The default handlers almost always try to set one for you, which as you have discovered is not always convenient.

          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