Follow these steps(Just a demo)…
- Add two buttons to a fresh dialog in a sequencial order, IDC_BUTTON1 and IDC_BUTTON2
- Goto OnInitDialog(you are not restricted to OnInitDialog, you can also do this on a button click) and paste this line of code
[sourcecode language=’cpp’]GetDlgItem( IDC_BUTTON1 )->SetWindowPos(GetDlgItem( IDC_BUTTON2 ),
0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );[/sourcecode]
So now run the dialog and you will see that
the focus is on the second button i.e. IDC_BUTTON2, I am invoking
IDC_BUTTON1 is moved down in the Z-Order after
IDC_BUTTON2. So this is how we dynamically change the Z-Order or tab order.
The key to all this behavior is because SWP_NOZORDER is not given when SetWindowPos is called, so it changes Z-Order of the control on which this method is invoked.