HOWTO: Prevent Screen Flash During List Box Multiple Update

ID: Q66479


The information in this article applies to:


SUMMARY

The WM_SETREDRAW message can be used to set and clear the redraw flag for a window. Before an application adds many items to a list box, this message can be used to turn the redraw flag off, which prevents the list box from being painted after each addition. Properly using the WM_SETREDRAW message keeps the list box from flashing after each addition.


MORE INFORMATION

The following four steps outline ways to use the WM_SETREDRAW message to facilitate making a number of changes to the contents of a list box in a visually pleasing manner:

  1. Clear the redraw flag by sending the list box a WM_SETREDRAW message with wParam set to FALSE. This prevents the list box from being painted after each change.


  2. Send appropriate messages to make any desired changes to the contents of the list box.


  3. Set the redraw flag by sending the list box a WM_SETREDRAW message with wParam set to TRUE. The list box does not update its display in response to this message.


  4. Call InvalidateRect(), which instructs the list box to update its display. Set the third parameter to TRUE to erase the background in the list box. If this is not done, if a short list box item is drawn over a long item, part of the long item will remain visible.


The following code fragment illustrates the process described above:

   /* Step 1: Clear the redraw flag. */ 
   SendMessage(hWndList, WM_SETREDRAW, FALSE, 0L);

   /* Step 2: Add the strings. */ 
   for (i = 0; i < n; i++)
      SendMessage(hWndList, LB_ADDSTRING, ...);

   /* Step 3: Set the redraw flag. */ 
   SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);

   /* Step 4: Invalidate the list box window to force repaint. */ 
   InvalidateRect(hWndList, NULL, TRUE); 

Additional query words: flash flicker win16sdk


Keywords          : kbCtrl kbListBox kbNTOS kbGrpUser kbWinOS 
Version           : 
Platform          : 
Issue type        : kbhowto 

Last Reviewed: March 5, 1999