建立一窗体,放一个名字为DDEText的text。
添加以下代码
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const ERROR_SUCCESS = 0&
Const REG_OPTION_NON_VOLATILE = &O0
Const KEY_ALL_CLASSES As Long = &HF0063
Const KEY_ALL_ACCESS = &H3F
Const REG_SZ As Long = 1Public Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)
Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long, v$, r As Long
RetVal$ = ""
r = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_CLASSES, hSubKey)
If r <> ERROR_SUCCESS Then GoTo Quit_Now
SZ = 256: v$ = String$(SZ, 0)
r = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
If r = ERROR_SUCCESS And dwType = REG_SZ Then
RetVal$ = Left(v$, SZ - 1)
Else
RetVal$ = ""
End If
If hInKey = 0 Then r = RegCloseKey(hSubKey)
Quit_Now:
RegGetString$ = RetVal$End FunctionPublic Sub ConnectW3(url$)
On Error GoTo fout_connectw3 Dim strProgram$, strDDETopic$, strDDEItem$
Dim intLoaded%'make on Form1 a invisible textbox named DDEText
strProgram = RegGetString(HKEY_CLASSES_ROOT, "http\shell\open\command", "")
strDDETopic = UCase(RegGetString(HKEY_CLASSES_ROOT, "http\shell\open\ddeexec\Application", "")) & "|" & RegGetString(HKEY_CLASSES_ROOT, "http\shell\open\ddeexec\Topic", "")
strDDEItem = url$
With Form1.DDEText
.LinkTopic = strDDETopic
.LinkItem = strDDEItem & ",," & -1
.LinkMode = 2
.LinkRequest
End With
Exit Sub
fout_connectw3:
If Err.Number = 282 Then
If intLoaded = 0 Then
Shell strProgram, vbNormalFocus
intLoaded = 1
ElseIf intLoaded <= 5 Then
intLoaded = intLoaded + 1
Else
Err.Number = vbObjectError + 1
GoTo fout_connectw3
End If
Resume
ElseIf Err.Number <> 0 Then
MsgBox "Fatal error while communicating to browser"
Exit Sub
End IfEnd Sub以后要到指点页面的话就可以这样使用。
Call ConnectW3("http://www.weleon.net/www/")
添加以下代码
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const ERROR_SUCCESS = 0&
Const REG_OPTION_NON_VOLATILE = &O0
Const KEY_ALL_CLASSES As Long = &HF0063
Const KEY_ALL_ACCESS = &H3F
Const REG_SZ As Long = 1Public Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)
Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long, v$, r As Long
RetVal$ = ""
r = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_CLASSES, hSubKey)
If r <> ERROR_SUCCESS Then GoTo Quit_Now
SZ = 256: v$ = String$(SZ, 0)
r = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
If r = ERROR_SUCCESS And dwType = REG_SZ Then
RetVal$ = Left(v$, SZ - 1)
Else
RetVal$ = ""
End If
If hInKey = 0 Then r = RegCloseKey(hSubKey)
Quit_Now:
RegGetString$ = RetVal$End FunctionPublic Sub ConnectW3(url$)
On Error GoTo fout_connectw3 Dim strProgram$, strDDETopic$, strDDEItem$
Dim intLoaded%'make on Form1 a invisible textbox named DDEText
strProgram = RegGetString(HKEY_CLASSES_ROOT, "http\shell\open\command", "")
strDDETopic = UCase(RegGetString(HKEY_CLASSES_ROOT, "http\shell\open\ddeexec\Application", "")) & "|" & RegGetString(HKEY_CLASSES_ROOT, "http\shell\open\ddeexec\Topic", "")
strDDEItem = url$
With Form1.DDEText
.LinkTopic = strDDETopic
.LinkItem = strDDEItem & ",," & -1
.LinkMode = 2
.LinkRequest
End With
Exit Sub
fout_connectw3:
If Err.Number = 282 Then
If intLoaded = 0 Then
Shell strProgram, vbNormalFocus
intLoaded = 1
ElseIf intLoaded <= 5 Then
intLoaded = intLoaded + 1
Else
Err.Number = vbObjectError + 1
GoTo fout_connectw3
End If
Resume
ElseIf Err.Number <> 0 Then
MsgBox "Fatal error while communicating to browser"
Exit Sub
End IfEnd Sub以后要到指点页面的话就可以这样使用。
Call ConnectW3("http://www.weleon.net/www/")
Private Sub CmdOK_Click()
ShellExecute Me.hWnd, "open", "http://www.csdn.net", "", "", 5
End Sub简单的不知道是不是你需要的先看看吧
Dim WithEvents eventIE As WebBrowser_V1Private Sub Command1_Click()
Dim objIE As Object
For Each objIE In dWinFolder
If objIE.LocationURL = List1.List(List1.ListIndex) Then
Set eventIE = objIE
Command1.Enabled = False
List1.Enabled = False
Text1.Text = ""
Exit For
End If
Next
End SubPrivate Sub eventIE_NavigateComplete(ByVal URL As String)
Text1.Text = Text1.Text + Chr(13) + Chr(10) + URL
End SubPrivate Sub Form_Load()
Dim objIE As Object
For Each objIE In dWinFolder
If InStr(1, objIE.FullName, "IEXPLORE.EXE", vbTextCompare) <> 0 Then
List1.AddItem objIE.LocationURL
End If
Next
Command1.Caption = "正文"
End SubPrivate Sub Form_Unload(Cancel As Integer)
Set dWinFolder = Nothing
End SubPrivate Sub List1_Click()
Dim objDoc As Object
Dim objIE As Object
For Each objIE In dWinFolder
If objIE.LocationURL = List1.List(List1.ListIndex) Then
objIE.Navigate "www.applevb.com"
Exit For
End If
Next
End Sub点击列表中的一个链接就可以使该ie窗口浏览 www.applevb.com