Tuesday, 6 August 2013

Implementing scrolling in a CWnd with multiple CWnd Children

Implementing scrolling in a CWnd with multiple CWnd Children

I'm using the ScrollHelper [1] code to try and implement scrolling in my
CWnd (ProgressListWnd) object. Within this CWnd, I have multiple child
CWnd objects (ProgressWnd) being placed within the parent ProgressListWnd.
Everything I've found is working with images or text / shapes being drawn
in a CWnd rather than only dealing with a parent CWnd with child CWnds.
Implementing the ScrollHelper seems to "work", but my issue is within my
OnPaint in the ProgressListWnd, I re-position each child object. I read
that when an OnScroll is called, it ends with sending a paint event to the
window. Since I start at 0,0 and re-position children downwards, nothing
appears to move.
My onPaint for the parent window is below. Anything scrollbar related is
directly from the ScrollHelper class.
Is there an easier way for scrolling in a CWnd that is only going to
consist of children CWnd objects? Do I need to manually keep track of
scroll positions and MoveWindow() on my children CWnds to negative
positions when repainting (which will be necessary when adding or removing
children)?
[1]
http://www.codeproject.com/Articles/10902/Add-Scrolling-to-a-CWnd-or-CDialog-using-a-C-Helpe
void CProgressListWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
POSITION pos = m_ProgressMap.GetStartPosition();
int corner = 0;
while(pos != NULL)
{
int uid = 0;
CProgressWnd* pWnd = NULL;
m_ProgressMap.GetNextAssoc(pos, uid, pWnd);
if(pWnd != NULL)
{
pWnd->MoveWindow(0,corner,400,90);
corner = corner + 90;
}
}
}

No comments:

Post a Comment