VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 打开一个直接到自己主页的浏览器
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:9929, 日期:2000-10-19
Opening a browser to your homepage
submitted by Dan Newsome
D&D Information Professionals, newsomed@earthlink.net
You can use code like the following to open a browser to your homepage. Modify filenames, paths, and URLs as necessary to match the values on your system.

Dim FileName As String, Dummy As String
Dim BrowserExec As String * 255
Dim RetVal As Long
Dim FileNumber As Integer
Const SW_SHOWNORMAL = 1 注释: Restores Window if Minimized or

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

Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As _
String) As Long
注释:<Code> ---------

BrowserExec = Space(255)
FileName = "C:\temphtm.HTM"

FileNumber = FreeFile() 注释: Get unused file number

Open FileName For Output As #FileNumber 注释: Create temp HTML file
Write #FileNumber, " <\HTML>" 注释: Output text
Close #FileNumber 注释: Close file

注释: Then find the application associated with it.
  RetVal = FindExecutable(FileName, Dummy, BrowserExec)
  BrowserExec = Trim$(BrowserExec)
  注释: If an application is found, launch it!
  If RetVal <= 32 Or IsEmpty(BrowserExec) Then 注释: Error

    Msgbox "Could not find a browser"

  Else
    RetVal = ShellExecute(frmMain.hwnd, "open", BrowserExec, _
      "www.myurl.com", Dummy, SW_SHOWNORMAL)
    If RetVal <= 32 Then 注释: Error
      Msgbox "Web Page not Opened"
    End If
  End If

Kill FileName 注释: delete temp HTML file