当前位置:首页 » 程序代码 » 正文

VB编程:vb打开网页代码

用vb代码打开网页,打开一个网站的功能用API来做实在是太容易了,就是用ShellExecute函数来完成,只要一行代码,而且VB用ShellExecute也可以轻易打开EXE程序,音乐,视频,txt文件,邮件软件等等...

先在窗体写下API代码:
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
Private Const SW_SHOW = 5


在窗体画一个按钮1,写入以下代码,就可以调用默认的浏览器打开2345网站
Private Sub Command1_Click()
Call ShellExecute(Me.hWnd, "open", "http://www.2345.com/?887", "", "", SW_SHOW)
End Sub

稍改一下代码,也可以打开邮件编辑软件,向某个邮箱写邮件:
Call ShellExecute(Me.hWnd, "open", "mailto:hyf64@sohu.com", "", "", SW_SHOW)

调用默认的文本编辑软件,如记事本,打开txt文件:
Call ShellExecute(Me.hWnd, "open", "c:\abc.txt", "", "", SW_SHOW)

调用默认的音乐播放器,打开MID格式音乐:
Call ShellExecute(Me.hWnd, "open", "c:\abc.mid", "", "", SW_SHOW)
 

调用默认的浏览器打开一个本地的网页:
Call ShellExecute(Me.hWnd, "open", "c:\abc.html", "", "", SW_SHOW)

打开一个EXE程序:
Call ShellExecute(Me.hWnd, "open", "c:\abc.exe", "", "", SW_SHOW)

打开C盘一个快捷方式对应的程序:
Call ShellExecute(Me.hWnd, "open", "c:\abc.lnk", "", "", SW_SHOW)

打赏 支付宝打赏 微信打赏

来源:济亨网

本文链接:http://wb86.com/post/32.html

VB代码  API  
    << 上一篇 下一篇 >>

    湘公网安备 43011102000514号 - 湘ICP备08100508号