0 out of 5 rated this helpful - Rate this topic

WM_NCPAINT message

Applies to: desktop apps only

The WM_NCPAINT message is sent to a window when its frame must be painted.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
  HWND hwnd, 
  UINT  uMsg, 
  WPARAM wParam, 
  LPARAM lParam     
);

Parameters

wParam

A handle to the update region of the window. The update region is clipped to the window frame.

lParam

This parameter is not used.

Return value

An application returns zero if it processes this message.

Remarks

The DefWindowProc function paints the window frame.

An application can intercept the WM_NCPAINT message and paint its own custom window frame. The clipping region for a window is always rectangular, even if the shape of the frame is altered.

The wParam value can be passed to GetDCEx as in the following example.



case WM_NCPAINT:
{
    HDC hdc;
    hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
    // Paint into this DC 
    ReleaseDC(hwnd, hdc);
}


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
DefWindowProc
GetWindowDC
WM_PAINT
GetDCEx

 

 

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
painting close button
I need close (X) button in the titlebar of a window but without sysmenu. So I draw a bitmap representing this button on this event and on event WM_NCACTIVATE. On Windows XP it works with no problems but on Windows 7 it doesn't work at all. Can anybody help me ? Thnx
wParam doesn't contain Region at all
You have to clip nonclient area with GetClientRect and ExcludeClipRect yourself.
wParam == 1
When wParam == 1, entire NC area has to be updated.
WM_NCPAINT and GetDCEx()
Getting the device context when handling WM_NCPAINT does not work as described. Additional undocumented flag 0x10000 has to be used:

case WM_NCPAINT:
{
HDC hdc;
hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW | DCX_INTERSECTRGN | 0x10000);
// Paint into this DC
ReleaseDC(hwnd, hdc);
}

(Verified on Windows XP)