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. SetFocus from OnInitDialog for Button control.

SetFocus from OnInitDialog for Button control.

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

    Hi, I my application(MFC dialog based),initially i have to put the focus on specified button control. i.e.Suppose my dialog having Three buttons 1.OK,2,Cancel,3.Button1.Initially i have to put focus on Button1, if user clicked Enter key the Button1 message handler will call. for this i tried like this. 1.CMyTestDlg::OnInitDialog() { GetDlgItem(IDC_BUTTON1)->SetFocus(); return FALSE;//Instead of TRUE } It showing correctly focus on Button1,But if i pressed enter key OnOK() is calling. Please help me inthis context. regards anju anju

    S 1 Reply Last reply
    0
    • A anju

      Hi, I my application(MFC dialog based),initially i have to put the focus on specified button control. i.e.Suppose my dialog having Three buttons 1.OK,2,Cancel,3.Button1.Initially i have to put focus on Button1, if user clicked Enter key the Button1 message handler will call. for this i tried like this. 1.CMyTestDlg::OnInitDialog() { GetDlgItem(IDC_BUTTON1)->SetFocus(); return FALSE;//Instead of TRUE } It showing correctly focus on Button1,But if i pressed enter key OnOK() is calling. Please help me inthis context. regards anju anju

      S Offline
      S Offline
      SNathani
      wrote on last edited by
      #2

      Hi, You don't have to setfocus() on OnInitDialog(), Try this one -- In design mode , go to Layout, choose Tab order, Click on the buttons that you want the tab order sequence. Run the application, -- Press Enter when the dialog shows up hope this might help you out

      A 1 Reply Last reply
      0
      • S SNathani

        Hi, You don't have to setfocus() on OnInitDialog(), Try this one -- In design mode , go to Layout, choose Tab order, Click on the buttons that you want the tab order sequence. Run the application, -- Press Enter when the dialog shows up hope this might help you out

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

        Hi SNathani, Thank you for your suggestion. Suppose, if my button is OwnerDrawn, what can i do? regards anju

        R 1 Reply Last reply
        0
        • A anju

          Hi SNathani, Thank you for your suggestion. Suppose, if my button is OwnerDrawn, what can i do? regards anju

          R Offline
          R Offline
          Roger Allen
          wrote on last edited by
          #4

          It does not make any difference if the button is OwnerDrawn. You main problem will probably be that the OK button is set as the default button in the resource editor, you may need to clear this flag to get RETURN to act correctly on BUTTON1. Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

          A 1 Reply Last reply
          0
          • R Roger Allen

            It does not make any difference if the button is OwnerDrawn. You main problem will probably be that the OK button is set as the default button in the resource editor, you may need to clear this flag to get RETURN to act correctly on BUTTON1. Roger Allen Sonork 100.10016 Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003

            A Offline
            A Offline
            anju
            wrote on last edited by
            #5

            Hi Roger Allen, Thanks for your reply. Already I cleared Ok button "default button" property. can you guess other thing. regards, anju

            B 1 Reply Last reply
            0
            • A anju

              Hi Roger Allen, Thanks for your reply. Already I cleared Ok button "default button" property. can you guess other thing. regards, anju

              B Offline
              B Offline
              basementman
              wrote on last edited by
              #6

              Rather than calling SetFocus(), you should call the following: GotoDlgCtrl(GetDlgItem(IDC_BUTTON1));

              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