本帖最后由 highflybir 于 2011-1-11 20:49 编辑
回复 highflybir 的帖子
Shell.Application篇
;;;windows shell
- (setq path (strcat (getSpecialPath 1) "/shell32.dll"))
- (if (not ac-ssfwindows)
- (vlax-import-type-library
- :tlb-filename path
- :methods-prefix "am-"
- :properties-prefix "ap-"
- :constants-prefix "ac-"
- )
- )
- (setq shapp (vlax-create-object "shell.application"))
以下种种用法:
- (am-CascadeWindows shapp)
;层叠窗口
- (am-ControlPanelItem shapp "inetcpl.cpl" )
;打开控制面板(internet)
- (am-settime shapp)
;打开时间和日期设置对话框
- (am-TrayProperties shapp)
;日期和时间 属性
- (am-explore shapp "c:\\")
;打开 C 盘
- (am-FindComputer shapp)
;搜索计算机
- (am-findPrinter shapp "canno")
;搜索打印机
- (am-GetSystemInformation shapp "ProcessorSpeed")
;处理器速度:运行windows 7 和vista
- (am-GetSystemInformation shapp "PhysicalMemoryInstalled")
;物理内存容量
- (am-GetSystemInformation shapp "IsOS_Professional")
;是否是专业版
- (am-filerun shapp)
;打开运行窗口
- (am-ShutdownWindows shapp)
;关机对话框
- (am-findfiles shapp)
;搜索文件
- (am-toggledesktop shapp)
;显示桌面
- (am-IsServiceRunning shapp "Spooler")
;检测某项服务(打印机)是否在运行
- (am-WindowsSecurity shapp)
;Windows安全
- (am-AddToRecent shapp "c:\\1.txt")
;添加到最近打开文档
- (am-namespace shapp "c:\\")
;返回所打开的Folder对象
;选择文件夹对话框
- (am-BrowseForFolder shapp
- (vla-get-hwnd (vlax-get-acad-object) )
- "Select a folder"
- 64
- )
- (am-BrowseForFolder shapp 0 "我的电脑" 16 17)
;打开文件浏览对话框,并获得文件夹对象
- (am-open shapp "c:\\")
;打开某个目录
;;获得图像的详细信息,包括分辨率等等
- (defun GetInfoOfPic(shapp path name / info root file i l)
- (setq root (am-namespace shapp path))
- (setq file (am-ParseName root name))
- (setq i 0)
- (repeat 256
- (setq info (am-GetDetailsOf root file i))
- (if (/= info "")
- (progn
- (princ (strcat "\nIndex " (itoa i) ": " info))
- (setq l (cons info l))
- )
- )
- (setq i (1+ i))
- )
- (reverse l)
- )
- (getInfoOfPic shapp "D:\\" "1.jpg")
;;下面是一个小小的程序,用来获得某个目录下的文件夹和文件名
- (defun BrowseFolder(shapp fp / root items count i item path name)
- (setq root (am-namespace shapp fp))
- (setq items (am-items root))
- (setq count (ap-get-Count items))
- (setq i 0)
- (repeat count
- (setq item (am-item items i))
- (setq path (ap-get-path item))
- (setq name (ap-get-name item))
- (if (= (ap-get-IsFolder item) :vlax-true) ;zip 也是folder??呵呵
- (progn
- (princ (strcat "\n---Folder:" path))
- (BrowseFolder shapp path)
- )
- (princ (strcat "\nFile name:" name))
- )
- (setq i (1+ i))
- )
- )
- (BrowseFolder shapp "C:\\Program Files\\AutoCAD 2006")
;;创建一个新的文件夹(移动MoveHere,拷贝copyhere,等)
- (setq root (am-namespace shapp "d:\\"))
- (am-NewFolder root "Test")
- (setq file (am-ParseName root "1.jpg"))
- (am-copyhere (am-namespace shapp "c:\\") file 16)
- (am-movehere (am-namespace shapp "c:\\") file 0)
;;得到某些特殊文件夹
- (am-NameSpace shapp "shell:PrintersFolder")
- (am-NameSpace shapp "shell:personal")
- (am-NameSpace shapp "shell:drivefolder")
- ;;(am-ShowBrowserBar shapp "{C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1}" :vlax-true);;???
;;执行跟一个文件或者文件夹相关联的
- (am-doit (am-item (am-verbs (ap-get-self root)) 0))
- (am-doit (am-item (am-verbs file) 0))
;;调出控制面版选项
- (am-ShellExecute shapp "Explorer.exe" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}") ;//打开我的电脑
- (am-ShellExecute shapp "Rundll32.exe" "shell32.dll,Control_RunDLL sysdm.cpl,,2" )
- (am-ShellExecute shapp "Rundll32.exe" "shell32.dll,Control_RunDLL netcpl.cpl,,1")
- (am-ShellExecute shapp "Rundll32.exe" "shell32.dll,SHCreateLocalServerRunDll {601ac3dc-786a-4eb0-bf40-ee3521e70bfb}");
- (am-ShellExecute shapp "Rundll32.exe" "shdocvw.dll,OpenURL") ;//Internet 快捷方式 要IE8,IE7?
- (am-ShellExecute shapp "Rundll32.exe" "msconf.dll,OpenConfLink") ;//SpeedDial
- (am-ShellExecute shapp "Rundll32.exe" "zipfldr.dll,RouteTheCall") ;//压缩文件夹shdocvw.dll,OpenURL
- (am-ShellExecute shapp "Rundll32.exe" "netplwiz.dll,UsersRunDll") ;//用户帐户
- (am-ShellExecute shapp "Rundll32.exe" "shell32.dll,Options_RunDLL 0") ;//文件夹选项
- (am-ShellExecute shapp "Rundll32.exe" "shell32.dll,Options_RunDLL 1") ;//显示任务栏和开始菜单
- (am-ShellExecute shapp "Rundll32.exe" "shell32.dll,Control_RunDLLAsUser") ;//控制面版
;;执行程序
- (am-ShellExecute shapp "cmd.exe")
- (setq root (am-namespace shapp "c:\\windows\\system32"))
- (setq exec (am-parsename root "CMD.exe"))
- (am-invokeverb exec)
;;收藏夹
- (setq mark (vlax-create-object "Shell.UIHelper.1"))
- (vlax-invoke mark 'AddChannel "http://www.mjtd.com/")
- (vlax-invoke mark 'AddFavorite "http://www.mjtd.com" "MJTD")
- (vlax-invoke mark 'AddDesktopComponent "d:\\1.jpg" "image")
;;下面用来获取某些特殊目录下的文件信息
- (defun GetInfo(shapp folds / objs i obj name lst prop)
- (setq objs (am-items (am-namespace shapp folds))) ;这些常量可以智能查取
- (setq i 0)
- (repeat (ap-get-count objs)
- (setq obj (am-item objs i))
- (setq name (ap-get-name obj))
- (setq prop (am-ExtendedProperty obj "type"))
- (setq lst (cons (cons name prop) lst))
- (setq i (1+ i))
- )
- (reverse lst)
- )
;;例子
- (getInfo shapp ac-ssffonts) ;获取系统中安装的字体
- (getInfo shapp ac-ssfCONTROLS) ;获取有哪些控制面板
- (getInfo shapp ac-ssfMYPICTURES) ;获取我的图片
- (getInfo shapp ac-ssfDRIVES) ;获取系统的磁盘信息
- (getInfo shapp ac-ssfnetwork) ;网络
- (getInfo shapp ac-ssfsystem) ;系统文件夹信息
- (getInfo shapp ac-ssfnetwork) ;获得网上邻居
- (getInfo shapp ac-ssfRecent) ;获得最近打开
- ;;下面用来获得你浏览器(Explore)打开的窗口
- (defun GetWindows(shapp / i l lst obj winobj)
- (vlax-invoke shapp 'windows)
- (vlax-get (vlax-invoke shapp 'windows) 'count)
- (setq winobj (vlax-invoke shapp 'windows))
- (setq i 0)
- (repeat (vlax-get winobj 'count)
- (setq obj (vlax-invoke winobj 'item i))
- (setq lst (list
- (vlax-get obj 'toolbar)
- (vlax-get obj 'StatusText)
- (vlax-get obj 'FullName)
- (vlax-get obj 'LocationURL)
- (vlax-get obj 'Path)
- )
- )
- (setq l (cons lst l))
- (setq i (1+ i))
- )
- (reverse l)
- )
- (GetWindows shapp)
;;清空指针
- (vlax-release-object mark)
- (vlax-release-object root)
- (vlax-release-object file)
- (vlax-release-object exec)
- (vlax-release-object shapp)
- (princ)
|