Here's a routine that prints text in a window, centered between two x-coordinates:
myWindow::WriteCenteredText(int x1, int x2, int y, string s),void
{
ÂÃ, // x1 is the leftmost limit, x2 the rightmost; y the distance from top
ÂÃ, int offset;
ÂÃ, point myPoint;
ÂÃ, myPoint = GetTextSize(s);ÂÃ, Ã‚Ã, Ã‚Ã, Ã‚Ã, Ã‚Ã, Ã‚Ã, // width of string
ÂÃ, offset = (x2 - x1 - myPoint.x) / 2;ÂÃ, // offset from x1
ÂÃ, WriteText(x1 + offset, y, s);
ÂÃ, return;
}
You can use GetClientRect() to find x1 and x2 for the window itself. I use this routine to center text under an image and to redraw text centered in a window when the window is resized.