Post Reply

Forums -> Multiple monitors -> Enabling Multi-Monitor with VB??
Nathan   2004-02-01 23:18

Hello All! I am trying to write a small VB app that will switch on my second monitor - my IBM Thinkpad had WinXP, and whenever I undock it then redock later, it "forgets" the multi-monitor settings. I want to write a small app that detects on boot if the machine is docked and switches on the multi-monitor if it is. I have tried using the code below to enable the multi-monitor (and a hundred other combinations), and while I always get a return code of 0 (DISP_CHANGE_SUCCESSFUL) it never actually switches on the second montior - any suggestions??

Do While EnumDisplayDevices(dd.DeviceName, devMon, ddMon, 0) <> 0
If CBool(ddMon.StateFlags And DISPLAY_DEVICE_ACTIVE) Then Exit Do
devMon = devMon + 1
Loop

Dim dm As DEVMODE
dm.dmSize = Len(dm)
If EnumDisplaySettingsEx(dd.DeviceName, ENUM_CURRENT_SETTINGS, dm, 0) = 0 Then
EnumDisplaySettingsEx dd.DeviceName, ENUM_REGISTRY_SETTINGS, dm, 0
End If

If CBool(dd.StateFlags And DISPLAY_DEVICE_PRIMARY_DEVICE) Then
If InStr(LCase(CStrToVBStr(ddMon.DeviceString)), "lcd panel") <> 0 Then
MsgBox "Running on LCD display - not changing..."
End
End If
Else
If Not CBool(dd.StateFlags And DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) Then
If MsgBox("Would you like to enable dual-monitor?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then
' TODO: Turn it on
Dim DevM As DEVMODE
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_POSITION
DevM.dmPelsHeight = 768
DevM.dmPelsWidth = 1024
DevM.dmPosition.X = -1024
DevM.dmPosition.Y = 0

rc = ChangeDisplaySettingsEx(dd.DeviceName, DevM, ByVal 0&, CDS_NORESET, ByVal 0&)

Call ChangeDisplaySettings(ByVal 0&, 0)
If rc <> DISP_CHANGE_SUCCESSFUL Then
MsgBox "Unable to switch to dual-screen mode.", vbExclamation
End
End If

End If
...
Forums -> Multiple monitors -> Enabling Multi-Monitor with VB??

Post Reply