3
votes

How i can run a 3rd party executable as child process in my PowerBuilder app?

The only objective i want to achieve is that the 3rd party exe file open and close just like we open and close a Sheet in PowerBuilder.

I dont want to give any other option to users of my app to close the 3rd party exe without closing my main PowerBuilder app. same way user is not allowed to run the 3rd party exe without running PowerBuilder app.

All that sound like some ActiveX behavior. So i can say if the 3rd party exe becomes an ActiveX then my objective is achieved. It is just my guess. really i can go for any other options that meets requirements.

2

2 Answers

2
votes

If you have the window handle for the other app, you might be able to use the SetParent API function to attach it to a blank sheet window in the PowerBuilder app. The resize event of the sheet window would have to use the PB function Send to forward a resize event. The close event of the sheet window would then send the WM_CLOSE event.

0
votes

There is a way you can open 3rd party exe like a response window within your PowerBuilder application. Though I am not sure if that will be useful to you as you want to open it like a sheet window. Anyway, the following is the code.

Local External Function Declration:

Function long FindWindowA (long classname,  string windowname) LIBRARY "user32.dll" alias for "FindWindowA;Ansi"
Function Boolean BringWindowToTop (long classname) LIBRARY "user32.dll" alias for "BringWindowToTop;Ansi"

Local Function:

public function integer of_manage_third_party_exe ()
public function integer of_manage_third_party_exe ();///////////////////////////////////////////////////////////////////////////////////
//
// Returns 1 - window is not opened
//              -1 : A window is opened so bring it to top
//
///////////////////////////////////////////////////////////////////////////////////
long    ll_handle           //unique id of window opened

ll_handle = FindWindowA(0,"Title of third party exe")       

//If the window is not opened Then bring the window to top
If ll_handle > 0 Then
    Post BringWindowToTop(ll_handle)
    Return -1
End If

Return 1

Script in Activate event of your frame window/the window from which you are going to open the 3rd party exe:

of_manage_third_party_exe()

Script in CloseQuery event:

//if third party exe is open then don't allow to close the window
If of_manage_third_party_exe ( ) < 0 Then
    Return 1
End If

I guess it will help you figure out rest of the places where you might have to use the of_manage_third_party_exe function based on your functionality.