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

  • Home
  • SEARCH
  • 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 6915125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:26:08+00:00 2026-05-27T09:26:08+00:00

We have a series of dialogs in our application for which the dialog template

  • 0

We have a series of dialogs in our application for which the dialog template defines 4 buttons along the bottom of the screen. However (depending which version of our hardware the application is running on) we sometimes create 2 additional buttons and then line up the 6 buttons (4 from the template, 2 created by calling CButton::Create()) along the bottom.

The problem I have is that usually the user can move the focus between these buttons using the left / right arrow keys (there is no mouse or touchscreen, just a restricted keyboard). This follows the control TAB-order as you would expect for the 4 buttons from the template. However the 2 dynamically create controls appear to be inserted at the beginning of the TAB-order, and that means (because they are put at the right-hand side of the screen) that they are in the “wrong” order as far as the cursor keys goes. In other words, when the focus gets to the left-hand button (TAB order 1) pressing the left arrow jumps the focus to the button on the right-hand side, which is just plain confusing…

There appears to be some link between Z-order (which I can affect with SetWindowPos()) and TAB-order but it does not seem to be a simple 1-to-1: by changing the Z-order I can move the sequence around so that the buttons are completely in the wrong order, so I can change the Z-order, but I can’t work out how to get them in the right order.

Can anyone give a concise explanation of how TAB-order works, and how to control the sequencing of controls at runtime?

Edit:
kol suggested below using SetWindowPos() to set the Z-order. This I had tried before but it does not let the cursor keys control the focus as expected.

However, by rigging this up so I can use TAB (as a test — this isn’t practical for the end-user solution) I find that kol’s solution does resolve the TAB-order. The problem I have is that this is not the same as the order used by the cursor keys!

So, revised question: how can I specify the order in which left / right cursor keys move focus between controls?

Solution:
With assistance from kol and MarkRansom’s input, I have got this working now.

I used SetWindowPos() as suggested by kol to put my new buttons after the existing buttons in the TAB order, and then (as Mark suggested) made the first button WS_GROUP | WS_TABSTOP but cleared those flags from the other buttons.

However this was not enough to solve the problem, with the 2 new buttons still appearing to come before the first rather than after the second when using arrow keys (not TAB) to move around.

I looked at my dialog template, and it was like this:

IDD_QUERY DIALOG  0, 0, 156, 34
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "+++Skey1+++",IDC_SKEY_1,1,21,36,12
    PUSHBUTTON      "+++Skey2+++",IDC_SKEY_2,40,21,37,12
    PUSHBUTTON      "+++Skey3+++",IDC_SKEY_3,79,21,36,12
    PUSHBUTTON      "+++Skey4+++",IDC_SKEY_4,118,21,36,12
    LTEXT           "Static",IDC_QUERY_MSG,2,1,153,15
END

So the static IDC_QUERY_MSG, which is used to display information to the user, was coming after the 4th button in the template. To resolve the problem, I moved IDC_QUERY_MSG before the first button (IDC_SKEY_1): this means the 6 buttons are not split up by a static inbetween, and has solved the problem.

Thanks to everyone for their assistance!

  • 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-27T09:26:09+00:00Added an answer on May 27, 2026 at 9:26 am

    Use the SetWindowPos member of your buttons. Calling it on button A and setting its first parameter to button B, puts button A after button B in the TAB order. If you want to set the order of two controls, you have to know the controls before and after them in the TAB order – this example shows how to do this (its not MFC but pure WinAPI, but it’s easy to understand).

    == UPDATE ==

    I created a dialog template with four buttons at the bottom and an editbox at the top, with TAB order button1 -> button2 -> button3 -> button4 -> editbox -> button1 -> ... In OnInitDialog, I added two additional buttons at runtime, and inserted them into the existing TAB order between button4 and editbox using SetWindowPos and GetNextWindow. Pressing TAB repeatedly shows that the TAB order is correct: button1 -> button2 -> button3 -> button4 -> button5 -> button6 -> editbox -> button1 -> ...

    class CTestDlg : public CDialogEx
    {
    public:
        CTestDlg() : CDialogEx(CTestDlg::IDD) {}
        enum { IDD = IDD_TESTDIALOG };
    
    protected:
        CButton button5;
        CButton button6;
        virtual BOOL OnInitDialog();
    };
    
    BOOL CTestDlg::OnInitDialog()
    {
        CDialogEx::OnInitDialog();
    
        CButton* button4 = (CButton*)GetDlgItem(IDBUTTON4);
        CWnd* next = button4->GetNextWindow(GW_HWNDNEXT);
    
        button5.Create("Button5", WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON, CRect(340, 172, 415, 195), this, 1005);
        button5.SetWindowPos(button4, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); 
    
        button6.Create("Button6", WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON, CRect(422, 172, 497, 195), this, 1006);
        button6.SetWindowPos(&button5, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); 
    
        if (next != NULL)
            next->SetWindowPos(&button6, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); 
    
        return TRUE;
    }
    
    void CDynamicMfcButtonTestApp::OnTestRun()
    {
        CTestDlg testDlg;
        testDlg.DoModal();  
    }
    

    == UPDATE2 ==

    The order of controls can be set using SetWindowPos and GetNextWindow, as above. The “tab order” and the “arrow order” can be set by setting the WS_TABSTOP and WS_GROUP styles of the controls:

    • The WS_TABSTOP style specifies the controls to which the user can
      move by pressing the TAB key or SHIFT+TAB keys.

    • The WS_GROUP style
      marks the beginning of a group of controls. If a control in the group
      has the input focus when the user begins pressing direction keys, the
      focus remains in the group. In general, the first control in a group
      must have the WS_GROUP style and all other controls in the group must
      not have this style. All controls in the group must be
      contiguous—that is, they must have been created consecutively with no
      intervening controls.

    More details can be found on MSDN, here.

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

Sidebar

Related Questions

We have our custom setup.exe program which launches a series of individial MSIs in
I have a page which has a series of dynamic jquery ui dialogs which
I have an app which creates a series of modeless dialog windows which are
I have a series of complex views being displayed on the screen and I
I have a Window that serves as a dialog in a WPF application. This
I have a series of texfields, which I'd like to format as currency. Preferably,
I have a series of UIViewControllers throughout my application. Most of them have the
Have the following code which (resides in a dialog box) and serves as an
I need to create a pdf file which will have series of images, where
I have a series of four yes/no choices in four separate dialog boxes, the

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.