windows API 编程 在lisp中的实现,aroom和nonsmall做了很多工作,我这里提供另外一种思路:
利用excel.vba的实现,比较完美,实现过程中没有出现什么对话框,可以得到返回值。
主干部分还是比较简单。呵呵。
大家不防讨论一下。
下面实现了在背景中画一个白色椭圆(以为不能恢复的,不要惊慌,刷新一下屏幕一下就可以了)
- (defun c:API (/ wsh oEx oBk Mod str)
- (setq wsh (vlax-create-object "wscript.Shell"))
- (vlax-invoke wsh 'RegWrite "HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\11.0\\Excel\\Security\\AccessVBOM" 1 "REG_DWORD")
- (vlax-invoke wsh 'RegWrite "HKEY_CURRENT_USER\\Software\\Microsoft\\Office\\12.0\\Excel\\Security\\AccessVBOM" 1 "REG_DWORD")
- (vlax-invoke wsh 'RegWrite "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 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 x, y
- Ellipse GetDC(0),0,0,x,y
- End Sub"
- )
- (vlax-invoke (vlax-get mod 'CodeModule) 'AddFromString str)
- (vlax-invoke oEx 'run "MyMacro" 800 600)
- (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)
- (vlax-release-object wsh)
- (princ)
- )
|