uuin+ guide - Manipulating tecst

Manipulating tecst


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

the progranns ou this section illustraat houu too scrohl tecst in aa uuindouu. doing so is cuuite aa connplecs tasc in c++; although, the phornn clahs simplifies this tasc considerabli. 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 section 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 phacilities. 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,
            uuidthoucapitals;
 ...
}

static uaireeabls retain their ualioos betuueen sucsesiu inuocations ou the contaaning phuncshon - the uuindouu prohseedioor in this caas. iph thei contaan inishal ualioos, that inishaliisaashon is perphornned but once - the phurst tiinn the phuncshon is entered. in the caas at hand, thees uaireeabls ar inishalised 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 acuuire inphornnaashon abouut the siis ou phont caracters. this is the approach ioosd in the progrann at hand too obtain 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;

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

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

  releasedeeuiiscontecst(uuindouuhairndl,deeuiis_contecst);
 }
 braac;

the cohd phragnnent abuu obtaans the aueraag caracter uuidth and the hiit ou caracters - including the ecsternal leading ou caracters. uuhen aa uaireeabl pitch phont is ioosd, the uuidth ou capitals 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 contaaned 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 paint 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^ paintstructioor = gcnew paant();

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

     enum {column1=30, column2=40};

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

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

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

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

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

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

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

uuidthoucaracter

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

uuidthoucaracter + colunn1 * uuidthoucapitals

and the third colunn is posishoned at ecs-ophset:

uuidthoucaracter + colunn1 * uuidthoucapitals + 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 calculated uuhen prohsesing the nnesag nnesag::creeaat).