demon_blog demon_blog
关注数: 3 粉丝数: 43 发帖数: 337 关注贴吧数: 6
VBS调用Windows API函数 Option Explicit Dim WshShell Dim oExcel, oBook, oModule Dim strRegKey, strCode, x, y Set oExcel = CreateObject("Excel.Application") set WshShell = CreateObject("wscript.Shell") strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM" strRegKey = Replace(strRegKey, "$", oExcel.Version) WshShell.RegWrite strRegKey, 1, "REG_DWORD" Set oBook = oExcel.Workbooks.Add Set oModule = obook.VBProject.VBComponents.Add(1) strCode = _ "Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCr & _ "Private Type POINTAPI : X As Long : Y As Long : End Type"                                          & vbCr & _ "Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long"                & vbCr & _ "Sub SetCursor(x as Long, y as Long) : SetCursorPos x, y : End Sub"                                 & vbCr & _ "Public Function GetXCursorPos() As Long"                                                           & vbCr & _       "Dim pt As POINTAPI : GetCursorPos pt : GetXCursorPos = pt.X"                                   & vbCr & _ "End Function"                                                                                      & vbCr & _ "Public Function GetYCursorPos() As Long"                                                           & vbCr & _       "Dim pt As POINTAPI: GetCursorPos pt : GetYCursorPos = pt.Y"                                    & vbCr & _ "End Function" oModule.CodeModule.AddFromString strCode x = oExcel.Run("GetXCursorPos") y = oExcel.Run("GetYCursorPos") WScript.Echo x, y oExcel.Run "SetCursor", 0, 0 oExcel.DisplayAlerts = False oBook.Close oExcel.Quit 懒得写注释,看得懂就看,看不懂就算。
1 下一页