Closing an .exe window (OpenInsight 32-Bit)
At 27 JAN 2009 04:23:36AM Barry Stevens wrote:
I am trying to test being able to run an executable flash show, then be able to close it (with the purpose of being able to start another after a set period of time)
Here is my testing code and the flash is not closing.
What am I doing wrong OR how should I be doing it.
RetVal=utility("RUNWIN","C:\FlashShow.exe")
Handle=RetVal
Equ WM_CLOSE$ to 0x0010
delay(5)
x= sendmessage(Handle,WM_CLOSE$,0,0)
At 27 JAN 2009 12:53PM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
Barry,
There are no window handles in any of the values returned from the RUNWIN method, so there's no way to use the SendMessage API call.
What you're actually trying to use there is the primary thread ID, not a window handle. The information returned from RUNWIN is:
Full path to the calling application
Instance handle
Process ID
Thread ID
The last two are incorrectly documented in the OI online help - I believe they refer to the old 16-bit information.
Because you have the Thread ID you could try using the PostThreadMessage() API call (See the MS docs for more details) and post a WM_QUIT message to it. This *might* work but I can't say I've tried it, and you may find interprocess security getting in the way.
Another way is to enumerate all the windows owned by the thread in question which should get you a window handle so you can then use the SendMessage API function. However, this involves more work as you would have to use the EnumThreadWindows() function which involves creating a callback function - this is not widely documented in OI, though I believe Bob C posted something similar on this board at some point in the past regarding the EnumWindows function.
a href=http://www.sprezzatura.com]The Sprezzatura Group
At 27 JAN 2009 12:54PM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
Helps if you don't forget to add the opening tag eh?
At 27 JAN 2009 01:43PM Bob Carten wrote:
Native callbacks were added in 2005. I posted an example ( thanks to Pat McNerthney )
See:
That posting also illustrates how to mess up embedded html. Seems to be a common problem these days :)
At 27 JAN 2009 05:24PM Barry Stevens wrote:
Cool.
I looped through the handles using GetWindowText looking for "Flash Player" and 'closed' the handle of each one I found. It worked
Thank you very much.
At 29 JAN 2009 07:55AM Barry Stevens wrote:
Is the any windows 'memory freeing function' that should be called if this routine is being called repeatedly throught the day.
I am also using these in the same routine that calls the above.
GetWindowText
GetWindowTextLength
At 29 JAN 2009 04:59PM Bob Carten wrote:
Is the any windows 'memory freeing function' that should be called if this routine is being called repeatedly throught the day
I don't know.
I bet that the CreateCallbackfunction hold a structure in memory, either until the program ends or until the engine closes. try puttin the callback into a common variable, e.g
common /callback_com/callback
if assigned(callback) else
callback=CreateCallback(...)end
If OI kills the callback at the end of the program, then this will fail (dramatically, I bet) the second time you call it. If you are able to re-use the callback between calls, then you know OI holds pointer for the life of the session and that you should use a common to avoid chewing up memory. If you cannot use the common, tehn you know OI cleans it up at the end of the program call and you don't need to worry.
- Bob