The easiest and perfect way to open web page/URL (includes mailto protocol) and methods contrast in VB6

Posted by Admin L in VB6 Programming on 29-08-2011. Tags:

Author: Nosa Lee
Original Address: https://www.seeksunslowly.com/vb6-easiest-perfect-open-url-mailto-methods
To reprint this article, please indicate the source, thank you.
_____________________________________

First, list three common ways for opening web page/URL:
1. Use Win32 API
[cc lang=”vb”]
‘ API declare.
Private Declare Function ShellExecute Lib “shell32.dll” Alias “ShellExecuteA” _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
‘ Call.
ShellExecute 0&, vbNullString, YourURL, vbNullString, vbNullString, vbNormalFocus
[/cc]
Advantages: can meet various web page/URL opening requirements, includes the URL with mailto protocol; can call the default program to open URL with the corresponding protocol, such as call the default web browser (e.g. Firefox) to open the URL with HTTP or HTTPS protocol, or call the default email client (e.g. Outlook) to open the URL with mailto protocol.
Disadvantages: need to declare Win32 API, complicated.

2. Use Shell(“explorer YourURL”)
Advantages: succinct.
Disadvantages: cannot open the URL with parameters (inclues = & ? symbols); unsupported mailto protocol; call IE but not the default web browser to open web page/URL.

3. Use Shell “rundll32.exe url.dll,FileProtocolHandler YourURL”
Example
Call the default web browser to open the complex URL with HTTP or HTTPS protocol:
[cc lang=”vb”]
Shell “rundll32.exe url.dll,FileProtocolHandler https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XXXXXXXXXXXXX”
[/cc]
Call the default email client to open the URL with mailto protocol:
[cc lang=”vb”]
Shell “rundll32.exe url.dll,FileProtocolHandler mailto:[email protected]
[/cc]
Advantages: succinct; can meet various web page/URL opening requirements, includes the URL with mailto protocol; can call the default program to open URL with the corresponding protocol, such as call the default web browser (e.g. Firefox) to open the URL with HTTP or HTTPS protocol, or call the default email client (e.g. Outlook) to open the URL with mailto protocol.
Disadvantages: None.

In summary, method 3 has the advantages of method 1 and 2 both, and has not disadvantage. So, this way is the easiest and perfect method to open web page/URL (includes mailto protocol) in VB6. Of course, you can sum the easiest and perfect way in other programming languages by re​​fer this article.

At last, remember it again:
[cc lang=”vb”]
Shell “rundll32.exe url.dll,FileProtocolHandler YourURL”
[/cc]

【赞赏 / Reward】

微信         支付宝         PayPal

Post a comment