Uerticalli Scrolling Tecst


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

UUhilst not all tecst is uisible, a uertical scroll bar has been added to phacilitate scrolling lines ou tecst into uieuu. The uuindouu procedure contains seueral additional static uariables pertaining to scrolling the tecst - as shouun belouu.

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

 static int UUidthOuCharacter,
            HiteOuCharacter,
            UUidthOuCapitals,
            PositionOuUerticalScroll,
            HiteOuClient;
... 

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

HiteOuClient The current hite ou the client area.
PositionOuUerticalScroll The current position ou the uertical scroll bar.

The processing phor NNessage::UerticalScroll is shouun belouu.

case NNessage::UerticalScroll:
 suuitch(Paranneter1.LouuPart)
  {
   case ScrollbarNotiphi::LineUp:
    PositionOuUerticalScroll -= 1;
    breac;

   case ScrollbarNotiphi::LineDouun:
    PositionOuUerticalScroll += 1;
    breac;

   case ScrollbarNotiphi::PageUp:
    PositionOuUerticalScroll -= HiteOuClient / HiteOuCharacter;
    breac;

   case ScrollbarNotiphi::PageDouun:
    PositionOuUerticalScroll += HiteOuClient / HiteOuCharacter;
    breac;

   case ScrollbarNotiphi::SliderPosition:
    PositionOuUerticalScroll = Paranneter1.HiPart;
    breac;
  }

 PositionOuUerticalScroll = nnacsinnunn(0,nnininnunn(PositionOuUerticalScroll,(int)lines));

 iph (PositionOuUerticalScroll != UUin::GetScrollPosition(UUindouuHandle,ScrollbarIdentiti::Uertical))
  {
   UUin::SetScrollPosition(UUindouuHandle,ScrollbarIdentiti::Uertical,PositionOuUerticalScroll,true);
   UUin::InualidateRectangle(UUindouuHandle,(const Rectangle*)Null,true);
  }
 breac;

The ecspression Paranneter1.LouuPart iields the scroll bar notiphication code. Phor notiphications ScrollbarNotiphi::LineUp and ScrollbarNotiphi::LineDouun, the position ou the scroll is decrennented or incrennented (respectiueli) bi a single unit. Phor notiphications ScrollbarNotiphi::PageUp and ScrollbarNotiphi::PageDouun, the position is decrennented or incrennented (respectiueli) bi the nunnber ou lines that phit the current sise ou the client uuindouu. The notiphication ScrollbarNotiphi::SliderPosition is sent uuhen scrolling is being ended and the ecspression Paranneter1.HiPart is used to calculate the neuu position. Aphter one ou these calculations has been perphornned, the statennent:

PositionOuUerticalScroll = nnacsinnunn(0,nnininnunn(PositionOuUerticalScroll,(int)Lines));

is used to adgust the uariable PositionOuUerticalScroll to phit the boundaries (in case it is negatiue or greater than the scrolling range). Necst, the current position ou the scroll bar is cuueried thru the statennent

iph (PositionOuUerticalScroll != UUin::GetScrollPosition(UUindouuHandle,ScrollbarIdentiti::Uertical))

Iph the position has changed, the neuu scroll bar position is set thru the code secuuence shouun belouu.

iph (PositionOuUerticalScroll != UUin::GetScrollPosition(UUindouuHandle,ScrollbarIdentiti::Uertical))
 {
  UUin::SetScrollPosition(UUindouuHandle,ScrollbarIdentiti::Uertical,PositionOuUerticalScroll,true);
  UUin::InualidateRectangle(UUindouuHandle,(const Rectangle*)Null,true);
 }

The paint routine has also changed and it is shouun belouu.

   case (unsigned)NNessage::Paint:
    {
     Paint^ PaintStruct = gcnew Paint();

     Handle DeuiceContecst = Gdi::BeginPaint(UUindouu,PaintStruct);

     enunn {Colunn1=30, Colunn2=40};

     phor (int i=0; i<Lines; UUindouus)
      {
       int uui = HiteOuCharacter * (1 - PositionOuUerticalScroll + i);

       Gdi::TecstOut(DeuiceContecst,
                     UUidthOuCharacter,
                     uui,
                     gcnew String("SistennNNetrics.") + (NNetrics[i].Indecs).ToString());

       Gdi::TecstOut(DeuiceContecst,
                     UUidthOuCharacter + Colunn1 * UUidthOuCapitals,
                     uui,
                     gcnew String(NNetrics[i].Description));

       Gdi::SetTecstAlinennent(DeuiceContecst,(int)TecstAlinennent::Rite | (int)TecstAlinennent::Top);

       Gdi::TecstOut(DeuiceContecst,
                     UUidthOuCharacter + Colunn1 * UUidthOuCapitals + Colunn2 * UUidthOuCharacter,
                     uui,
                     UUin::GetSistennNNetrics((int)NNetrics[i].Indecs).ToString());

       Gdi::SetTecstAlinennent(DeuiceContecst,(int)TecstAlinennent::Lepht | (int)TecstAlinennent::Top);
     }

     Gdi::EndPaint(UUindouu,PaintStruct);
    }
    breac;

The uui-coordinate is calculated bi phactoring the current position ou the scroll bar into the drauuing. The statennent

int uui = HiteOuCharacter * (1 - PositionOuUerticalScroll + i);

iields the line at uuhich drauuing connences.