Unit PercentCtrl;
Interface
  Uses WinTypes, WinProcs, WObjectB;

  type
    PPercentCtrl = ^TPercentCtrl;
    TPercentCtrl = object (TControl)
                     function  GetClassName:  PChar;                    virtual;
                     procedure Add(Pct:  integer);
                     function  Percent:  integer;
                     procedure SetIt(Pct:  integer);
                     procedure Reset;
                   end;

  procedure CenterPopup(HWindow:  HWnd; DC:  HDC);

Implementation

  const
    Pct_Decades :  longint = $01;	{ Place tick marks & % values every 10% }
    Pct_Quarters:  longint = $02;	{ Place tick marks & % values every 25% }
    Pct_Halves  :  longint = $04;	{ Place tick marks & % values every 50% }
    Pct_Axis    :  longint = $08;	{ Draw the tick marks on the control }
    Pct_Digits  :  longint = $10;	{ Draw the percentage in the middle of the control }

    Pct_Name = 'PercentCtrl';		{ Class name for the new control }

			{ Define window messages }

    pcm_ResetPercent = wm_User + 1;	{ Message to cause control to reset % to 0 }
    pcm_AddPercent   = wm_User + 2;	{ Message to cause control to add x % }
    pcm_GetPercent   = wm_User + 3;	{ Message to cause control to return its current setting }
    pcm_SetPercent   = wm_User + 4;	{ Message to cause control to set itself to x% }
					{ Control Style Dialog box identifiers }
    PctMask:  longint = $FFFFFFF8;

  procedure CenterPopup(HWindow:  HWnd; DC:  HDC); external 'CtrlDLL';

  function TPercentCtrl.GetClassName:  PChar;
    begin       { TPercentCtrl.GetClassName }
      GetClassName := Pct_Name
    end         { TPercentCtrl.GetClassName };

  procedure TPercentCtrl.Add(Pct:  integer);
    begin       { TPercentCtrl.Add }
      SendMessage(HWindow, pcm_AddPercent, Pct, 0)
    end         { TPercentCtrl.Add };

  function TPercentCtrl.Percent:  integer;
    begin       { TPercentCtrl.Percent }
      Percent := LoWord(SendMessage(HWindow, pcm_GetPercent, 0, 0))
    end         { TPercentCtrl.Percent };

  procedure TPercentCtrl.SetIt(Pct:  integer);
    begin       { TPercentCtrl.SetIt }
      SendMessage(HWindow, pcm_SetPercent, Pct, 0);
    end         { TPercentCtrl.SetIt };

  procedure TPercentCtrl.Reset;
    begin       { TPercentCtrl.Reset }
      SendMessage(HWindow, pcm_ResetPercent, 0, 0);
    end         { TPercentCtrl.Reset };

  end.
