How Pure Basic catches an application close event?

Windows specific forum
cecilcheah
Enthusiast
Enthusiast
Posts: 168
Joined: Wed Jun 04, 2003 8:44 am
Location: Switzerland

How Pure Basic catches an application close event?

Post by cecilcheah »

Hi there

How can Pure Basic knows if an external Programme is closed?

What i want to do is, use Pure Basic to add as a bridge of communicatzion between two programme. One application will send text strings to a second applicatzion on starting my small pure basic application. And when the second application is closed, the text string from a text field in the second application will be copied back to the first application. Pure basic will have to know when the user closes the application and catches the text string in the second applicatio to send back to the first before the second application is closed.

So my question is how can Pure Basic know when the user closes the second application?

Thanks in advance

Cecil
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How Pure Basic catches an application close event?

Post by PB »

> How can Pure Basic knows if an external Programme is closed?

If the external app has a static (non-changing) window title, you could
periodically check to see if it's still open. Start Notepad, then run this
to see what I mean:

Code: Select all

Repeat : Sleep_(1) : Until FindWindow_(0,"Untitled - Notepad")=0
Debug "Notepad has just closed!"
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

If I understand right, you need to know when the second app is about to
be closed, but still open, in order to read the string, is that corerect?

I don't know if that is possible.

However, starting an app from PureBasic, and finding out, if it has ended
(by the time it allready has ended) is easy:

Code: Select all

 ; when starting the app
ProcessId = Runprogram(...)
;
; in your loop
GetExitCodeProcess_(ProcessID, @ExitCode.l)
If ExitCode <> #STATUS_PENDING
  ;
  ; the app has closed
  ;
EndIf
Therefore, the app doesn't need any windows, but you have to start it
with RunProgram(), and the problem is, you can't take any actions on
that program anymore, because it allready ended.

Timo
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

>If I understand right, you need to know when the second app is about to
> be closed, but still open, in order to read the string, is that corerect?

You're right -- I didn't notice (at first) that cecilcheah needs to read a text
gadget from the second app before it closes. So... why not just use my tip
and periodically poll the text gadget, so that when it closes, you'll know the
gadget's final text?
Post Reply