天天看點

vbs 中使用 Win32Exts 擴充調用 ActiveX控件 示例

續接前文:

https://blog.csdn.net/tan_kaishuai/article/details/97898661

github 位址:

https://github.com/tankaishuai/win32exts_for_VBScript

本文主要示範如何使用 vbs 操作一個實際的ActiveX控件。

目标控件為“五虎大戰”棋類小遊戲,可在這裡擷取下載下傳:

https://github.com/tankaishuai/My_ActiveX_DLL_MIX_DEV/blob/master/ActiveX/Tigers5.ocx

首先需要下載下傳:win32exts.dll (v49.202.4.4 及以上版本),然後注冊之:

   regsvr32  win32exts.dll

然後愉快地編寫 vbs 腳本如下:

------------------------------------------------------------------------------------------------

' 初始化 win32exts

On Error Resume Next

Call win32exts.pop_edx()

If err Then

    Set win32exts = WScript.CreateObject("win32exts.win32atls")

End If

On Error GoTo 0

call win32exts.load_sym("*", "*")

' 設定控件顯示位置為 {0, 0, 600, 600}

g_pBuf = win32exts.malloc(520)

call win32exts.write_value(g_pBuf, 8, 4, 600)

call win32exts.write_value(g_pBuf, 12, 4, 600)

'建立 ActiveX 控件

hwnd = 0      '11798276

ax = win32exts.NewActiveXControl_IE(win32exts.L("工程2.Tigers5"), hwnd, g_pBuf)

'調用 ax.Ax_ShowWindow(1) 顯示控件

call win32exts.ax_call(ax, 0, win32exts.L("Ax_ShowWindow"), win32exts.L("d"), 1)

'調用 ax.put_CaptionLBL("修改後的資料") 修改控件屬性

call win32exts.ax_put(ax, win32exts.L("CaptionLBL"), win32exts.L("a"), "修改後的資料")

'進入消息循環

call win32exts.SysMessageLoop()

------------------------------------------------------------------------------------------------

儲存該 vbs 腳本為 test_ActiveX_Control.vbs ,并執行之:

c:\windows\syswow64\wscript   test_ActiveX_Control.vbs

顯示效果如下:

vbs 中使用 Win32Exts 擴充調用 ActiveX控件 示例