|
分類:[VB6以前]
※大投下(orz ノ■ミ Option Explicit Private Declare Function EnumWindows Lib "user32" _ (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const WM_GETTEXTLENGTH As Long = &HE Private Const WM_GETTEXT As Long = &HD Private EnumWindowTextCollection As Collection
Public Function EnumWindowText() As Collection Set EnumWindowTextCollection = New Collection Call EnumWindows(AddressOf EnumWindowsProc, 0) Set EnumWindowText = EnumWindowTextCollection End Function
Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long EnumWindowTextCollection.Add GetWndText(hWnd) EnumWindowsProc = 1 End Function
Public Function GetWndText(ByVal hWnd As Long) As String Dim i As Long Dim buf() As Byte If hWnd <> 0 Then i = SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0) + 1 ReDim buf(1 To i) i = SendMessage(hWnd, WM_GETTEXT, i, buf(1)) If i <= 0 Then Erase buf Else ReDim Preserve buf(1 To i) End If GetWndText = StrConv(buf, vbUnicode) End If End Function
※IDE上でEnumWindowTextを実行したところ、0.05秒かかりました。 …少し遅いですねぇ。 ID:12345
|