goodvibration
goodvibration

Reputation: 6206

Scrolling a child window "overflows" to the parent window

I have a parent window and a child window, something like:

class CChildDlg : public CDialog
{
    ...
}

class CParentDlg : public CDialog
{
    CChildDlg m_cChildDlg;
    ...
}

In the parent's OnInitDialog function, I create the child window:

m_cChildDlg.CreateEx(0,
                     WC_STATIC,
                     NULL,
                     WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|SS_NOTIFY,
                     {0,0,width,height},
                     this,
                     0);

I can scroll the child window easily using m_cChildDlg.ScrollWindow(xAmount, yAmount).

The problem is that I have a few other controls in the parent window right above the child window (tool-bar, etc), which the child window "overrides" when scrolled upwards.

I tried calling SetWindowPos in order to set the child window behind the other controls, but that did not seem to make any difference.

This is what the MSDN says about these two functions:

But I haven't been able to find anything related to this problem, so I'm guessing there might be something else that I'm missing here.

Thank you.

Upvotes: 2

Views: 690

Answers (1)

zett42
zett42

Reputation: 27756

You are not passing a clip rectangle (parameter lpClipRect) to ScrollWindow(). From the reference:

If lpClipRect is NULL, no clipping is performed on the scroll rectangle.

That's why you get the overflow.

You can fix it like this:

CRect rc; 
m_cChildDlg.GetClientRect(rc);
m_cChildDlg.ScrollWindow(xAmount, yAmount, nullptr, rc);

Upvotes: 2

Related Questions