Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3991536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:37:40+00:00 2026-05-20T06:37:40+00:00

I created an application in which I use window procedure to keep track of

  • 0

I created an application in which I use window procedure to keep track of all the controls in the window.

My question is, how do I initially set the focus to the first created control in the window?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:37:41+00:00Added an answer on May 20, 2026 at 6:37 am

    There are two ways to set the initial focus to a particular control in MFC.

    1. The first, and simplest, method is to take advantage of your controls’ tab order. When you use the Resource Editor in Visual Studio to lay out a dialog, you can assign each control a tab index. The control with the lowest tab index will automatically receive the initial focus. To set the tab order of your controls, select “Tab Order” from the “Format” menu, or press Ctrl+D.

    2. The second, slightly more complicated, method is to override the OnInitDialog function in the class that represents your dialog. In that function, you can set the input focus to any control you wish, and then return FALSE to indicate that you have explicitly set the input focus to one of the controls in the dialog box. If you return TRUE, the framework automatically sets the focus to the default location, described above as the first control in the dialog box. To set the focus to a particular control, call the GotoDlgCtrl method and specify your control. For example:

      BOOL CMyDialog::OnInitDialog()
      {
          CDialog::OnInitDialog();
      
          // Add your initialization code here
          // ...
      
          // Set the input focus to your control
          GotoDlgCtrl(GetDlgItem(IDC_EDIT)); 
      
          // Return FALSE because you manually set the focus to a control
          return FALSE;
      }
      

      Note that you should not set focus in a dialog box by simply calling the SetFocus method of a particular control. Raymond Chen explains here on his blog why it’s more complicated than that, and why the GotoDlgCtrl function (or its equivalent, the WM_NEXTDLGCTRL message) is preferred.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created an application which has a menu where it's items are created dynamicly.
I have created an application which needs 'hand-over' to the support group in the
I have created an application which needs to have a profile box tab which
We have created an application which we want to run in a 64 bit
The company where I work created this application which is core to our business
I have created a small application which opens,reads and creates Excel files. The app
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,
I'm developing an application which currently have hundreds of objects created. Is it possible
I've created an attached behaviour in my WPF application which lets me handle the
I'm debugging an intermittent problem in which an application (created using C++ in Visual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.