1、VB中如何设置超链接?
Shell 函数
执行一个可执行文件,返回一个 Variant (Double),如果成功的话,代表这个程序的任务 ID,若不成功,则会返回 0。
语法
Shell(pathname[,windowstyle])
Shell 函数的语法含有下面这些命名参数:
部分 描述
pathname 必要参数。Variant (String),要执行的程序名,以及任何必需的参数或命令行变量,可能还包括目录或文件夹,以及驱动器。在Macintosh中,可以使用MacID函数来指定一个应用程序的署名而不是名称。下面的例子使用了Microsoft Word的署名:
Shell MacID("MSWD")
Windowstyle 可选参数。Variant (Integer),表示在程序运行时窗口的样式。如果 windowstyle 省略,则程序是以具有焦点的最小化窗口来执行的。在Macintosh(系统7.0或更高)中,windowstyle仅决定当应用程序运行时是否获得焦点。
windowstyle 命名参数有以下这些值:
常量 值 描述
vbHide 0 窗口被隐藏,且焦点会移到隐式窗口。常数vbHide在Macintosh平台不可用。
VbNormalFocus 1 窗口具有焦点,且会还原到它原来的大小和位置。
VbMinimizedFocus 2 窗口会以一个具有焦点的图标来显示。
VbMaximizedFocus 3 窗口是一个具有焦点的最大化窗口。
VbNormalNoFocus 4 窗口会被还原到最近使用的大小和位置,而当前活动的窗口仍然保持活动。
VbMinimizedNoFocus 6 窗口会以一个图标来显示。而当前活动的的窗口仍然保持活动。
说明
如果 Shell 函数成功地执行了所要执行的文件,则它会返回程序的任务 ID。任务 ID 是一个唯一的数值,用来指明正在运行的程序。如果 Shell 函数不能打开命名的程序,则会产生错误。
在Macintosh中,vbNormalFocus、vbMinimizedFocus和vbMaximizedFocus都将应用程序置于前台;vbHide、vbNoFocus、vbMinimizeFocus都将应用程序置于后台。
注意 缺省情况下,Shell 函数是以异步方式来执行其它程序的。也就是说,用 Shell 启动的程序可能还没有完成执行过程,就已经执行到 Shell 函数之后的语句。
2、VB的webbrowser控件如何用代码来点击超链接
我想楼主是想问用WebBrowser自动点这个链接吧。
Dim
Str1
As
String
Str1
=
"发送"
'判断是否为要点击的A标签的特版征字符
'历遍所有权A标签,查找含有"发送"字符的A标签并点击
Set
aSet
=
WebBrowser1.document.All.tags("A")
For
i
=
0
To
aSet.length
-
1
If
(InStr(1,
aSet(i).innerText,
Str1))
Then
aSet(i).onclick
'
如果aSet(i).onclick不能点击的话,请试试aSet(i).click
End
If
Next
i
3、如何用VB编写简单的浏览器(要单击超链接时可以跳转的)
添加的控件有:1.Microsoft Internet Controls
2.Microsoft Windows Common Control
3. Microsoft Windows Common Dialpg软件用到的控件有:1.CommandButton控件 命名为打开网站.
2.WebBrowser控件 象地球
3.StatusBar控件和ProgressBar控件 是Common Control里面带的
4.ComboBox控件
5.CommonDialog控件
代码
Private Sub Combo1_Click()
WebBrowser1.Navigate Combo1.Text
End Sub Private Sub Form_Load()
Combo1.Text = ""
Combo1.Top = 0
Combo1.Left = 0
WebBrowser1.Top = Combo1.Top + Combo1.Height
WebBrowser1.Left = 0
Form_Resize
StatusBar1.Style = sbrSimple
ProgressBar1.ZOrder
End Sub
Private Sub Form_Resize()
On Error GoTo a
Combo1.Width = Form1.Width - 100
WebBrowser1.Width = Combo1.Width
WebBrowser1.Height = Form1.Height - Combo1.Height - 1000
ProgressBar1.Top = Me.Height - StatusBar1.Height - 330
ProgressBar1.Left = 0.25 * StatusBar1.Width
ProgressBar1.Width = 0.75 * Me.Width - 250
a:
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim I As Long
Dim existed As Boolean
If KeyCode = 13 Then
If Left(Combo1.Text, 7) <> "http://" Then
Combo1.Text = "http://" + Combo1.Text
End If
WebBrowser1.Navigate Combo1.Text
For I = 0 To Combo1.ListCount - 1
If Combo1.List(I) = Combo1.Text Then
existed = True
Exit For
Else
existed = False
End If
Next
If Not existed Then
Combo1.AddItem (Combo1.Text)
End If
End If
End Sub
4、vb如何使用超链接打开网页
方法1)直接使用VB的Shell函数调用explorer.exe来实现。
Private Sub Command2_Click()方法2)使用API函数 ShellExecute实现。
以下是具体代码:
Option Explicit方法3)使用WebBrowser控件,直接制作个简易浏览器来实现。
Private Sub Command1_Click()方法3的运行效果图:
5、vb如何实现超链接
'添加一个按钮,把按钮的style的属性改为1,再添加一个模块
Private Sub Form_Load()
SetButton: SetButton Command1.hWnd, vbBlue
Command1.Caption = "Hello"
Command1.FontSize = 15
Command1.FontUnderline = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
RemoveButton: RemoveButton Command1.hWnd
End Sub
'下面为模块代码
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetParent Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Declare Function GetProp Lib "user32" Alias "GetPropA" _
(ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" _
(ByVal hWnd As Long, ByVal lpString As String, _
ByVal hData As Long) As Long
Private Declare Function RemoveProp Lib "user32" Alias _
"RemovePropA" (ByVal hWnd As Long, _
ByVal lpString As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
'Owner draw constants
Private Const ODT_BUTTON = 4
Private Const ODS_SELECTED = &H1
'Window messages we're using
Private Const WM_DESTROY = &H2
Private Const WM_DRAWITEM = &H2B
Private Type DRAWITEMSTRUCT
CtlType As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hDC As Long
rcItem As RECT
itemData As Long
End Type
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
'Various GDI painting-related functions
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
(ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, _
lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, _
ByVal crColor As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, _
ByVal nBkMode As Long) As Long
Private Const TRANSPARENT = 1
Private Const DT_CENTER = &H1
Public Enum TextVAligns
DT_VCENTER = &H4
DT_BOTTOM = &H8
End Enum
Private Const DT_SINGLELINE = &H20
Private Sub DrawButton(ByVal hWnd As Long, ByVal hDC As Long, _
rct As RECT, ByVal nState As Long)
Dim s As String
Dim va As TextVAligns
va = GetProp(hWnd, "VBTVAlign")
'Prepare DC for drawing
SetBkMode hDC, TRANSPARENT
SetTextColor hDC, GetProp(hWnd, "VBTForeColor")
'Prepare a text buffer
s = String$(255, 0)
'What should we print on the button?
GetWindowText hWnd, s, 255
'Trim off nulls
s = Left$(s, InStr(s, Chr$(0)) - 1)
If va = DT_BOTTOM Then
'Adjust specially for VB's CommandButton control
rct.Bottom = rct.Bottom - 4
End If
If (nState And ODS_SELECTED) = ODS_SELECTED Then
'Button is in down state - offset
'the text
rct.Left = rct.Left + 1
rct.Right = rct.Right + 1
rct.Bottom = rct.Bottom + 1
rct.Top = rct.Top + 1
End If
DrawText hDC, s, Len(s), rct, DT_CENTER Or DT_SINGLELINE _
Or va
End Sub
Public Function ExtButtonProc(ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim lOldProc As Long
Dim di As DRAWITEMSTRUCT
lOldProc = GetProp(hWnd, "ExtBtnProc")
ExtButtonProc = CallWindowProc(lOldProc, hWnd, wMsg, wParam, lParam)
If wMsg = WM_DRAWITEM Then
CopyMemory di, ByVal lParam, Len(di)
If di.CtlType = ODT_BUTTON Then
If GetProp(di.hwndItem, "VBTCustom") = 1 Then
DrawButton di.hwndItem, di.hDC, di.rcItem, _
di.itemState
End If
End If
ElseIf wMsg = WM_DESTROY Then
ExtButtonUnSubclass hWnd
End If
End Function
Public Sub ExtButtonSubclass(hWndForm As Long)
Dim l As Long
l = GetProp(hWndForm, "ExtBtnProc")
If l <> 0 Then
'Already subclassed
Exit Sub
End If
SetProp hWndForm, "ExtBtnProc", _
GetWindowLong(hWndForm, GWL_WNDPROC)
SetWindowLong hWndForm, GWL_WNDPROC, AddressOf ExtButtonProc
End Sub
Public Sub ExtButtonUnSubclass(hWndForm As Long)
Dim l As Long
l = GetProp(hWndForm, "ExtBtnProc")
If l = 0 Then
'Isn't subclassed
Exit Sub
End If
SetWindowLong hWndForm, GWL_WNDPROC, l
RemoveProp hWndForm, "ExtBtnProc"
End Sub
Public Sub SetButton(ByVal hWnd As Long, _
ByVal lForeColor As Long, _
Optional ByVal VAlign As TextVAligns = DT_VCENTER)
Dim hWndParent As Long
hWndParent = GetParent(hWnd)
If GetProp(hWndParent, "ExtBtnProc") = 0 Then
ExtButtonSubclass hWndParent
End If
SetProp hWnd, "VBTCustom", 1
SetProp hWnd, "VBTForeColor", lForeColor
SetProp hWnd, "VBTVAlign", VAlign
End Sub
Public Sub RemoveButton(ByVal hWnd As Long)
RemoveProp hWnd, "VBTCustom"
RemoveProp hWnd, "VBTForeColor"
RemoveProp hWnd, "VBTVAlign"
End Sub
'然后回到FORM中:
'添加CommandButton,不必更改它们的名称,将它们的Style设为Graphical,给第3个按钮设置一幅图片。
'CommandButton也可以放置在一个容器如PictureBox或Frame中,模块会判断,如果需要的话将CommandButton的容器也子类化。
'在Form中的代码:
Private Sub Form_Load()
'Initialize each button color.
SetButton Command1.hWnd, vbRed
SetButton Command2.hWnd, &H8000& '深绿色
'Assign this one a DT_BOTTOM alignment because
SetButton Command3.hWnd, vbBlue, DT_BOTTOM '含有图片,将文本放置在按钮底部
SetButton Command4.hWnd, &H8080& '暗棕黄色
End Sub
Private Sub Form_Unload(Cancel As Integer)
'手动解除按钮的子类化
'这并不是必须的
RemoveButton Command1.hWnd
RemoveButton Command2.hWnd
RemoveButton Command3.hWnd
RemoveButton Command4.hWnd
End Sub
For m = 0 To 9
SetButton CmdNum(m).hWnd, vbBlue
Next
For n = 1 To 4
SetButton CmdCal(n).hWnd, vbRed
Next
For l = 2 To 4
SetButton CmdOth(l).hWnd, vbRed
Next
6、vb6.0如何响应WebBrowser控件中的超链接
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Text1.Text = URL
End Sub
这句本身就是WebBrowser1加载完成时执行的,不跳转,WebBrowser1的url不显示,跳转就显示正内常的url,不能既不跳转又显示吧容 ,页面不会跳转,到哪找URL地址?
7、vb制作浏览器 在什么事件下能让网页跳转超链接
那要把该浏览器设置成默认浏览器才行啊!具休方法我就不知道了!建议你到编程中国论坛去看看吧!
8、VB自动点击网页超链接
^用正则试试,关于如何在VB中使用正则,请参考相关手册.给一专个属VBS例子
Dim ss, re, rv
ss = "<a href="asfsaf.htm" target=_blank>123</a>"
Set re = New RegExp
re.Pattern = ".*\shref="([^""]+)""\s*[^>]*>123<.*"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$1")
9、VB的webbrowser控件如何用代码来点击超链接
我想楼主抄是想问用WebBrowser自动点这个链袭接吧。
Dim Str1 As String
Str1 = "发送" '判断是否为要点击的A标签的特征字符
'历遍所有A标签,查找含有"发送"字符的A标签并点击
Set aSet = WebBrowser1.document.All.tags("A")
For i = 0 To aSet.length - 1
If (InStr(1, aSet(i).innerText, Str1)) Then
aSet(i).onclick
' 如果aSet(i).onclick不能点击的话,请试试aSet(i).click
End If
Next i
10、vb 获取网页超链接和超链接上的文字
推荐使用WebBrowser控件复来获取超链接。制
在WebBrowser1_DocumentComplete事件里面,可以检举到超链接和该链接的文本。
WebBrowser1.Document.links.length '这个是网页上超链接的数量
WebBrowser1.Document.links.Item(i).innerText '这个属性是超链接的文本
WebBrowser1.Document.links.Item(i).outerhtml '这个属性是超链接的网址
或者自己编写函数,查找html文本的【<a href="......."】字段,里面就是超链接的网址,超链接文本在紧跟后门的【>......<】字段里面。
个人极力推荐用WebBrowser1控件实现。