Wednesday, December 17, 2003

WTL list control

I always had refresh problem with the list control, now I think I had the solution:

LRESULT CEMRecycleBinListCtrl::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

{

// we shouldn't use begin paint to obtain the HDC,

// otherwise we will loose the update region for the parent

WTL::CDC dc = GetDC();

WTL::CRgn rgn = CreateRectRgn(0,0,0,0);

if( GetUpdateRgn(rgn) != ERROR )

{

CRect headerRC;

CRect listRC;

WTL::CBrush hbrBkgnd = CreateSolidBrush(dc.GetBkColor());

CHeaderCtrl header = GetHeader();

header.GetClientRect(&headerRC);

LVHITTESTINFO htInfo;

ZeroMemory(&htInfo, sizeof(LVHITTESTINFO));

htInfo.pt.x = 1;

htInfo.pt.y = headerRC.bottom + 1;

int idx = HitTest(&htInfo);

if( idx >= 0 )

{

CRect rc;

int count = GetCountPerPage();

if( GetItemRect(idx+count, &rc, LVIR_BOUNDS) )

{

listRC.top = headerRC.bottom;

listRC.left = rc.left + 2;

listRC.bottom = rc.bottom;

listRC.right = rc.right;

WTL::CRgn headerRgn = CreateRectRgnIndirect(headerRC);

WTL::CRgn listRgn = CreateRectRgnIndirect(listRC);

rgn.CombineRgn(listRgn, RGN_DIFF);

rgn.CombineRgn(headerRgn, RGN_DIFF);

}

}

dc.FillRgn(rgn, hbrBkgnd);

}

ReleaseDC(dc);

// we should let the parent to draw himself

bHandled = FALSE;

return 0;

} // OnPaint

 

No comments: