Change Tab order by code in a MFC Dialog


First Option

use ctrl+d on resource view in visual studio. and change tab order


Other option

An easier solution is change the sequence of controls in .rc file...that will change your tab order and z order both.

For Eg. this dialog will have Tab Order IDOK first, then IDCANCEL

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
END

now if you change it to

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
END

This will have Tab Order IDCANCEL first then IDOK


The tab order of controls on a dialog is governed by the Z-Order of those controls. So, to change the tab order, change the z-order positioning of the relevant controls.

You can change the z-order by using SetWindowPos. See this, for example.

Tags:

Tabs

Mfc