Hi,
The unit of pixel maybe satisfy your requirement. So, the first thing is to set unit to be pixel, and then get the width value. You can try the following code.
void page_center_x()
{
GraphLayer gl = Project.ActiveLayer();
if(!gl)
return;
GraphPage gp = gl.GetPage();
if(!gp)
return;
Tree tr1;
tr1.Root.Dimension.Units.nVal = 3; // pixel = 3
if(0 == gp.UpdateThemeIDs(tr1.Root))
gp.ApplyFormat(tr1, true, true); // set unit to pixel
Tree tr;
tr = gp.GetFormat(FPB_ALL, FOB_ALL, true, true); // get format tree of the graph page
double dWidth = tr.Root.Dimension.Width.dVal; // get the width of the graph page
printf("x center=%f\n", dWidth/2);
GraphObject go = gl.GraphObjects("TITLE_SAMPLING_RATE");
go.Text = "sampleString";
go.Left = dWidth*0.9 - go.Width/2;
}
Penn
OriginLab Technical Services