在研究了上面链接中的VBA代码后,我尝试将其转换为AutoLISP:
- (defun CountMonitors( / regPath listMonitors device id theType IsMonitor displayCount )
- ;registry path that store registred monitors (in use or discontinued)
- (setq regPath "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\")
- ;gather all registred "display" devices (monitors or other)
- (setq listMonitors (vl-registry-descendents regPath))
- (setq device (car listMonitors))
- (setq displayCount 0)
- ;parse "display" devices
- (foreach device listMonitors
- (setq id (vl-registry-descendents (strcat regPath device))) ;get product ID for this device
- (if id
- (progn
- (setq device (strcat regPath device "\" (car id))
- theType (vl-registry-read device "HardwareID")) ;list entries under hardware ID
- (if (not (listp theType)) (setq theType (list theType))) ;not sure if above key return always a list !!!
- (setq IsMonitor nil)
- (foreach val theType ;check if device is a monitor
- (if (and (equal (type val) 'STR)
- (wcmatch val "Monitor\\*"))
- (setq IsMonitor T)
- )
- )
- ;if device is a monitor check if is attached (should have a sub-key named "Control")
- (if IsMonitor
- (if (member "Control"
- (vl-registry-descendents device))
- (setq displayCount (1+ displayCount)) ;count current monitor
- )
- )
- )
- )
- )
- (if (> displayCount 0)
- (alert (strcat "Your workstation have " (itoa displayCount) " monitor" (if (= displayCount 1) "" "s") "!"))
- (alert "Unable to detect monitor on this workstation!")
- )
- displayCount ;return number of monitors on workstation
- )
不幸的是,直到星期一,我才能在有两个监视器的工作站上测试这一点。
当做
米尔恰 |