home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / mswindo / programm / misc / 3285 < prev    next >
Encoding:
Internet Message Format  |  1992-11-08  |  3.3 KB

  1. Path: sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!levels!ccdps
  2. Newsgroups: comp.os.ms-windows.programmer.misc
  3. Subject: Detecting termination of an Exec'ed program
  4. Message-ID: <19146.2af4e329@levels.unisa.edu.au>
  5. From: ccdps@levels.unisa.edu.au
  6. Date: 2 Nov 92 08:13:29 +1030
  7. Organization: University of South Australia
  8. Lines: 114
  9.  
  10. Program TestExitTask;
  11.  
  12. {
  13.    This short TPW 1.5 program installs a callback that does a MessageBeep every
  14.    time a task exits. What I want it to do, however, is beep only when
  15.    a particular task exits, which is trickier. When this program works, it
  16.    will provide a framework for utilities that launch an application and
  17.    then wait for it to finish. My immediate need is for our LAN; we need to
  18.    be able to unlink a network drive when the program is finished, thus taking
  19.    one network copy out of use. (ie, a kind of batch file for Windows.)
  20.  
  21.    The global variable that holds the taskid I am looking for is always
  22.    0, and so is the dwData that is passed to the callback. I don't know
  23.    why this is. I am using the far memory model.
  24.  
  25.    Any ideas? This is a Frequently Unanswered Question which goes past
  26.    regularly, and this is the second posting I have made (just in case...
  27.    sorry if I got you twice!)
  28.  
  29.    Many, many thanks,
  30.  
  31.    --
  32.    Dan Shearer                        email: Dan.Shearer@UniSA.edu.au
  33.    Information Technology Branch      Phone: +61 8 302 3479
  34.    University of South Australia      Fax  : +61 8 302 3385
  35.  
  36. [ BTW LAN Manager 2.1 Programmers Toolkit available from comlab.gatech.edu ]
  37.  
  38. }
  39.  
  40. {$F+}  {Far model - Needed for global hTaskTest to be available to callback.}
  41.  
  42.  
  43. uses
  44.    {TPW Units}
  45.    WObjects, strings, WinProcs, WinTypes, Win31, ToolHelp;
  46.  
  47. type
  48.   PTaskTestApp = ^TTaskTestApp;
  49.   TTaskTestApp = object(TApplication)
  50.     procedure InitMainWindow; virtual;
  51.   end;
  52.  
  53. var
  54.   hTestTask : THandle;
  55.  
  56. {This is the callback installed by a NotifyRegister}
  57. function CheckTask(wId:Word; dwData:longint) : Bool;
  58.  
  59. begin
  60.   if wID = NFY_EXITTASK then begin
  61.     if THandle(dwData)=hTestTask then begin
  62.       MessageBeep(MB_ICONEXCLAMATION);
  63.     end;
  64.     CheckTask := TRUE;
  65.     end;
  66.   end else begin
  67.     CheckTask := FALSE;
  68.   end;
  69. end; {CheckTask}
  70.  
  71. {Spawns NOTEPAD}
  72. function Execute : boolean;
  73. var
  74.   PText,PCaption,PAppPath : PChar;
  75.   AppInstance : THandle;
  76.   lpTask : PTaskEntry;
  77.   Result : Integer;
  78.   AppPath : String;
  79.   ExecuteVal : boolean;
  80.  
  81. begin
  82.   GetMem(PAppPath,64);
  83.   AppPath := 'NOTEPAD.EXE';
  84.   StrPCopy(PAppPath,AppPath);
  85.   ExecuteVal := TRUE;
  86.   AppInstance := THandle(WinExec(PAppPath,SW_SHOWNORMAL));
  87.   if AppInstance < HINSTANCE_ERROR then begin
  88.     GetMem(PText,40);
  89.     GetMem(PCaption,40);
  90.     PText := 'Error loading program';
  91.     PCaption := 'TaskTest Error';
  92.     MessageBox(0,PText,PCaption,1);
  93.     ExecuteVal := FALSE;
  94.   end; {if WinExec unsuccessful}
  95.   hTestTask := AppInstance;
  96.   Execute := ExecuteVal;
  97. end; {Execute}
  98.  
  99.  
  100. procedure TTaskTestApp.InitMainWindow;
  101. var
  102.   CheckTaskProc: TFarProc;
  103.   NotifyProc: TNotifyCallback;
  104.  
  105. begin
  106.   MainWindow := New(PWindow, Init(nil, 'Exit Task Tester'));
  107.   CheckTaskProc := MakeProcInstance(@CheckTask,HInstance); {HInstance means this app}
  108.   NotifyProc := TNotifyCallBack(CheckTaskProc);
  109.   NotifyRegister(THandle(0),NotifyProc,NF_NORMAL);
  110.   if not Execute then begin
  111.   end;
  112. end; {TTestTaskApp.InitMainWindow}
  113.  
  114.  
  115.  
  116. var
  117.   MyApp : TTaskTestApp;
  118.  
  119. begin
  120.   MyApp.Init('TaskTest');
  121.   MyApp.Run;
  122.   MyApp.Done;
  123. end.
  124.