This topic has not yet been rated - Rate this topic

WM_SETREDRAW message

Applies to: desktop apps only

An application sends the WM_SETREDRAW message to a window to allow changes in that window to be redrawn or to prevent changes in that window from being redrawn.

To send this message, call the SendMessage function with the following parameters.

SendMessage( 
  (HWND) hWnd,              
  WM_SETREDRAW,             
  (WPARAM) wParam,          
  (LPARAM) lParam            
);

Parameters

wParam

The redraw state. If this parameter is TRUE, the content can be redrawn after a change. If this parameter is FALSE, the content cannot be redrawn after a change.

lParam

This parameter is not used.

Return value

An application returns zero if it processes this message.

Remarks

This message can be useful if an application must add several items to a list box. The application can call this message with wParam set to FALSE, add the items, and then call the message again with wParam set to TRUE. Finally, the application can call RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN) to cause the list box to be repainted.

Note  RedrawWindow with the specified flags is used instead of InvalidateRect because the former is necessary for some controls that have nonclient area on their own, or have window styles that cause them to be given a nonclient area (such as WS_THICKFRAME, WS_BORDER, or WS_EX_CLIENTEDGE). If the control does not have a nonclient area, RedrawWindow with these flags will do only as much invalidation as InvalidateRect would.

If the application sends the WM_SETREDRAW message to a hidden window, the window becomes visible (that is, the operating system adds the WS_VISIBLE style to the window).

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Painting and Drawing Overview
Painting and Drawing Messages
RedrawWindow

 

 

Send comments about this topic to Microsoft

Build date: 3/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
SendMessage is mostly required
Hello

> unless you need to intercept this message for any reason, there is no need to call SendMessage()

This is definitely wrong.
There is the need to call SendMessage whenever you want to send a message to a window from another thread that is not the GUI thread!
SendMessage halts the calling thread sends the message, waits for the result, and resumes the calling thread.

Elmü
For win32/x64 programmers...
Since this operation is performed by Windows - and is almost certainly just a flag set - unless you need to intercept this message for any reason, there is no need to call SendMessage(), just call DefWindowProc() directly on the window with the same parameters. Not strictly good form but you bypass the SendMessage() queue and possibly several function calls.

See www.chrismillward.com/winprog.html?req=d9 for further discussion of bypassing the sent messages queue.
A piece of C# code
// Function import
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

// Constants
private const int WM_SETREDRAW = 0xB;
private const int FALSE = 0;
private const int TRUE = 1;

// Turn off redrawing
SendMessage(MyControl.Handle, WM_SETREDRAW, FALSE, 0);

// Your time consuming code here
// ...

// Turn on redrawing
SendMessage(MyControl.Handle, WM_SETREDRAW, TRUE, 0); 

// Cause the control to be repainted
MyControl.Invalidate();