Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've seen people who've written in code where the graphics of a scene are rendered in response to WM_PAINT. I only ever rendered the scene once all Windows messages were done translating, and then rendered the scene. Is this the wrong way to go about it, or should I only use DirectX rendering in response to WM_PAINT?

share|improve this question
I believe WM_PAINT is used so that the scene is rendered on all special updates (like maximize, resize, etc.) although I'm not sure. – Jonathan Connell May 30 '11 at 11:15
up vote 5 down vote accepted

WM_PAINT response code is a convenient place to put rendering routines, especially when rendering in a window, but I believe - it is not the best.

WM_PAINT message is recieved by window message loop when system wants to update its contents, eg. during moving or resising window or when window content is showed again due to closing other overlapping window. Rendering in response to WM_PAINT assures that rendered content stays accurate. It is up to programmer to assure that WM_PAINT is posted to window's message queue often enough, to keep up to the desired rendering framerate. It can be achieved by calling

BOOL InvalidateRect(__in  HWND hWnd, __in  const RECT *lpRect, __in  BOOL bErase);


It is not necessary to do it that way, as in fact- posting and processing window messages can introduce a significant delay to rendering pipeline.

Better way is to call rendering routines from the message loop itself, something like this:

BOOL done = false;
while (!done)
    if (PeekMessage(&msg, wnd, 0, 0, false))
        int result = GetMessage(&msg, wnd, 0, 0);

        if (result == -1)
             // process GetMessage() error
             if (msg.message == WM_QUIT)
                 done = true;


share|improve this answer
Thanks! This clarifies a lot. – DeadMG May 30 '11 at 20:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.