tags:

views:

2211

answers:

4
A: 

Is this happening with the stock listview, or is it custom draw? I've never seen redrawing issues with the standard windows controls.

Maybe you can post a screenshot to illustrate the problem? I presume you'd prefer to fix the redraw issue and not size the control exactly?

Roel
Completely stock.The problem is hard to reproduce, and I am not clear on how to post a picture here.
ravenspoint
Added screenshots
ravenspoint
Ok I see. Is this control created with the resource editor, or do you create it dynamically (in OnInitDialog() with m_ListCtrl.Create(...) for example?) If you're doing the last, have you tried playing with WS_CLIPCHILDREN and WM_CLIPSIBLINGS? That has fixed similar redraw issues for me in the past.
Roel
It is created in the resource editor. I have no problem creating it in OnInitDialog ( I do this for other things ). I do not know anything about using WS_CLIPCHILDREN - will take a look.
ravenspoint
myZoneList.ModifyStyle( 0, WS_CLIPSIBLINGS , 0 ); Adding this code in OnInitDialog has no effect, neither does it if use WS_CLIPCHILDREN. My quick reading suggests it would only if the rows were windows, which I doubt.
ravenspoint
+1  A: 

I recall this being a bug in the ListView (not just through MFC, but the common control in general) itself. A quick google on this seems to hit a lot of people coming to that same conclusion. I guess since Windows Explorer doesn't have gridlines they don't feel the need fix this? I remember this back in the late 90's.

I guess the trick would be to invalidate the window after a scroll - maybe in response to a VSCROLL message? Just a guess.

Aardvark
What search terms did you use in google? I could find nothing. Is "ListView" the same as "List Control", which is what I am using>
ravenspoint
Aardvark
+5  A: 

This is indeed a bug related to "smooth scrolling," here's a workaround:

void CMyListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    __super::OnVScroll(nSBCode, nPos, pScrollBar);
    Invalidate();
    UpdateWindow();
}
Aidan Ryan
To make the framework call the overide, it is necessary to add it to the message map.
ravenspoint
Details of message map coding in my answer
ravenspoint
Message map is something everyone working in MFC should understand, not specifically pertinent to this answer.
Aidan Ryan
You're not going to accept this answer since he didn't put the message map entry?? Geesh! The message map thing could have just been appended here as a comment (or edit you question with it).
Aardvark
A: 

To fix this bug in the MFC List Control you need to specialize the control, over-ride the method wich responds to the scroll, and force it to redraw the list completely after it has done the scroll.

interface header

class cSmoothListControl : public CListCtrl
{
public:
    DECLARE_MESSAGE_MAP()
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
};

implementation:

BEGIN_MESSAGE_MAP(cSmoothListControl, CListCtrl)
ON_WM_VSCROLL()
END_MESSAGE_MAP()

void cSmoothListControl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // call base class method to do scroll
    CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);

    // force redraw to cover any mess that may be created
    Invalidate();
    UpdateWindow();
}
ravenspoint
This answer just adds peripheral message map cruft to my already sufficient answer.
Aidan Ryan
Ajryan, I did not find your answer sufficient. When I implemented it, it failed. It took about an hour to find the necessary code you had left out. I thought to save others this grief.
ravenspoint
Completely ridiculous. That's like asking how to add two numbers and saying the answer was not sufficient because it didn't say how to print the result.
Aidan Ryan
sorry, I agree with ravenspoint on this. OnVScroll never gets called if ON_WM_VSCROLL() is not declared in the messagemap, and it is not mentioned in the msdn documentation at all. Check http://msdn.microsoft.com/en-us/library/fhfk142k%28VS.80%29.aspx you can find this page: http://msdn.microsoft.com/en-us/library/hfk31946%28VS.80%29.aspx only if you already know that a message map entry is expected.
rec
Well I also think it's ridiculous. Any MFC programmer worth his salt should know to add a bloody messagemap entry to get the overridden function to be called. Also -1 for crappy tagging.
demoncodemonkey