I found a way to use windows API functions in vlisp.Now you can see the effect:
My question is : Is there another better way to applicate it? Any problems in here?
;;;Call windows API with "Excel.application"
(defun c:API (/ wsh oEx oBk Mod str)
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\11.0\\Excel\\Security\\AccessVBOM" "1 REG_DWORD")
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\12.0\\Excel\\Security\\AccessVBOM" "1 REG_DWORD")
(vl-registry-write "HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\14.0\\Excel\\Security\\AccessVBOM" "1 REG_DWORD")
(setq oEx (vlax-create-object "excel.application"))
(setq obk (vlax-invoke (vlax-get oEx 'workbooks) 'add))
(setq mod (vlax-invoke (vlax-get (vlax-get obk 'VBProject) 'VBComponents) 'add 1))
(setq str
"Private Declare Function SetCursorPos Lib \"user32\" (ByVal x As Long, ByVal y As Long) As Long
Declare Function GetForegroundWindow Lib \"user32\" Alias \"GetForegroundWindow\" () As Long
Declare Function GetWindowDC Lib \"user32\" Alias \"GetWindowDC\" (ByVal hwnd As Long) As Long
Declare Sub Sleep Lib \"kernel32\" (ByVal dwMilliseconds As Long)
'Declare Function GetDC Lib \"user32\" Alias \"GetDC\" (ByVal hwnd As Long) As Long
Declare Function Ellipse Lib \"gdi32\" Alias \"Ellipse\" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Sub MyMacro(x as Long, y as Long)
SetCursorPos 0, 0
Ellipse GetWindowDC(GetForegroundWindow),x,y,x+800,y+600
Sleep(2000)
End Sub"
)
(vlax-invoke (vlax-get mod 'CodeModule) 'AddFromString str)
(vlax-invoke oEx 'run "MyMacro" 200 100)
(vlax-put oEx 'DisplayAlerts 0)
(vlax-invoke obk 'close)
(vlax-invoke oEx 'quit)
(vlax-release-object mod)
(vlax-release-object obk)
(vlax-release-object oEx)
(princ)
)