在VB中怎么通过代码用IE打开一个指定的网站?

解决方案 »

  1.   

    使用超链接和发送Email 
     
        
      
        使用API函数ShellExecute可以调用外部默认的浏览器和电子邮件工具来打开一个超链接和和发送一个电子邮件。    先在程序中加入如下的声明后,就能引用这个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  其中各个参数的意义如下表所示:参数  意义  
    hwnd Long,指定一个窗口的句柄,有时windows程序要在创建自己的主窗口前显示一个消息框 
    lpOperation String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它 
    lpFile String,想用关联程序打印或打开一个程序名或文件名 
    lpParameters String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数 
    lpDirectory String,想使用的完整路径 
    nShowCmd Long,定义了如何显示启动程序的常数值   比如我们要使用IE打开标签中的超链接,则我们可以在标签的Click()过程中加入如下一句代码:
      Call ShellExecute(Form1.hwnd, "open", "http://www.hongen.com", vbNullString, vbNullString, &H0)
      其中http://www.hongen.com是要打开的超链接,"open"是采用打开的方法,&H0表示用默认程序IE打开时,IE窗口可见。  又比如我们要打开默认的电子邮件工具发送邮件,则使用下面语句:
       Call ShellExecute(Form1.hwnd, "Open", "mailto:[email protected]", "", App.Path, 1)  最后我们设置标签Label的字体为下划线,MouseIcon选择一个小手状的图标,把MousePointer设为99-Custom,这样就能模拟超链接的效果了。
     
      

  2.   

    Option Explicit
    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 Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     Label1.FontUnderline = False
     Label1.ForeColor = RGB(0, 0, 0)
    End SubPrivate Sub Label1_Click() ShellExecute Me.hWnd, "open", "http://www.sina.com.cn", "", "", 5End SubPrivate Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     Label1.FontUnderline = True
     Label1.ForeColor = RGB(0, 0, 255)
    End Sub
      

  3.   

    nResult = Shell("start.exe http://news.sohu.com", vbHide)
      

  4.   

    声明:
    Public 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
    '其中各个参数的意义如下表所示:
    'hwnd Long,指定一个窗口的句柄,有时windows程序要在创建自己的主窗口前显示一个消息框
    'lpOperation String,指定字串“open”来打开lpFlie文档,或指定“Print”来打印它
    'lpFile String,想用关联程序打印或打开一个程序名或文件名
    'lpParameters String,如lpszFlie是可执行文件,则这个字串包含传递给执行程序的参数
    'lpDirectory String,想使用的完整路径
    'nShowCmd Long,定义了如何显示启动程序的常数值调用:
        Call ShellExecute(hwnd, "open", "http://www.sina.com.cn", vbNullString, vbNullString, &H0)
      

  5.   

    这个API功能很多,同样可以打开可执行文件
      

  6.   

    inet控件
    openurl("www.sohu.com")