News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Enable a second monitor

Started by zooba, May 28, 2006, 05:59:56 AM

Previous topic - Next topic

zooba

Just spent half a day figuring this out and thought I'd post it:

.data?
    dmDevice        DEVMODE     <>
.data
    szDisp1         BYTE        "\\.\DISPLAY1", 0
    szDisp2         BYTE        "\\.\DISPLAY2", 0

.code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

EnableSecondMonitor PROC USES edi
    mov     dmDevice.dmSize, SIZEOF DEVMODE
    mov     dmDevice.dmDriverExtra, 0
    invoke  EnumDisplaySettings, OFFSET szDisp1, ENUM_CURRENT_SETTINGS, OFFSET dmDisp1
   
    push    dmDevice.dmPelsWidth
    invoke  EnumDisplaySettings, OFFSET szDisp2, ENUM_CURRENT_SETTINGS, OFFSET dmDisp2
   
    pop     dmDevice.dmPosition.x   ; position at right
   
    mov     dmDevice.dmFields, DM_POSITION
    invoke  ChangeDisplaySettingsEx, OFFSET dmDisp2, OFFSET dmDevice, 0, CDS_UPDATEREGISTRY, 0
    invoke  ChangeDisplaySettingsEx, 0, 0, 0, 0, 0
   
    ret
EnableSecondMonitor ENDP

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

DisableSecondMonitor PROC USES edi
    mov     dmDevice.dmSize, SIZEOF DEVMODE
    mov     dmDevice.dmDriverExtra, 0
   
    invoke  EnumDisplaySettings, OFFSET szDisp2, ENUM_CURRENT_SETTINGS, OFFSET dmDisp2
    mov     dmDevice.dmPelsWidth, 0     ; turn off the monitor
    mov     dmDevice.dmPelsHeight, 0
   
    mov     dmDevice.dmFields, DM_POSITION
    invoke  ChangeDisplaySettingsEx, OFFSET dmDisp2, OFFSET dmDevice, 0, CDS_UPDATEREGISTRY, 0
    invoke  ChangeDisplaySettingsEx, 0, 0, 0, 0, 0
   
    ret
DisableSecondMonitor ENDP


This will enable the second monitor (I think it needs to have been enabled before) and locate it's left edge against the first monitor's right edge. It shouldn't be too hard to modify the code to put it elsewhere, but make sure it uses the right dimensions - the monitors must touch along an edge.

Cheers,

Zooba :U