Announcement

Collapse
No announcement yet.

Sensing when a handle is no longer active

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sensing when a handle is no longer active

    After an asynchronous SHELL to another app in Windows 95, how can I detect when the app is no longer executing/active?

    MyHandle = SHELL(pgm)

    e.g. is there an Api I can use to see if "MyHandle" is no longer active?

    TIA

  • #2
    The GetExitCodeProcess API will return %STILL_ACTIVE (&h0103&) as long as an app is running, but you need the Process Handle to use it and the PB/DLL docs say that the SHELL function returns an Instance Handle. There may be an API to get the Process Handle from an Instance Handle... I can't remember. If you can't figure out how to do it, it might be easier to use CreateProcess instead of SHELL, since CreateProcess returns a Process Handle directly.

    Or, if the app that you are trying to detect has (or can have) a unique string in its title bar, you could use the FindWindow API function to see if the window still exists.

    -- Eric

    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited May 11, 2000).]
    "Not my circus, not my monkeys."

    Comment


    • #3
      I just performed a quick test and it appears that the PB/DLL SHELL function returns a Process ID, not an Instance Handle. I have posted a message containing a sample program in the Source Code Forum.

      -- Eric

      ------------------
      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>

      "Not my circus, not my monkeys."

      Comment


      • #4
        Simple alternative - thread
        Code:
           #Compile Exe
           #Register None
           #Dim All
           #Include "Win32Api.inc"
           Global hDlg As Long
           Function MyThread (ByVal x As Long) As Long
              Shell "Notepad.Exe"
              Control Set Text hDlg, 101, "Finished"
           End Function
           Function PbMain () As Long
              Local x As Long, idThread As Long
              Thread Create MyThread(x) To idThread
              Thread Close idThread To idThread
              Dialog New 0, "Hello",,, 200, 80, %WS_SYSMENU, %WS_EX_TOPMOST To hDlg
              Control Add TextBox, hDlg, 101, "", 10, 10, 180, 50
              Dialog Show Modal hDlg
           End Function
        ------------------

        Comment


        • #5
          Thank you Semen - because of my circumstances, your tip did the trick exactly. I needed to make a conditional DOS window close after running a Win95 utility (sometimes it appears, sometimes not), and the extra thread did the trick perfectly.

          ------------------

          Comment

          Working...
          X