例子是官网的例子,本人做了 x64 兼容修改。
提示:没有安装过 DynamicWrapperX 的,先执行 附件中的 DynamicWrapperX_Make.vbs。- DynamicWrapperX.7z 文件说明:
- .\dynwrapx1_00_eng.zip --官网已挂?原文件及示例文件在这里。
- .\DynamicWrapperX_Make.vbs --首次使用 DynamicWrapperX ,自动注册,可在 x86/x64 系统中使用。
- .\DynamicWrapperX_Init-WinList.vbs --列出 Windows 所有窗口标题
- .\Beep.vbs --调用主板嗡鸣器发出声音
- .\Hello.vbs --简单对话框 Windows API MessageBoxW()
复制代码 示例:DynamicWrapperX_Make.vbs- '************************************************************************
- 'Main
- '************************************************************************
- Sub Main()
-
- If Not DynamicWrapperX_Init() Then Exit Sub
-
- Msgbox "DynamicWrapperX_Init() = OK"
-
- Set DX = CreateObject("DynamicWrapperX")
-
- DX.Register "user32", "EnumWindows", "i=pl"
- DX.Register "user32", "GetWindowTextW", "i=hWl" ' Unicode variant.
- ' DX.Register "user32", "GetWindowText", "i=hSl" ' ANSI variant.
-
- Set Ref = GetRef("CbkEnumWin") ' Get a reference to the function.
-
- pCbkFunc = DX.RegisterCallback(Ref, "i=hl", "r=l") ' Register CbkEnumWin
- ' as a callback procedure
- ' and get its pointer.
- n = 0 : m = 0 : WinList = ""
- Title = Space(256) ' Buffer for the window titles (an output string).
-
- DX.EnumWindows pCbkFunc, 0 ' Call EnumWindows and pass it the pointer
- ' to the callback procedure.
-
- WScript.Echo "Windows in total: " & m & vbCrLf & "With a title: " & n & _
- vbCrLf & vbCrLf & WinList
-
- End Sub
-
- '************************************************************************
- 'The callback function itself
- '************************************************************************
- Function CbkEnumWin(ByVal hwnd, ByVal lparam)
-
- DX.GetWindowTextW hwnd, Title, 256
- ' DX.GetWindowText hwnd, Title, 256 ' ANSI variant.
- If Len(Title) > 0 Then ' Add the title to the list if its length is greater than 0.
- WinList = WinList & hwnd & vbTab & Title & vbCrLf
- n = n + 1
- End If
- m = m + 1
- CbkEnumWin = 1 ' Returning 0 will stop the calls.
- End Function
复制代码 结果如下:复制代码 |