CWnd::SetRedraw (MFC)

Switch View :
ScriptFree
MFC Library Reference 
CWnd::SetRedraw 

An application calls SetRedraw to allow changes to be redrawn or to prevent changes from being redrawn.


void SetRedraw(
   BOOL bRedraw = TRUE 
);

Parameters

bRedraw

Specifies the state of the redraw flag. If this parameter is TRUE, the redraw flag is set; if FALSE, the flag is cleared.

Remarks

This member function sets or clears the redraw flag. While the redraw flag is cleared, the contents will not be updated after each change and will not be repainted until the redraw flag is set. For example, an application that needs to add several items to a list box can clear the redraw flag, add the items, and then set the redraw flag. Finally, the application can call the Invalidate or InvalidateRect member function to cause the list box to be repainted.

Example

// Updating a control or window with large amounts of data may cause 
// flicker. In such cases it may be better to turn off drawing

//...

   //m_list is a member of type CListCtrl
   m_List.SetRedraw(FALSE);  // turn drawing off regardless of list mode

//...
// Update control
//...

   m_List.SetRedraw(TRUE);  // turn drawing back on and update the window

   // invalidate the entire control, force painting
   m_List.Invalidate();
   m_List.UpdateWindow();
See Also

Reference

CWnd Class
Hierarchy Chart
WM_SETREDRAW

Concepts

CWnd Members

Community Content

Hasisko
SetRedraw(FALSE) causes window to be hidden

Like SetRedraw(TRUE) may cause the hidden window to become visible, the call to SetRedraw(FALSE) may cause the window to be hidden. This has very unfortunate consequences - if you use SetRedraw(FALSE) on a CView and then you try to update the document title, the view's frame title will not be updated - the problem lies in CDocument::UpdateFrameCounts()
where the following loop effectively ignores the hidden views:

 int iFrame = 1;
pos = GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = GetNextView(pos);
ASSERT_VALID(pView);
ASSERT(::IsWindow(pView->m_hWnd));
if (pView->IsWindowVisible()) // Do not count invisible windows.
{
CFrameWnd* pFrame = pView->GetParentFrame();
if (pFrame != NULL && pFrame->m_nWindow == iFrame)
{
ASSERT_VALID(pFrame);
if (nFrames == 1)
pFrame->m_nWindow = 0; // the only one of its kind
pFrame->OnUpdateFrameTitle(TRUE);
iFrame++;
}
}
}

Adzm
Beware of hidden controls
Calling SetRedraw(TRUE) on a hidden control may cause it to become visible. Therefore checking IsWindowVisible (or equivalent) may be wise before using this function. This behavior does not seem consistent, but I've happened across it in several different scenarios.