史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   vb如何呼叫其它應用程式 (http://forum.slime.com.tw/thread206597.html)

profibus 2007-05-28 09:31 AM

vb如何呼叫其它應用程式
 
請問各位:
如何用vb的語法呼叫Internet Explorer至前景出現,當Internet Explorer未被呼叫出來的時候(不管按幾次就是只能執行1次),謝謝!:on_47:

mini 2007-05-28 10:39 AM

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


profibus 2007-05-28 11:35 AM

謝謝大大的提供,我再測試一下,謝謝:on_15:


所有時間均為台北時間。現在的時間是 03:50 AM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2024, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1