IE 視窗上的標題列是 *** - Microsoft Internet Explorer
所以只要搜一次系統內的視窗是否已有 這種標題出現 且是 顯性視窗
來決定是否 呼叫Internet Explorer
至於如何呼叫其它應用程式
可以使用
Shell "C:\Program Files\Internet Explorer\iexplore.exe " & strURL, VbNormalFocus
strURL 是網址或欲下載的地址
語法:
Sub FindWindowsText()
dim hCurrentWindow as Long
Dim buff As String * 255
Dim CaptionIs As String, strText As String, strURL As String
CaptionIs = " - Microsoft Internet Explorer"
hCurrentWindow = GetWindow(Me.hwnd, GW_HWNDFIRST)
Do While hCurrentWindow <> 0
If ((GetWindowText(hCurrentWindow, buff, 255) > 0) And IsWindowVisible(hCurrentWindow)) Then
strText = Left(buff, InStr(buff, Chr$(0)) - 1)
If InStr(1, strText, CaptionIs, vbTextCompare) > 0 Then Exit Sub
End If
hCurrentWindow = GetWindow(hCurrentWindow, GW_HWNDNEXT)
Loop
'VbNormalFocus 是 視窗具有駐點,且會還原到它原來的大小和位置。
Shell "C:\Program Files\Internet Explorer\iexplore.exe " & strURL, VbNormalFocus
End Sub
會用到的 API宣告
語法:
Global Const GW_HWNDFIRST = 0 '從最上層的視窗開始找
'得到視窗 執掌ID
Public Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
'得到視窗標題列文字 至lpString
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
'判斷此視窗是否為可視狀態
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long