cppgangster -1 Junior Poster in Training

Hi

I am trying to get windows positioned in specific order as show below

desired.PNG

but I am unable to get and get always this

wrong.PNG

the code below is shown

HDWP cmdWnds;
    cmdWnds = BeginDeferWindowPos(col.size());
    for (int i = 0; i < col.size(); i++)
    {
        if (i == 0)
        {
            if (DeferWindowPos(cmdWnds, col[i], HWND_NOTOPMOST, x_pos_start_pr + i * x_offset_pr, y_pos_start_pr + i * y_offset_pr, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW) == NULL)
                return ERROR;
        }
        else
        {
            if (DeferWindowPos(cmdWnds, col[i], col[i - 1], x_pos_start_pr + i * x_offset_pr, y_pos_start_pr + i * y_offset_pr, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW) == NULL)
                return ERROR;
        }
    }
    if (EndDeferWindowPos(cmdWnds) == ERROR)
        return ERROR;
    return !ERROR;

where col is collection of cmd windows updated every time this code is run.
After reading Click Here unable to understand how to use it correctly the fucntions.
Does anyone know what is wrong with my code?

Thanks in advance for any help