tags:

views:

646

answers:

2

I have a dialog that I want to place within another dialog and position relative to one of the controls on the main dialog.

void CspAceDlg::DrawResultsArea()
{
    CWnd* pTabCtl = GetDlgItem(IDC_BUILDTABS);
    CRect rectTabCtl; // Allocate CRect for control's position.
    pTabCtl->GetWindowRect(&rectTabCtl);
    int resX = rectTabCtl.right + 15;
    int resY = rectTabCtl.top;
    //RESULTS AREA
    results.Create(IDD_RESULTSDIALOG, this);
    results.SetWindowPos(this, resX, resY, /*608, 19, */175, 135, SWP_SHOWWINDOW);
    results.ShowWindow(SW_SHOW);
}

My problem is that my dialog resource (IDD_REULTSDIALOG) has properties called X Pos and Y Pos that seem to be overriding my SetWindowPos() (and the little property tab in the resource editor won't let me leave these blank). If I set these properties to 0, 0 my dialog appears in the top left corner of the main dialog. If I set them to a number I can guess-and-test place it roughly where I want, but then running the application on different resolutions causes the dialog to appear in different spots. What I really want to do anyway is place the dialog relative to another control on my main dialog (in this case my tab control). Why is my SetWindowPos() being ignored, and how do I fix this? Should I be using a different function?

A: 

Figured it out myself, largely due to this thread.

My code came out looking like this:

void CspAceDlg::DrawResultsArea()
{
    CRect rectTabCtl; // CRect representing tab control's position.
    POINT pResXY;
    POINT pResWH;

    CWnd* pTabCtl = GetDlgItem(IDC_BUILDTABS);
    pTabCtl->GetWindowRect(&rectTabCtl);

    pResXY.x = rectTabCtl.right + 15;
    pResXY.y = rectTabCtl.top;
    pResWH.x = pResXY.x + 175;
    pResWH.y = pResXY.y + 135;
    ScreenToClient(&pResXY);
    ScreenToClient(&pResWH);
    //RESULTS AREA
    results.Create(IDD_RESULTSDIALOG, this);
    //results.SetWindowPos(this, resX, resY, /*608, 19, */175, 135, SWP_SHOWWINDOW);
    results.MoveWindow(pResXY.x, pResXY.y, pResWH.x, pResWH.y, TRUE);
    results.ShowWindow(SW_SHOW);
}
Lauren
+3  A: 

According to the documentation for SetWindowPos, if you pass in SWP_SHOWWINDOW, the window will not be moved:

If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is set, the window cannot be moved or sized.

sean e
Wow, that's so strange... thanks! I was wondering why it would get ignored like that.
Lauren
Yeah, at first glance it is strange. But it means that you can use SetWindowPos for some of the other flags without having to worry about it actually moving (like when you want to change z-order).
sean e