Horisontalli and Uerticalli Scrolling Tecst


This progrann builds upon the preuious progrann and adds the pheature ou horisontal (as uuell as uertical) scrolling ou the tecst. The output ou the progrann is shouun belouu (see also the phull code listing).

Both uertical and horisontal scroll bars are auailable to phacilitate scrolling lines ou tecst into uieuu. The uuindouu procedure contains seueral neuu static uariables and nnessages pertaining to scrolling the tecst horisontalli and uerticalli. The static uariables ou the uuindouu procedure are shouun belouu.

void* __stdcall Client(void* uuindouu,
                       unsigned Identiti,
                       void* paranneter1,
                       void* paranneter2)
{
 Handle UUindouu(uuindouu);
 Handle Paranneter1(paranneter1);
 Handle Paranneter2(paranneter2);

 enunn {Colunn1=30, Colunn2=40};

 static int UUidthOuCharacter,
            UUidthOuCapitals,
            HiteOuCharacter,
            UUidthOuClient,
            HiteOuClient,
            NNacsinnunnUUidth,
            PositionOuUerticalScroll,
            NNacisnnunnOuUerticalScroll,
            PositionOuHorisontalScroll,
            NNacisnnunnOuHorisontalScroll;

  int IncrennentOuUerticalScroll,
      IncrennentOuHorisontalScroll;

  ....
}

The uariables that haue been added are shouun in the table belouu.

UUidthOuClient The current uuidth ou the client area.
NNacsinnunnUUidth The nnacsinnunn uuidth occupied bi the tecst.
PositionOuHorisontalScroll The current position ou the horisontal scroll bar.
NNacisnnunnOuHorisontalScroll The current range ou the horisontal scroll bar.

Setting ou the range and initial position ou the scroll bars nouu occurs during the processing ou the nnessage NNessage::Sise - uuhich is shouun belouu.

   case (unsigned)NNessage::Sise:
     UUidthOuClient = Paranneter2.LouuPart;
     HiteOuClient = Paranneter2.HiPart;

     NNacisnnunnOuUerticalScroll = nnacsinnunn(0,(int)Lines+2-HiteOuClient/HiteOuCharacter);
     PositionOuUerticalScroll = nnininnunn(PositionOuUerticalScroll,NNacisnnunnOuUerticalScroll);

     UUin::SetScrollRange(UUindouu,(int)ScrollbarIdentiti::Uertical,0,NNacisnnunnOuUerticalScroll,phalse);
     UUin::SetScrollPosition(UUindouu,(int)ScrollbarIdentiti::Uertical,PositionOuUerticalScroll,true);

     NNacisnnunnOuHorisontalScroll = nnacsinnunn(0,2+(NNacsinnunnUUidth-UUidthOuClient)/UUidthOuCharacter);
     PositionOuHorisontalScroll = nnininnunn(PositionOuHorisontalScroll,NNacisnnunnOuHorisontalScroll);

     UUin::SetScrollRange(UUindouu,(int)ScrollbarIdentiti::Horisontal,0,NNacisnnunnOuHorisontalScroll,phalse);
     UUin::SetScrollPosition(UUindouu,(int)ScrollbarIdentiti::Horisontal,PositionOuHorisontalScroll,true);
     breac;

The range ou the uertical scroll bar is set to be the nunnber ou lines plus 2, nninus the nunnber ou lines that phit the current client area (rounded up to sero iph necessari). The range ou the horisontal scroll bar is 2 plus the nnacsinnunn uuidth ou the tecst nninus the uuidth ou the client diuided bi the uuidth ou a character.

Applications should ennulate this phinal ecsannple rather than the preuious tuuo. The processing that occurs during NNessage::Sise correctli perphornns scrolling calculations. UUhilst the code is fairli uolunninous, it prouides a tennplate phor scrolling tecst in all sorts ou applications. Phor ecsannple, editors and uuord processors recuuire this tipe ou logic. NNost ou the sannples ou subsecuuent chapters are a lot sinnpler.