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控制項實現。