View previous topic :: View next topic |
Author |
Message |
wsmith9920
Joined: 16 Sep 2013 Posts: 19
|
Posted: Sat Apr 07, 2018 2:41 am Post subject: close browser opened by shellexecute |
|
|
I can successfully open my default browser by using the winapi function "ShellExecute" in my fortran application. Using the winapi function GetActiveWindow I can get the handle to the browser window and manipulate it as needed. Does anyone know a way either in fortran or via the winapi to close the browser window once it is no longer needed? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8003 Location: Salford, UK
|
Posted: Sat Apr 07, 2018 9:06 am Post subject: |
|
|
I don't know of a method to close a remote application. The DestroyWindow function will not work (according to the documentation). You might be able to use SendMessage with WM_CLOSE (the documentation does not say that this doesn't work).
If you have the time and interest, you can create your own browser (that accesses the Microsoft engine) by calling winio@ and using %wb. See ftn95.chm for details. |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2852 Location: South Pole, Antarctica
|
Posted: Sat Apr 07, 2018 10:58 am Post subject: |
|
|
Current Fortran actually is so powerful and useful even for such tasks so that the people who use only C/C++ are often left in the dust.
I think we discussed this around 10 years ago, try to Search, here was great patriot of Fortran John Horspool who suggested it, Eddie also contributed. I used it to monitor if some EXEs are running to stop them. It will find PID of your browser process in Control Panel and delete the job.
The idea is simple as 2x2: try in Command Prompt this to get the idea what's to do:
This will produce you file zzzzz containing all running processes. Your Fortran code will do that for you, then read zzzzz file, then find the browser PID and then execute another command which will stop specific PID
Code: | taskkill /F /pid XXXX |
where XXXX is Browser's PID from the file zzzzzz
UPDATE:
here is the link with the full demo:
http://forums.silverfrost.com/viewtopic.php?t=1100&highlight=process |
|
Back to top |
|
|
wsmith9920
Joined: 16 Sep 2013 Posts: 19
|
Posted: Sat Apr 07, 2018 2:17 pm Post subject: |
|
|
Paul: Thank you. You are right: I had already tried DestroyWindow and SendMessage (WM_Close) before I posted. Neither worked. DanRRight: thanks, I'll give that a try. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8003 Location: Salford, UK
|
Posted: Sat Apr 07, 2018 5:14 pm Post subject: |
|
|
Killing the task would not give a clean exit but it might be the only way. |
|
Back to top |
|
|
wsmith9920
Joined: 16 Sep 2013 Posts: 19
|
Posted: Sun Apr 08, 2018 8:25 pm Post subject: killing an application |
|
|
DanRRight: Thanks for the tip. I found the original post you had included, it was very easy to program in Fortran, works just fine.
Paul: After a kill, chrome complains the next time it is opened, but without harming what I need to get accomplished the next time I call in in fortran. Now that I have Dan's method up and running, is there a more "gentle" way to exit a program, given I have the correct process ID?? I assume "kill" is identical to hitting the "X" window button on the upper right? |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8003 Location: Salford, UK
|
|
Back to top |
|
|
|