查看單個文章
舊 2007-05-28, 10:39 AM   #2 (permalink)
mini
管理版主
 
mini 的頭像
榮譽勳章
UID - 4144
在線等級: 級別:96 | 在線時長:9694小時 | 升級還需:103小時級別:96 | 在線時長:9694小時 | 升級還需:103小時級別:96 | 在線時長:9694小時 | 升級還需:103小時級別:96 | 在線時長:9694小時 | 升級還需:103小時級別:96 | 在線時長:9694小時 | 升級還需:103小時級別:96 | 在線時長:9694小時 | 升級還需:103小時
註冊日期: 2002-12-07
文章: 13261
精華: 0
現金: 26261 金幣
資產: 3024071 金幣
預設

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

此帖於 2007-05-28 02:55 PM 被 mini 編輯. 原因: 修正一處
mini 目前離線  
送花文章: 2001, 收花文章: 7962 篇, 收花: 26757 次
回覆時引用此帖
向 mini 送花的會員:
profibus (2007-05-28)
感謝您發表一篇好文章