I have a Problem when drawing with the MFC CDC class and the LineTo and MoveTo function. The CDC Object doesn't begin at the point where I move the Pointer and leaves the first Pixel blanc like in the center of the image. When I draw around a corner like on the left side of the image it is clear that the CDC object leaves the outmost pixel free. I did try to load a custom brush but had no different results.
memDC.FillSolidRect(client, BACKGROUND_COLOR);
CPen penBorder(PS_ENDCAP_SQUARE | PS_SOLID, BORDER_WIDTH, BORDER_COLOR);
//Draw the Horizontal line for the Status Bar
CPen* oldPen = memDC.SelectObject(&penBorder);
memDC.MoveTo(client.left + 0.5f * BORDER_WIDTH, client.top + 0.5f * BORDER_WIDTH);
memDC.LineTo(client.Width() - 0.5f * BORDER_WIDTH, client.top + 0.5f * BORDER_WIDTH);
CPen penRecess(PS_ENDCAP_SQUARE | PS_SOLID, BORDER_WIDTH, RECESS_COLOR);
//Draw the recess
memDC.SelectObject(&penRecess);
memDC.MoveTo(client.left + 1.5f * BORDER_WIDTH, client.top + 1.5f * BORDER_WIDTH);
memDC.LineTo(client.Width() - 0.5f * BORDER_WIDTH, client.top + 1.5f * BORDER_WIDTH);
The problem has nothing to do with MFC but is inherent in the underlying Windows GDI function. The documentation for LineTo
says:
The LineTo function draws a line from the current position up to, but not including, the specified point.
If you need the last point drawn, you should do a second LineTo
one pixel away from the first.