home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / FOLEY / EXMETER.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-07  |  4KB  |  147 lines

  1. {$S-,R-,V-,I-,B-,F-,W-,A-,G+,X+}
  2.  
  3. {*********************************************************}
  4. {*                   EXMETER.PAS 1.00                    *}
  5. {*           Copyright (c) Brian Foley 1993.             *}
  6. {*                 All rights reserved.                  *}
  7. {*********************************************************}
  8.  
  9. program ExMeter;
  10.   {-Sample meter control application}
  11.  
  12. uses
  13.   WinTypes, WinProcs,
  14.   {$IFDEF Ver15}
  15.   wObjects,
  16.   {$ELSE}
  17.   OWindows, ODialogs,
  18.   {$ENDIF}
  19.   BWCC, Meter;
  20.  
  21.   {$IFDEF Ver10}
  22.     Error: This program does not work with TPW 1.0!
  23.   {$ENDIF}
  24.  
  25. {$R EXMETER.RES}
  26.  
  27. type
  28.   PMainWindow = ^TMainWindow;
  29.   TMainWindow = object(TDlgWindow)
  30.     Meter     : PMeterControl;
  31.     Text      : PStatic;
  32.     OKBtn     : PButton;
  33.     CancelBtn : PButton;
  34.  
  35.     constructor Init(AParent : PWindowsObject);
  36.     procedure Update(N : Word);
  37.   end;
  38.  
  39.   OurApplication = object(TApplication)
  40.     Count   : LongInt;
  41.     Percent : Byte;
  42.  
  43.     procedure InitMainWindow; virtual;
  44.     {$IFDEF Ver15}
  45.     procedure IdleAction; virtual;
  46.     {$ELSE}
  47.     function IdleAction : Boolean; virtual;
  48.     {$ENDIF}
  49.     procedure MessageLoop; virtual;
  50.   end;
  51.  
  52. var
  53.   OurApp : OurApplication;
  54.  
  55. {TMainWindow}
  56.  
  57.   constructor TMainWindow.Init(AParent : PWindowsObject);
  58.   begin
  59.     TDlgWindow.Init(AParent, 'EXMETER');
  60.  
  61.     {initialize control objects}
  62.     Text := New(PStatic, InitResource(@Self, 100, 30));
  63.     Meter := New(PMeterControl, InitResource(@Self, 101));
  64.     OKBtn := New(PButton, InitResource(@Self, id_OK));
  65.     CancelBtn := New(PButton, InitResource(@Self, id_Cancel));
  66.   end;
  67.  
  68.   procedure TMainWindow.Update(N : Word);
  69.   begin
  70.     if hWindow <> 0 then begin
  71.       {update meter value}
  72.       Meter^.SetMeterValue(N);
  73.  
  74.       {when we get to 100%, change the message and switch to the OK button}
  75.       if N = 100 then begin
  76.         Text^.SetText('Installation complete!');
  77.         ShowWindow(OKBtn^.hWindow, sw_Normal);
  78.         ShowWindow(CancelBtn^.hWindow, sw_Hide);
  79.  
  80.         {wm_NextDlgCtl works better than SetFocus in this situation}
  81.         SendMessage(hWindow, wm_NextDlgCtl, OKBtn^.hWindow, 1);
  82.       end;
  83.     end;
  84.   end;
  85.  
  86. {OurApplication}
  87.  
  88.   procedure OurApplication.InitMainWindow;
  89.   begin
  90.     MainWindow := New(PMainWindow, Init(nil));
  91.     Count := GetTickCount;
  92.     Percent := 0;
  93.   end;
  94.  
  95.   {$IFDEF Ver15}
  96.   procedure OurApplication.IdleAction;
  97.   {$ELSE}
  98.   function OurApplication.IdleAction : Boolean;
  99.   {$ENDIF}
  100.   begin
  101.     {$IFNDEF Ver15}
  102.     IdleAction := False;
  103.     {$ENDIF}
  104.     if Percent < 100 then begin
  105.       if GetTickCount >= Count+200 then begin
  106.         Inc(Percent);
  107.         PMainWindow(MainWindow)^.Update(Percent);
  108.         Count := GetTickCount;
  109.       end;
  110.       {$IFNDEF Ver15}
  111.       IdleAction := True;
  112.       {$ENDIF}
  113.     end;
  114.   end;
  115.  
  116.   procedure OurApplication.MessageLoop;
  117.   var
  118.     Message : TMsg;
  119.     IsDone  : Boolean;
  120.   begin
  121.     IsDone := False;
  122.     repeat
  123.       if PeekMessage(Message, 0, 0, 0, pm_Remove) then begin
  124.         if Message.Message = wm_Quit then
  125.           IsDone := True
  126.         else if not ProcessAppMsg(Message) then begin
  127.           TranslateMessage(Message);
  128.           DispatchMessage(Message);
  129.         end
  130.       end
  131.       else
  132.         {$IFDEF Ver15}
  133.         IdleAction;
  134.         {$ELSE}
  135.         if not IdleAction then
  136.           WaitMessage;
  137.         {$ENDIF}
  138.     until IsDone;
  139.     Status := Message.wParam;
  140.   end;
  141.  
  142. begin
  143.   OurApp.Init('EXMETER');
  144.   OurApp.Run;
  145.   OurApp.Done;
  146. end.
  147.