Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Move second monitor position


  • Please log in to reply
6 replies to this topic
davidcj
  • Members
  • 1 posts
  • Last active: Feb 21 2009 01:16 AM
  • Joined: 21 Feb 2009
I have a two monitor setup on an XP machine. I would like to be able to go to display\settings and move the relative positions of the monitors. When I use Autoscriptwriter, it does not record the movements I make. The relative positions remain unchanged.

Any ideas of how to do this? :?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
DisplayPosition_Set(device_name, x, y, defer=false)
{
    ; Prepare the DEVMODE structure.
    VarSetCapacity(devmode, 158, 0), NumPut(158, devmode, 0, "ushort")
    ; Get current display settings. -1=current, -2=registry
    DllCall("EnumDisplaySettings","str",device_name,"int",-1,"uint",&devmode)
    if ! NumGet(devmode, 108) ; dmPelsWidth (=0 means display is disabled)
        DllCall("EnumDisplaySettings","str",device_name,"int",-2,"uint",&devmode)
    
    ; dmFlags |= DM_POSITION
    NumPut(NumGet(devmode,40)|0x20, devmode, 40)
        
    ; dmPosition.X := x, dmPosition.Y := y
    NumPut(x,devmode,44,"int"), NumPut(y,devmode,48,"int")

    err := DllCall("ChangeDisplaySettingsEx","str",device_name,"uint",&devmode,"uint",0,"uint",0x10000001,"uint",0)
    
    ; ChangeDisplaySettings() is called here for two reasons:
    ;   - A restart is otherwise required to enable a secondary display device.
    ;       See: http://support.microsoft.com/kb/308216
    ;   - Disabling display devices with just ChangeDisplaySettingsEx()
    ;     tends to leave them turned on.
    if (!err && !defer)
        err := DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
    
    return err
}
Your second display is probably "\\.\DISPLAY2", but on my system 1 and 2 seem to swap around randomly when I enable/disable displays. :? Might be a Windows 7 quirk...

For example, if display 2 is 1680x1050, the following puts it to the left of the primary and 100 pixels up.
DisplayPosition_Set("\\.\DISPLAY2", -1680, -100)
I originally used this to simultaneously enable and position a display.

lq
  • Guests
  • Last active:
  • Joined: --
I get this error when I try to use the script:

"Error: Call to nonexistent function.

Specifically: StdOut(NumGet(devmode, 108),"width")"
...
"---> 024: if ! StdOut(NumGet(devmode, 108),"width")
025: DllCall("EnumDisplaySettings","str",device_name,"int",-2,"uint",&devmode) "

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Sorry, I left some debug code in. Just remove the bits in red:
if ! [color=red]StdOut([/color]NumGet(devmode, 108)[color=red],"width")[/color]


lq
  • Guests
  • Last active:
  • Joined: --
thanks!

lq
  • Guests
  • Last active:
  • Joined: --
Lexikos,

Where can I find information on what DllCalls I need to change certain OS settings?

What other programming languages do I have to be able to write AHK scripts such as this one.

For example, which dll and which function do I have to call to change the behaviour of a particular systray icon? (always hide, hide when inactive, always visible)

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

For example, which dll and which function do I have to call to change the behaviour of a particular systray icon? (always hide, hide when inactive, always visible)


You can learn all yourself, like I do since I know and love AHK :D

MSDN and Google is where you get all info you need.
Example: [Lib] TrayIcon_...()