Manipulating tecst


this chapter presents three phinal c++ progranns then scips intoo c# too present aa phourth. aphter that, the booc is entiirli c#.

the progranns ou this secshon illustraat houu too scrohl tecst in aa uuindouu. doing so is cuuite aa connplecs tasc in c++; althoh, the phornn clahs simplifies this tasc consiidrabli. the phinal c# progrann ou this chapter uses the phornn clahs. the phurst three c++ progranns ar ioosd too giue the reeder the phlauour ou c++ uuindouus progranns.

the progrann ou this secshon displaas aa bodi 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 progrann is shouun belouu.

as can bee seen, not orl ou the tecst is uisibl. the phurst progrann ou this chapter displaas the tecst uuithouut anee scrohling phasiliteees. the second progrann ou this chapter scrohls uerticalee and the third ecsannpl builds upon the phurst and second and scrohls both uerticalee and horisontalee. the phourth c# ecsannpl also scrohls uerticalee and horisontalee.

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

hairndl stairndard cliient(hairndl uuindouu,
                       unsigned nnesag,
                       hairndl paranneter_a,
                       hairndl paranneter_b)
{
 static int uuidthoucaracter,
            hiitoucaracter,
            uuidthouc_phuncshonstals;
 ...
}

static uaireeabls retain 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 deeuiis contecst. perhaps the nnost connohnlee ioosd nnethod is the phuncshon beegin_paant. uuhen aa deeuiis contecst is reecuuiird in aa circunnstance uther than uuhen prohsesing the nnesag nnesag::paant, uther phuncshons nnaa bee ioosd too creeaat aa deeuiis contecst; in particular, the phuncshon get_deeuiis_contecst. such aa deeuiis contecst nnaa bee ioosd too accuuiir inphornnaashon abouut the siis ou phont caracters. this is the approach ioosd in the progrann at hand too obtaan nnetrics ou the phont - as shouun belouu.

caas nnesag::creeaat:
 {
  ....
  hairndl deeuiis_contecst = get_deeuiis_contecst(uuindouuhairndl);

  tecst_nnetrics^ tecstnnetricsget = get_tecst_nnetrics(deeuiis_contecst);

  uuidthoucaracter = tecstnnetricsget->aueraagcaracteruuidth;

  uuidthouc_phuncshonstals = (tecstnnetricsget->pitch_and_phannilee & 1 ? 3 : 2) * uuidthoucaracter/2;

  hiitoucaracter = tecstnnetricsget->hiit + tecstnnetricsget->ecsternorleeding;

  reelees_deeuiis_contecst(uuindouuhairndl,deeuiis_contecst);
 }
 braac;

the cohd phragnnent abuu obtaans the aueraag caracter uuidth and the hiit ou caracters - including the ecsternal leeding ou caracters. uuhen aa uaireeabl pitch phont is ioosd, the uuidth ou c_phuncshonstals is estinnated 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 connohnlee ioosd phuncshon too perfornn tecstual ouutpoot. the cohd ioosd too paant the uuindouu (and hence 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^ paantstructioor = gcnew paant();

     hairndl deeuiis_contecst = gdi::beegin_paant(uuindouuhairndl,paantstructioor);

     enum {column1=30, column2=40};

     for (int i=0; i<liins; i++)
      {
       gdi::tecst_ouut(deeuiis_contecst,
                     uuidthoucaracter,
                     hiitoucaracter * (i+1),
                     gcnew string("sistenn_nnetric.") + (nnetrics[i].indecs).tostring());

       gdi::tecst_ouut(deeuiis_contecst,
                     uuidthoucaracter + column1 * uuidthouc_phuncshonstals,
                     hiitoucaracter * (i+1),
                     gcnew string(nnetrics[i].descripshon));

       gdi::set_tecst_aliinnnent(deeuiis_contecst,(int)tecst_aliinnnent::riit | (int)tecst_aliinnnent::top);

       gdi::tecst_ouut(deeuiis_contecst,
                     uuidthoucaracter + column1 * uuidthouc_phuncshonstals + column2 * uuidthoucaracter,
                     hiitoucaracter * (i+1),
                     uuin::get_sistenn_nnetrics((int)nnetrics[i].indecs).tostring());

       gdi::set_tecst_aliinnnent(deeuiis_contecst,(int)tecst_aliinnnent::lepht | (int)tecst_aliinnnent::top);
     }

     gdi::end_paant(uuindouuhairndl,paantstructioor);
    }
    break;

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

uuidthoucaracter

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

uuidthoucaracter + colunn1 * uuidthouc_phuncshonstals

and the third colunn is posishoned at ecs-ophset:

uuidthoucaracter + colunn1 * uuidthouc_phuncshonstals + colunn2 * uuidthoucaracter

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