Listing 3 GDI+ code to shift the origin to the center of the window
RECT rect; GetClientRect(hwnd, &rect); float xOrigin = 0.5f * (rect.right - rect.left)/ (graphics.GetDpiX() * graphics.GetPageScale()); float yOrigin = 0.5f * (rect.bottom - rect.top)/ (graphics.GetDpiY() * graphics.GetPageScale()); graphics.TranslateTransform( xOrigin, yOrigin, MatrixOrderAppend); // Draw a 1 inch box with a gradient pen LinearGradientBrush grad( PointF(-50.0f, 0.0f), PointF(50.0f, 0.0f), Color(255, 255, 0, 0), Color(255, 0, 0, 255)); // 1 inch square, centered on the origin graphics.FillRectangle(&grad, -50, -50, 100, 100);