Handle Window Movement

Any DirectX application that runs in a window must track the position of the client area for the window so that blits to the window will appear on the desktop in the right place. Failing to track this results in graphics appearing outside the application window—a confusing sight for the user. The Triangle sample responds to the WM_MOVE messages that the system sends to the window procedure as shown here:

 .
 .
 .
    case WM_MOVE:
        // Move messages need to be tracked to update the screen rects
        // used for blitting the backbuffer to the primary.
        if( g_bActive && g_bReady )
            OnMove( (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam) );
        break;
 . 
 .
 .

The g_bActive variable is set elsewhere in the window procedure to reflect whether or not the window is active—when the window is minimized it's set to FALSE. The g_bReady variable is TRUE except when the application is in the midst of re-creating the DirectX objects it uses. If these variables are both TRUE, the OnMove application-defined function gets called:

VOID OnMove( INT x, INT y )
{
    DWORD dwWidth  = g_rcScreenRect.right - g_rcScreenRect.left;
    DWORD dwHeight = g_rcScreenRect.bottom - g_rcScreenRect.top;
    SetRect( &g_rcScreenRect, x, y, x + dwWidth, y + dwHeight );
}
 

This function simply recalculates the size of the global variable, g_rcScreenRect, that the tutorial uses as the destination rectangle when it updates the display in Step 5.3: Update the Display.