Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Call a URL from the VFP 9 app?
Message
 
 
To
14/01/2021 15:50:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01677841
Message ID:
01677848
Views:
53
>>>>>>Hi,
>>>>>>
>>>>>>How would you write a code to call a URL from the VFP application? As if a user clicked on this URL. Specifically, I want to create a small PRG to call a URL every 1 or 2 minutes? Basically a FOR loop and then call this URL?
>>>>>>
>>>>>>How would you do it?
>>>>>>
>>>>>>TIA
>>>>>
>>>>>If you just want to retrieve the contents of a URL then I suggest getting a quality comms library. I use Chilkat from https://www.chilkatsoft.com/ - they have a great, feature rich libary and great support. Excecllent help documentation complete with VFP examples that you can just copy/paste in to your own apps. Can try before buying too.
>>>>
>>>>No, I don't want to retrieve a content of a URL. Here is an example. Suppose I want to call the URL "www.msn.com" from a VFP 9 code. Here is a pseudo code:
>>>>
>>>>cUrl = "www.msn.com"
>>>>for i = 1 to 100
>>>>      *--  Call the cUrl as if a browser is opened and the cURL is entered. This is what I don't know how to do.
>>>>      wait(20)
>>>>next
>>>>
>>>
>>>To open a URL with the default browser you need to first find out the associated browser (exe) on the users machine which is used for URLs. To do that I use the ShellExecute () function in the Windows API. To declare that function in VFP:
>>>
>>>
>>>  *
>>>  *    ShellExecute    -    SHELL EXECUTE FUNCTION IN SHELL32
>>>  *
>>>  *                         Copied (and adapted) from the UniversalThread (FAQ#190, by Gérald Santerre)
>>>  *                         According to the author, opens an HTML document or mail.
>>>  *                         Actually helps to open *any* document with its default association.
>>>  *
>>>  * nShowWindow = ...
>>>  *
>>>  * 0 Hides the window and passes activation to another window.
>>>  * 1 Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as 9).
>>>  * 2 Activates a window and displays it as an icon.
>>>  * 3 Activates a window and displays it as a maximized window.
>>>  * 4 Displays a window in its most recent size and position. The window that is currently active remains active.
>>>  * 5 Activates a window and displays it in its current size and position.
>>>  * 6 Minimizes the specified window and activates the top-level window in the system's list.
>>>  * 7 Displays a window as an icon. The currently active window remains active.
>>>  * 8 Displays a window in its current state. The window that is currently active remains active.
>>>  * 9 Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as 1).
>>>  *
>>>
>>>   DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
>>>    INTEGER nWinHandle , ;
>>>    STRING cOperation  , ;
>>>    STRING cFileName   , ;
>>>    STRING cParameters , ;
>>>    STRING cDirectory  , ;
>>>    INTEGER nShowWindow
>>>
>>>
>>>
>>>Then to call it you simple use:
>>>
>>>
>>>SHELLEXECUTE( 0, "Open", "https://duckduckgo.com", "", "", 1 )  &&  Enter whatever URL as appropriate
>>>
>>
>>Your code works; thank you again.
>>
>>One follow-up question. Do you know if it is possible that SHELLEXECUTE open the page in the same tab? That is, when I run the above code in a FOR loop, it opens a new tab on every SHELLEXECUTE. I use Chrome as a default browser. Is this a function of Chrome or something I can do in the VFP code?
>>
>>UPDATE. Or maybe there is a code to close the tab and then the next SHELLEXECUTE will open a tab. Therefore, you won't have many tabs open. Would this work?
>
>I am not sure. FireFox also opens a new tab. I think this is a browser setting and perhaps check the options for "opening new links" etc. You could also program to close the browser app between calls. i.e. Open browser, load url, close browser.

Thank you. I will try this.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform