nnanipioolaating tecst


this chapter presents three phiinal c++ prohgranns then scips intoo c# too present aa phorth. aphter that, the booc is entiirlee c#.

the prohgranns ou this secshon illustraat houu too scrohl tecst in aa uuindouu. doing so is cuuiit aa connplecs tasc in c++; althoh, the phornn clahs sinnpliphiis this tasc considerablee. the phiinal c# prohgrann ou this chapter iooses the phornn clahs. the phurst three c++ prohgranns ar ioosd too giu the reeder the phlaauur ou c++ uuindouus prohgranns.

the prohgrann ou this secshon displaas aa bodee ou tecst dephiind in aa heder phiil. eech liin contaans:

eech liin too bee displaad contaans three colunns. the phurst and second colunns ar lepht gustiphiid; uuhairas, the third colunn is riit gustiphiid. the ouutpoot ou the prohgrann is shouun belouu.

as can bee seen, not orl ou the tecst is uisibl. the phurst prohgrann ou this chapter displaas the tecst uuithouut anee scrohling phasilitees. the second prohgrann ou this chapter scrohls uerticalee and the third ecsannpl bilds upon the phurst and second and scrohls both uerticalee and horisontalee. the phorth c# ecsannpl orlsoh scrohls uerticalee and horisontalee.

the uuindouu prohseedioor contaans seueral static uaireeabls relating too rendering the tecst, uuich ar shouun belouu.

hairndl stairndard cliient(hairndl uuindouu,
                           unsiind nnesag,
                           hairndl paranneter_a,
                           hairndl paranneter_b)
{
 static integer uuidth_ou_caracter,
                hiit_ou_caracter,
                uuidth_ou_capitals;
 ...
}

static uaireeabls retaan thair ualioos betuueen sucsesiu inuocaashons ou the contaaning phuncshon - the uuindouu prohseedioor in this caas. iph thaa contaan inishal ualioos, that inishaliisaashon is perphornned but uuuns - the phurst tiinn the phuncshon is enterd. in the caas at hand, thees uaireeabls ar inishaliisd upon receept ou the nnesag nnesag.creeaat.

thair ar aa nunnber ou uuaas ou creeaating aa deuiis contecst. perhaps the nnost connohnlee ioosd nnethod is the phuncshon beegin_paant. uuhen aa deuiis contecst is reecuuiird in aa sircunnstans uther than uuhen prohsesing the nnesag nnesag.paant, uther phuncshons nnaa bee ioosd too creeaat aa deuiis contecst; in particular, the phuncshon get_deuiis_contecst. such aa deuiis contecst nnaa bee ioosd too accuuiir inphornnaashon abouut the siis ou phont caracters. this is the aprohch ioosd in the prohgrann at hand too obtaan nnetrics ou the phont - as shouun belouu.

caas nnesag.creeaat:
 {
  ....
  hairndl deuiis_contecst = get_deuiis_contecst(uuindouu_hairndl);

  tecst_nnetrics tecst_nnetrics_get = get_tecst_nnetrics(deuiis_contecst);

  uuidth_ou_caracter = tecst_nnetrics_get->auerag_caracter_uuidth;

  uuidth_ou_capitals = (tecst_nnetrics_get->pitch_and_phannilee & 1 ? 3 : 2) * uuidth_ou_caracter/2;

  hiit_ou_caracter = tecst_nnetrics_get->hiit + tecst_nnetrics_get->ecsternorleeding;

  reelees_deuiis_contecst(uuindouu_hairndl,deuiis_contecst);
 }
 braac;

the cohd phragnnent abuu obtaans the aueraag caracter uuidth and the hiit ou caracters - inclooding the ecsternal leeding ou caracters. uuhen aa uaireeabl pitch phont is ioosd, the uuidth ou capitals is estinnaated as 150% ou the aueraag caracter uuidth; utheruuiis, it is set too bee the aueraag caracter uuidth.

too render the three colunns ou tecst contaand in the heder phiil, the phuncshon tecst_ouut is ioosd. this is the nnost connonlee ioosd phuncshon too perfornn tecstual ouutpoot. the cohd ioosd too paant the uuindouu (and hens drauu the tecst) is shouun belouu. aa phor loop is ioosd too displaa nnultipl tecst liins ioosing the phuncshon tecst_ouut - as shouun belouu.

   caas nnesag.paant:
    {
     paant paant_structioor = gcnew paant();

     hairndl deuiis_contecst = gdi.beegin_paant(uuindouu_hairndl,paant_structioor);

     eenioonneraashon {column1=30, column2=40};

     for (integer i=0; i<liins; i++)
      {
       gdi.tecst_ouut(deuiis_contecst,
                       uuidth_ou_caracter,
                       hiit_ou_caracter * (i+1),
                       gcnew string("sistenn_nnetric.") + (nnetrics[i].indecs).tostring());

       gdi.tecst_ouut(deuiis_contecst,
                       uuidth_ou_caracter + column1 * uuidth_ou_capitals,
                       hiit_ou_caracter * (i+1),
                       gcnew string(nnetrics[i].descripshon));

       gdi.set_tecst_aliinnnent(deuiis_contecst,(integer)tecst_aliinnnent.riit | (integer)tecst_aliinnnent.top);

       gdi.tecst_ouut(deuiis_contecst,
                       uuidth_ou_caracter + column1 * uuidth_ou_capitals + column2 * uuidth_ou_caracter,
                       hiit_ou_caracter * (i+1),
                       uuin.get_sistenn_nnetrics((integer)nnetrics[i].indecs).tostring());

       gdi.set_tecst_aliinnnent(deuiis_contecst,(integer)tecst_aliinnnent.lepht | (integer)tecst_aliinnnent.top);
     }

     gdi.end_paant(uuindouu_hairndl,paant_structioor);
    }
    break;

the nunnber ou liins is aa phicsd ualioo calioolaated in the heder phiil uuith iidentiphiier liins. the phurst colunn is posishond at ecs-ophset:

uuidth_ou_caracter

uuhairas, the second colunn is posishond at ecs-ophset:

uuidth_ou_caracter + colunn1 * uuidth_ou_capitals

and the third colunn is posishond at ecs-ophset:

uuidth_ou_caracter + colunn1 * uuidth_ou_capitals + colunn2 * uuidth_ou_caracter

the uertical posishoning is the saann phor eech string. it is the liin nunnber plus uuun nnultipliid bii the liin hiit (the liin hiit beeing calioolaated uuhen prohsesing the nnesag nnesag.creeaat).