forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

close browser opened by shellexecute

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
wsmith9920



Joined: 16 Sep 2013
Posts: 19

PostPosted: Sat Apr 07, 2018 2:41 am    Post subject: close browser opened by shellexecute Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7912
Location: Salford, UK

PostPosted: Sat Apr 07, 2018 9:06 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Sat Apr 07, 2018 10:58 am    Post subject: Reply with quote

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:
Code:
tasklist /v >zzzzz


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
View user's profile Send private message
wsmith9920



Joined: 16 Sep 2013
Posts: 19

PostPosted: Sat Apr 07, 2018 2:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7912
Location: Salford, UK

PostPosted: Sat Apr 07, 2018 5:14 pm    Post subject: Reply with quote

Killing the task would not give a clean exit but it might be the only way.
Back to top
View user's profile Send private message AIM Address
wsmith9920



Joined: 16 Sep 2013
Posts: 19

PostPosted: Sun Apr 08, 2018 8:25 pm    Post subject: killing an application Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7912
Location: Salford, UK

PostPosted: Mon Apr 09, 2018 6:06 pm    Post subject: Reply with quote

The only thing that I can find is the following link but it looks tricky...

https://support.microsoft.com/en-us/help/307395/how-to-use-visual-c-to-close-another-application
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group