回覆列表
  • 1 # maimi32709

    可以使用API函式FindWindow和PostMessage來尋找一個視窗並且關閉它。下面的範例演示如何關閉一個標題為"Calculator"的視窗。"下面的程式碼放到模組中 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long "FindWindowAPI函式Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long "PostMessageAPI函式Public Const WM_CLOSE = &H10 "常用變數定義"程式程式碼Dim winHwnd As Long "定義一個長整形變數winHwndDim RetVal As Long "定義一個長整形變數RetValwinHwnd = FindWindow(vbNullString, "Calculator") "API函式查詢"Calculator"這個視窗Debug.Print winHwnd "顯示這個視窗控制代碼If winHwnd 0 Then "如不為0,表示找到視窗RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) "向這個視窗傳送關閉資訊If RetVal = 0 Then "如果返回資訊為0.表示失敗,未傳送成功MsgBox "Error posting message." "提示傳送失敗End IfElseMsgBox "The Calculator is not open." "提示沒有找到開啟的程式End If

  • 中秋節和大豐收的關聯?
  • 《舟過安仁》中哪句寫出兒童調皮?