AutoHotkey Community

It is currently May 25th, 2012, 5:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 71 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: October 4th, 2007, 6:55 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
What does EnumDisplayDevices Example 2 output? Do either of the hotkeys do anything?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 3:36 pm 
im not sure about example2 its in comment and he said i should use the script as is. There's nothing in the "Script lines most recently executed.. window


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 3:55 pm 
ive tried use example2 like this... dont know if its right

Code:


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.


#+NumpadMult::EnableDisplayDevice("\\.\DISPLAY1", -1)
#+NumpadDiv::EnableDisplayDevice("\\.\DISPLAY2", -1)


; EnumDisplayDevices(Index [, ByRef Name, ByRef StateFlags ] )
;
; Index:        One-based index of device to get info for.
; DeviceName:   [out] The name of the device.
; StateFlags:   [out] Any reasonable combination of the following flags:
;   0x00000001      DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
;   0x00000004      DISPLAY_DEVICE_PRIMARY_DEVICE
;   0x00000008      DISPLAY_DEVICE_MIRRORING_DRIVER
; DeviceKey:    [out] Path to the device's registry key relative to HKEY_LOCAL_MACHINE.
;
; Returns true if the display device exists, otherwise false.
;
/* Example 1 (requires EnableDisplayDevice()):
    SecondaryDevice =
    count = 0
    Loop {
        if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
            break
        if !(StateFlags & 8) ; not a pseudo-device
            if (++count = 2) ; second device
                break
    }
    if DeviceName
        EnableDisplayDevice(DeviceName, -1) ; toggle
*/
/* Example 2:
    Loop {
        if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
            break
        if (StateFlags & 4)
            text .= DeviceName " is the primary display device.`n"
        else if (StateFlags & 1)
            text .= "The desktop extends onto " DeviceName ".`n"
        if (StateFlags & 8)
            text .= DeviceName " is a pseudo-device.`n"
    }
    MsgBox %text%
*/
EnumDisplayDevices(Index, ByRef DeviceName, ByRef StateFlags="", ByRef DeviceKey="")
{
    ; DISPLAY_DEVICE DisplayDevice
    VarSetCapacity(DisplayDevice, 424)
    ; lpDisplayDevice.cb := sizeof(DISPLAY_DEVICE)
    NumPut(424, DisplayDevice, 0)
   
    VarSetCapacity(DeviceName, 32, 0)
    VarSetCapacity(DeviceKey, 128, 0)
    ; For consistency, clear StateFlags in case of failure.
    StateFlags = 0
   
    if ! DllCall("EnumDisplayDevices"
        , "UInt", 0
        , "UInt", Index-1
        , "UInt", &DisplayDevice
        , "UInt", 0)
        return false
   
    StateFlags := NumGet(DisplayDevice, 164)
    DllCall("lstrcpynA", "Str", DeviceName, "UInt", &DisplayDevice+4,   "int", 32)
    DllCall("lstrcpynA", "Str", DeviceKey,  "UInt", &DisplayDevice+296, "int", 128)
    if (SubStr(DeviceKey,1,18)="\Registry\Machine\")
        DeviceKey := SubStr(DeviceKey,19)
    return true
}

; Enables, disables or toggles a display device.
;
; DeviceName:   The name of the device, e.g. \\.\DISPLAY1
; Action:       The action to take.
;                    0   Disable
;                    1   Enable
;                   -1   Toggle (may not be reliable if NoReset=true)
; NoReset:      If true, settings will be saved to the registry, but not applied.
;
; The following can be used to apply settings saved in the registry:
;   DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
;
; Return values:
;    DISP_CHANGE_SUCCESSFUL       0
;    DISP_CHANGE_RESTART          1
;    DISP_CHANGE_FAILED          -1
;    DISP_CHANGE_BADMODE         -2
;    DISP_CHANGE_NOTUPDATED      -3
;    DISP_CHANGE_BADFLAGS        -4
;    DISP_CHANGE_BADPARAM        -5
;
; Examples:
;   ; disable display 2
;     EnableDisplayDevice("\\.\DISPLAY2", 0)
;     Sleep, 10000
;
;   ; simultaneously enable display 2 and disable display 1
;     EnableDisplayDevice("\\.\DISPLAY2", 1, true)
;     EnableDisplayDevice("\\.\DISPLAY1", 0)
;     Sleep, 10000
;
;   ; ensure both are enabled
;     EnableDisplayDevice("\\.\DISPLAY2", 1, true)
;     EnableDisplayDevice("\\.\DISPLAY1")
;
; Note: DeviceNames may vary. Rather than hard-coding the device name,
;       EnumDisplayDevices() should be used to enumerate the devices.
;
EnableDisplayDevice(DeviceName, Action=1, NoReset=false)
{
    if (Action = -1)
    {   ; Determine if the display should be enabled or disabled.
          Loop {
        if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
            break
        if (StateFlags & 4)
            text .= DeviceName " is the primary display device.`n"
        else if (StateFlags & 1)
            text .= "The desktop extends onto " DeviceName ".`n"
        if (StateFlags & 8)
            text .= DeviceName " is a pseudo-device.`n"
    }
    MsgBox %text%
    }

    VarSetCapacity(devmode, 156, 0)
    NumPut(156, devmode, 36, "UShort")

    ; Set DEVMODE.dmFields to indicate which fields are valid.
    if (Action) ; Enable
        NumPut(0x000020, devmode, 40)   ; position={0,0}
    else        ; Disable
        NumPut(0x180020, devmode, 40)   ; width=0, height=0, position={0,0}

    ; Since CDS_NORESET is specified here, if NoReset=true, the user must
    ; manually call ChangeDisplaySettings(NULL,1) or restart the computer.
    err := DllCall("ChangeDisplaySettingsEx", "str", DeviceName
        , "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 && !NoReset)
        err := DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
   
    return err
}



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 4:18 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
novis wrote:
im not sure about example2 its in comment and he said i should use the script as is.
Sorry, just uncomment it. :)

Running this as is should output a list of display device names:
Code:
; EnumDisplayDevices(Index [, ByRef Name, ByRef StateFlags ] )
;
; ... removed "documentation"
;
;/* Example 2:
    Loop {
        if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
            break
        if (StateFlags & 4)
            text .= DeviceName " is the primary display device.`n"
        else if (StateFlags & 1)
            text .= "The desktop extends onto " DeviceName ".`n"
        if (StateFlags & 8)
            text .= DeviceName " is a pseudo-device.`n"
    }
    MsgBox %text%
;*/
EnumDisplayDevices(Index, ByRef DeviceName, ByRef StateFlags="", ByRef DeviceKey="")
{
    ; DISPLAY_DEVICE DisplayDevice
    VarSetCapacity(DisplayDevice, 424)
    ; lpDisplayDevice.cb := sizeof(DISPLAY_DEVICE)
    NumPut(424, DisplayDevice, 0)
   
    VarSetCapacity(DeviceName, 32, 0)
    VarSetCapacity(DeviceKey, 128, 0)
    ; For consistency, clear StateFlags in case of failure.
    StateFlags = 0
   
    if ! DllCall("EnumDisplayDevices"
        , "UInt", 0
        , "UInt", Index-1
        , "UInt", &DisplayDevice
        , "UInt", 0)
        return false
   
    StateFlags := NumGet(DisplayDevice, 164)
    DllCall("lstrcpynA", "Str", DeviceName, "UInt", &DisplayDevice+4,   "int", 32)
    DllCall("lstrcpynA", "Str", DeviceKey,  "UInt", &DisplayDevice+296, "int", 128)
    if (SubStr(DeviceKey,1,18)="\Registry\Machine")
        DeviceKey := SubStr(DeviceKey,19)
    return true
}

Pressing Ctrl+C at the message box should copy the list to the clipboard.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 5:17 pm 
---------------------------
enableDev.ahk
---------------------------
\\.\DISPLAY1 is the primary display device.
\\.\DISPLAYV1 is a pseudo-device.

---------------------------
OK
---------------------------


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 5:34 pm 
i wonder if matrox locked it somehow ..for instance i cant change Res from rightclicking on desktop. Only from "Matrox-Powerdesk SE"


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 5:57 pm 
ok now ive messed things up :/

in my matrox powerdesk util i changed from:

Use Advanced Matrox Display Controls

to

Use Windows Display Controls

and now .txt files opens minimized ...weird. other shortcuts opens normal.
ive changed it back and it remains like that. hmm


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 6:42 pm 
hmm 4th post ..cant edit post?

i had to do a complete removal of matrox driver to get rid of it all. now its all good.

ive tried this (now using Windows Display Control)
still nothing..


Code:
#NoEnv

#+NumpadDiv::EnableDisplayDevice("\\.\DISPLAYV1", 1)

EnableDisplayDevice(DeviceName, Action=1, NoReset=false)
{
    if (Action = -1)
    {
        Loop {
            if ! EnumDisplayDevices(A_Index, this_name, this_state)
                break
            if (this_name = DeviceName) {
                Action := !(this_state & 1) ; DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
                break
            }
        }
    }

    VarSetCapacity(devmode, 156, 0)
    NumPut(156, devmode, 36, "UShort")

    if (Action) ; Enable
        NumPut(0x000020, devmode, 40)   ; position={0,0}
    else        ; Disable
        NumPut(0x180020, devmode, 40)   ; width=0, height=0, position={0,0}

    err := DllCall("ChangeDisplaySettingsEx", "str", DeviceName
        , "uint", &devmode, "uint", 0, "uint", 0x10000001, "uint", 0)
   
    if (!err && !NoReset)
        err := DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
   
    return err
}

;/* Example 2:
    Loop {
        if ! EnumDisplayDevices(A_Index, DeviceName, StateFlags)
            break
        if (StateFlags & 4)
            text .= DeviceName " is the primary display device.`n"
        else if (StateFlags & 1)
            text .= "The desktop extends onto " DeviceName ".`n"
        if (StateFlags & 8)
            text .= DeviceName " is a pseudo-device.`n"
    }
    MsgBox %text%
;*/
EnumDisplayDevices(Index, ByRef DeviceName, ByRef StateFlags="", ByRef DeviceKey="")
{
    ; DISPLAY_DEVICE DisplayDevice
    VarSetCapacity(DisplayDevice, 424)
    ; lpDisplayDevice.cb := sizeof(DISPLAY_DEVICE)
    NumPut(424, DisplayDevice, 0)
   
    VarSetCapacity(DeviceName, 32, 0)
    VarSetCapacity(DeviceKey, 128, 0)
    ; For consistency, clear StateFlags in case of failure.
    StateFlags = 0
   
    if ! DllCall("EnumDisplayDevices"
        , "UInt", 0
        , "UInt", Index-1
        , "UInt", &DisplayDevice
        , "UInt", 0)
        return false
   
    StateFlags := NumGet(DisplayDevice, 164)
    DllCall("lstrcpynA", "Str", DeviceName, "UInt", &DisplayDevice+4,   "int", 32)
    DllCall("lstrcpynA", "Str", DeviceKey,  "UInt", &DisplayDevice+296, "int", 128)
    if (SubStr(DeviceKey,1,18)="\Registry\Machine\")
        DeviceKey := SubStr(DeviceKey,19)
    return true
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 4th, 2007, 11:01 pm 
Online
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8657
Location: Salem, MA
if you register, you can edit your new posts.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 1:56 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
novis wrote:
ive tried this (now using Windows Display Control)
still nothing..
Code:
#+NumpadDiv::EnableDisplayDevice("\\.\DISPLAYV1", 1)

\\.\DISPLAYV1 isn't a "real" display device. Try running the script (example 2) again, assuming you haven't since you uninstalled the Matrox drivers.
Quote:
\\.\DISPLAY1 is the primary display device.
\\.\DISPLAYV1 is a pseudo-device.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 8:45 pm 
ok but then what should i do with the output
Quote:
---------------------------
enableDev.ahk
---------------------------
\\.\DISPLAY1 is the primary display device.
\\.\DISPLAYV1 is a pseudo-device.

---------------------------
OK
---------------------------


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2007, 10:40 am 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
I also tried this and couldnt get it to work.

I used
Code:
EnableDisplayDevice("\\.\DISPLAY2", 1)


where \\.\DISPLAY2 is the name reported by enumdisplay adapters when my second monitor was on. But it did nothing.

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2008, 11:19 pm 
lexiKos, I've read through this thread several times now and I'm still very confused on what I need to get this up and running. Could you post a version of the script for us beginners, a version that includes everything in one package -- all needed functions, all hotkey code and so on?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2008, 8:57 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Superfraggle wrote:
I also tried this and couldnt get it to work.

I used
Code:
EnableDisplayDevice("\\.\DISPLAY2", 1)


where \\.\DISPLAY2 is the name reported by enumdisplay adapters when my second monitor was on. But it did nothing.
If your second monitor was already on, attempting to turn it on should do nothing. :P Use -1 to toggle or 0 to turn it off. Sorry for not replying sooner; I guess I missed your post.

Here is an updated EnableDisplayDevice:
Code:
; Enables, disables or toggles a display device.
;
; DeviceName:   The name of the device, e.g. \\.\DISPLAY1
;               Alternatively, it can be the index of the device, which might
;               not be the same as the number shown in Display Settings.
; Action:       The action to take.
;                    0   Disable (false is synonymous with 0)
;                    1   Enable (true is synonymous with 1)
;                   -1   Toggle
; NoReset:      If true, settings will be saved to the registry, but not applied.
;
; The following can be used to apply settings saved in the registry:
;   DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
;
; Return values:
;    DISP_CHANGE_SUCCESSFUL       0
;    DISP_CHANGE_RESTART          1
;    DISP_CHANGE_FAILED          -1
;    DISP_CHANGE_BADMODE         -2
;    DISP_CHANGE_NOTUPDATED      -3
;    DISP_CHANGE_BADFLAGS        -4
;    DISP_CHANGE_BADPARAM        -5
;
EnableDisplayDevice(DeviceName, Action=1, NoReset=false)
{
    if (Action = -1) || (DeviceName+0 != "")
    {
        VarSetCapacity(DisplayDevice, 424), NumPut(424, DisplayDevice, 0)
        VarSetCapacity(ThisDeviceName, 32, 0)
        Index = 0
        Loop {
            if !DllCall("EnumDisplayDevices", "UInt", 0, "UInt", A_Index-1, "UInt", &DisplayDevice, "UInt", 0)
                return -5
            ThisDeviceState := NumGet(DisplayDevice, 164)
            Index += 1
            DllCall("lstrcpynA", "Str", ThisDeviceName, "UInt", &DisplayDevice+4, "int", 32)
            if (DeviceName = Index || DeviceName = ThisDeviceName)
            {
                if Action = -1
                    Action := !(ThisDeviceState & 1)
                DeviceName := ThisDeviceName
                break
            }
        }
    }
    VarSetCapacity(devmode, 156, 0), NumPut(156, devmode, 36, "UShort")
    if Action
        NumPut(0x000020, devmode, 40) ; Enable by setting position = {0,0}
    else
        NumPut(0x180020, devmode, 40) ; Disable by setting size = {0,0}
    err := DllCall("ChangeDisplaySettingsEx", "str", DeviceName, "uint", &devmode, "uint", 0, "uint", 0x10000001, "uint", 0)
    if !err && !NoReset
        err := DllCall("ChangeDisplaySettings", "uint", 0, "uint", 1)
    return err, ErrorLevel:=Action
}
It can be used as follows:
Code:
; disable display 2
EnableDisplayDevice(2, false)
Sleep, 10000

; simultaneously enable display 2 and disable display 1
EnableDisplayDevice(2, true, true)
EnableDisplayDevice(1, false)
Sleep, 10000

; ensure both are enabled
EnableDisplayDevice(2, true, true)
EnableDisplayDevice(1)

(Edit: corrected comment about device numbering and display settings.)


Last edited by Lexikos on March 13th, 2008, 7:17 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2008, 11:55 am 
Thank you! But I get an error:
call to nonexistent function
specifically: NumPut(424, DisplayDevice, 0)

http://img394.imageshack.us/img394/1464/errormj7.png


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 71 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Cephei1, cmikaiti, DetroitAutoHotkey, ogrish, Rathgar2, SKAN, vinniel, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group