3

現在開いているswfファイル名を検出したい。これが私のコードです:

Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Sub Form_Load()
  ListWins "*.swf*"
End Sub

Sub ListWins(Optional Title = "*", Optional Class = "*")
  Dim hWndThis As Long

  hWndThis = FindWindow(vbNullString, vbNullString)

  While hWndThis
    Dim sTitle As String, sClass As String
    sTitle = Space$(255)
    sTitle = Left$(sTitle, GetWindowText(hWndThis, sTitle, Len(sTitle)))

    sClass = Space$(255)
    sClass = Left$(sClass, GetClassName(hWndThis, sClass, Len(sClass)))

    If sTitle Like Title And sClass Like Class Then
      Debug.Print sTitle, sClass
      List1.AddItem (sTitle)
    End If

    hWndThis = GetWindow(hWndThis, GW_HWNDNEXT)
  Wend
End Sub

このコードは*.doc*.xlsファイル名を検出するために正常に機能していますが、ファイルでは機能していません*.swf

4

1 に答える 1

2

ノート

VBAでテストしました。VB6でも動くと思います。

これを試してください (このコードをモジュールに貼り付けて、サブサンプルを実行してください)

Private Declare Function GetWindowTextLength Lib "user32" Alias _
"GetWindowTextLengthA" (ByVal HWnd As Long) As Long

Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal HWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetDesktopWindow Lib "user32" () As Long

Public Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Public Function APIWindowCaption(ByVal HWnd As Long, ByVal lParam As Long) As Long
    Static winnum As Integer
    Dim MyStr As String

    winnum = winnum + 1

    MyStr = String(GetWindowTextLength(HWnd) + 1, Chr$(0))

    GetWindowText HWnd, MyStr, Len(MyStr)

    '~~> This will give you the caption of the window
    If InStr(1, MyStr, ".swf", vbTextCompare) Then Debug.Print MyStr

    APIWindowCaption = 1
End Function

Sub Sample()
    Dim retval As Long, DesktophWnd As Long

    DesktophWnd = GetDesktopWindow

    retval = EnumChildWindows(DesktophWnd, AddressOf APIWindowCaption, ByVal 0&)
End Sub

スナップショット

ここに画像の説明を入力

于 2012-05-15T11:28:14.777 に答える