×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ShellExec to close a Website - possible?

ShellExec to close a Website - possible?

ShellExec to close a Website - possible?

(OP)
You can use a shellexec function to open any website.

But can you use a similar function to close the website again if, for example, you only want to look at the website for a moment. (e.g. wait window 5) ???

Of course you can manually click on the cross in the top right of the website with the mouse, but if you want to quickly look at several websites one after the other, it would be desirable to be able to do this automatically in an individual time sequence.

The function I use to open a web-page is this one:

CODE --> ShellExec

*Example:
*Source: Book with function by Rick Strahl "Internet Applications with VFp 6,0 - Page 194 edited 1999"

shellExec("https://www.google.com/search?client=firefox-b-d&q=aktienkurs+rheinmetall/")


FUNCTION ShellExec
LPARAMETERS lcLink,lcAction,lcParms

lcAction = IIF(EMPTY(lcAction), "Open",lcAction)
lcParms = IIF(EMPTY(lcParms),"",lcParms)

DECLARE INTEGER ShellExecute IN shell32.DLL ;
      INTEGER hWinHandle, ;
      STRING cOperation, ;
      STRING cFileName, ;
      STRING cParameters, ;
      STRING cDirectory, ;
      INTEGER nShowWindow

DECLARE INTEGER FindWindow ;
      IN WIN32API ;
      STRING cNull,STRING cWinname

RETURN ShellExecute(FindWindow(0,_Screen.Caption),;
                   lcAction,lcLink, ;
                   lcParms,SYS(2023),1) 



There is another effect - when you open too many internet-windows (means you let every site open) it would be better not to stretch the tabs across the windows, there could be too many then, or the memory will be overloaded.
This can be avoided you can do this in the browser settings - but then you have to change it back later because it is normally a sensible setting.

Thanks for help
Klaus


Peace worldwide - it starts here...

RE: ShellExec to close a Website - possible?

With ShellExecute you don't get hands on the started process. To have control over the browser you'd need to automate it, which only works with Internet Explorer, that's not a real option anymore.

To at least get hands on the Window you'd need to switch to CreateProcess. Not as easy as it sounds to switch from ShellExecute to CreateProcess. I'll get back to this after having a full example. In the meantime you can get an impression of how complex it will get from a ample of Rick Strahl: https://west-wind.com/wconnect/Weblog/ShowEntry.bl...

What you get with CreateProcess, that's not available with ShellExecute or RUN is a process handle. That can be used in several functions, one is TerminateProcess, i.e. what you want to do.

Quote (Klaus)

when you open too many internet-windows (means you let every site open) it would be better not to stretch the tabs across the windows, there could be too many then, or the memory will be overloaded.
Browsers will give tabs a minimum width, there's never the problem of too many tabs not being accessible. What is true is that browsers with too many open tabs become unresponsive. So sure, you better not open 100 tabs. Why would you? OPening a browser is something you only do to let a user look at it and work with it, one website at a time would be something I'd do. Why would you, say, opĆ¼en all URLs you know?

If you open all URLs to provcess them, don't open them in a browser, just use http requests to get the result page html and process that, there's no need to open a browser at all, if you want to do that.

Chriss

RE: ShellExec to close a Website - possible?

You can't do this with ShellExecute(). That's because ShellExecute() simply launches a program or URL. Once it has done that, VFP has no control over it.

You might be able to do it with Windows Scripting. Something like this:

CODE

* To launch the web page
lcTarget = "https://www.tek-tips.com/viewthread.cfm?qid=1829740"
lcWindow = "Firefox"   && a unique word from the browser's title bar

oSH = CREATEOBJECT("wscript.shell")
oSH.Run(lcTarget)

* When you are ready to close the web page
oSH.AppActivate(lcWindow)
* (you might need to put a short delay here to give
* the window time to activate)
osH.Sendkeys("^W")  && send Ctrl+W to close the tab 

This is just off the top of my head. I haven't tested it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ShellExec to close a Website - possible?

Hello,

in my lib I found a function which maybe able to do that if you have the windows handle.

CODE -->

Function killappbyhandle(tnHwnd)
  Declare Integer GetWindowThreadProcessId In win32API ;
    Integer HWnd, Integer @lpdwProcessId
  Declare Integer OpenProcess In Win32API ;
    integer dwDesiredAccess, Integer bInheritHandle, Integer dwProcessID
  Declare Integer TerminateProcess In Win32API ;
    integer hProcess, Integer uExitCode
  Local lnProcessId
  lnProcessId = 0
  GetWindowThreadProcessId(m.tnHwnd, @lnProcessId)
  Return TerminateProcess(OpenProcess(1, 1, m.lnProcessId), 0) > 0
Endfunc 


Regards
tom

RE: ShellExec to close a Website - possible?

This is to iterate through open windows and check for part of caption

CODE -->

Function api_getwindowbyname(cName)
  Local lnfound,lcBuffer,lnoldhwnd,lnhWnd,lnretval
  lnfound = findwindow(0,cName)
  If lnfound>0
    Return lnfound
  Endif

  lnoldhwnd = GetActiveWindow()
  lnhWnd = GetWindow(lnoldhwnd, 0) && First
  Do While lnhWnd <> 0
    lcBuffer = Replicate(Chr(0), 255)
    lnretval = GetWindowText(lnhWnd, @lcBuffer, Len(lcBuffer))
    If lnretval > 0 Then
      cBuffer =  Upper(Left(lcBuffer,lnretval))
      If !Empty(At(Upper(cName),cBuffer))
        lnfound = lnhWnd
        Exit
      Endif
    Endif
    lnoldhwnd = lnhWnd
    lnhWnd = GetWindow(lnoldhwnd, 2) && next
  Enddo
  Return lnfound
Endfunc 

RE: ShellExec to close a Website - possible?

(OP)
Mike Lewis,
I tested your code - it runs well.
Thank you.

Peace worldwide - it starts here...

RE: ShellExec to close a Website - possible?

(OP)

Quote (tomk3 -in my lib I found a function which maybe able to do that if you have the windows handle.)


What does it mean - if you have the windows handle?

Peace worldwide - it starts here...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close