View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default multiple monitors

I see one of the statements word-wrapped. Here is the same code again, but
using a line continuation to make sure the statement doesn't word-wrap....

'****************** Start Of Code ******************
Private Declare Function EnumDisplayMonitors Lib "user32.dll" _
(ByVal hdc As Long, ByRef lprcClip As Any, _
ByVal lpfnEnum As Long, ByVal dwData As Long) As Long

Private MonitorCount As Long

Public Function NumberOfMonitors()
MonitorCount = 0
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf _
MonitorEnumProc, ByVal 0&
NumberOfMonitors = MonitorCount
End Function

Private Function MonitorEnumProc()
MonitorCount = MonitorCount + 1
MonitorEnumProc = 1
End Function
'****************** End Of Code ******************

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
I'm pretty sure this will work. Put the following marked code in a Module
(Insert/Module from the VB editor's menu bar)...

'****************** Start Of Code ******************
Private Declare Function EnumDisplayMonitors Lib "user32.dll" _
(ByVal hdc As Long, ByRef lprcClip As Any, _
ByVal lpfnEnum As Long, ByVal dwData As Long) As Long

Private MonitorCount As Long

Public Function NumberOfMonitors()
MonitorCount = 0
EnumDisplayMonitors ByVal 0&, ByVal 0&, AddressOf MonitorEnumProc,
ByVal 0&
NumberOfMonitors = MonitorCount
End Function

Private Function MonitorEnumProc()
MonitorCount = MonitorCount + 1
MonitorEnumProc = 1
End Function
'****************** End Of Code ******************

And then simply call the NumberOfMonitors function from your own code. For
example...

Sub Test()
If NumberOfMonitors = 1 Then
MsgBox "There is only one monitor on this system."
Else
MsgBox "There are 2 or more monitors on this system"
End If
End Sub

--
Rick (MVP - Excel)


"Robert Flanagan" wrote in message
...
Is there a way to detect if a user has two or more monitors?

Bob