Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Setting Primary Display

Setting Primary Display

Scheduled Pinned Locked Moved Visual Basic
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jayme65
    wrote on last edited by
    #1

    Hi, I'm trying to set the Primary Display...without success! Here's the code I'm working on, would you please help me see what I'm doing wrong there? There's no compilation error...it simply doesn't give the expected result! Thank you!!

    Imports System.Runtime.InteropServices
    Class MainWindow
    Const CCDEVICENAME As Short = 32
    Const CCFORMNAME As Short = 32

    Private Const MONITORINFOF\_PRIMARY As Integer = &H1
    Private Const DISPLAY\_DEVICE\_ATTACHED\_TO\_DESKTOP As Integer = &H1
    Private Const DISPLAY\_DEVICE\_PRIMARY\_DEVICE As Integer = &H4
    Private Const DISPLAY\_DEVICE\_MIRRORING\_DRIVER As Integer = &H8
    Private Const DISPLAY\_DEVICE\_VGA\_COMPATIBLE As Integer = &H10
    Private Const DISPLAY\_DEVICE\_REMOVABLE As Integer = &H20
    Private Const DISPLAY\_DEVICE\_MODESPRUNED As Integer = &H8000000
    
    Private Const DM\_POSITION = &H20
    Private Const DM\_DISPLAYORIENTATION = &H80 ' XP only
    Private Const DM\_BITSPERPEL = &H40000
    Private Const DM\_PELSWIDTH = &H80000
    Private Const DM\_PELSHEIGHT = &H100000
    Private Const DM\_DISPLAYFLAGS = &H200000
    Private Const DM\_DISPLAYFREQUENCY = &H400000
    'Private Const DM\_DISPLAYFIXEDOUTPUT As Long = &H20000000 ' XP only
    
    Private Const ENUM\_CURRENT\_SETTINGS As Integer = -1
    Private Const ENUM\_REGISTRY\_SETTINGS As Integer = -2
    Private Const EDS\_RAWMODE As Integer = &H2
    
    Private Const CDS\_UPDATEREGISTRY As Integer = &H1
    Private Const CDS\_TEST As Integer = &H2
    Private Const CDS\_FULLSCREEN As Integer = &H4
    Private Const CDS\_GLOBAL As Integer = &H8
    Private Const CDS\_SET\_PRIMARY As Integer = &H10
    Private Const CDS\_VIDEOPARAMETERS As Integer = &H20
    Private Const CDS\_NORESET As Integer = &H10000000
    Private Const CDS\_RESET As Integer = &H40000000
    Private Const CDS\_FORCE As Integer = &H80000000
    Private Const CDS\_NONE As Integer = 0
    
    Public Structure PointL
        Dim x As Integer
        Dim y As Integer
    End Structure
    
    \_
    Enum DisplayDeviceStateFlags As Integer
        AttachedToDesktop = &H1
        MultiDriver = &H2
        PrimaryDevice = &H4
        MirroringDriver = &H8
        VGACompatible = &H10
        Removable = &H20
        ModesPruned = &H8000000
        Remote = &H4000000
        Disconnect = &H2000000
    End Enum
    
    '0 is Not Attached
    
    Const DISPLAY\_PRIMARY\_DEVICE = &H4 'Primary device
    
    'Holds the information of display adpter
    Private Structure DISPLAY\_DEVICE
    
    Richard Andrew x64R 1 Reply Last reply
    0
    • J Jayme65

      Hi, I'm trying to set the Primary Display...without success! Here's the code I'm working on, would you please help me see what I'm doing wrong there? There's no compilation error...it simply doesn't give the expected result! Thank you!!

      Imports System.Runtime.InteropServices
      Class MainWindow
      Const CCDEVICENAME As Short = 32
      Const CCFORMNAME As Short = 32

      Private Const MONITORINFOF\_PRIMARY As Integer = &H1
      Private Const DISPLAY\_DEVICE\_ATTACHED\_TO\_DESKTOP As Integer = &H1
      Private Const DISPLAY\_DEVICE\_PRIMARY\_DEVICE As Integer = &H4
      Private Const DISPLAY\_DEVICE\_MIRRORING\_DRIVER As Integer = &H8
      Private Const DISPLAY\_DEVICE\_VGA\_COMPATIBLE As Integer = &H10
      Private Const DISPLAY\_DEVICE\_REMOVABLE As Integer = &H20
      Private Const DISPLAY\_DEVICE\_MODESPRUNED As Integer = &H8000000
      
      Private Const DM\_POSITION = &H20
      Private Const DM\_DISPLAYORIENTATION = &H80 ' XP only
      Private Const DM\_BITSPERPEL = &H40000
      Private Const DM\_PELSWIDTH = &H80000
      Private Const DM\_PELSHEIGHT = &H100000
      Private Const DM\_DISPLAYFLAGS = &H200000
      Private Const DM\_DISPLAYFREQUENCY = &H400000
      'Private Const DM\_DISPLAYFIXEDOUTPUT As Long = &H20000000 ' XP only
      
      Private Const ENUM\_CURRENT\_SETTINGS As Integer = -1
      Private Const ENUM\_REGISTRY\_SETTINGS As Integer = -2
      Private Const EDS\_RAWMODE As Integer = &H2
      
      Private Const CDS\_UPDATEREGISTRY As Integer = &H1
      Private Const CDS\_TEST As Integer = &H2
      Private Const CDS\_FULLSCREEN As Integer = &H4
      Private Const CDS\_GLOBAL As Integer = &H8
      Private Const CDS\_SET\_PRIMARY As Integer = &H10
      Private Const CDS\_VIDEOPARAMETERS As Integer = &H20
      Private Const CDS\_NORESET As Integer = &H10000000
      Private Const CDS\_RESET As Integer = &H40000000
      Private Const CDS\_FORCE As Integer = &H80000000
      Private Const CDS\_NONE As Integer = 0
      
      Public Structure PointL
          Dim x As Integer
          Dim y As Integer
      End Structure
      
      \_
      Enum DisplayDeviceStateFlags As Integer
          AttachedToDesktop = &H1
          MultiDriver = &H2
          PrimaryDevice = &H4
          MirroringDriver = &H8
          VGACompatible = &H10
          Removable = &H20
          ModesPruned = &H8000000
          Remote = &H4000000
          Disconnect = &H2000000
      End Enum
      
      '0 is Not Attached
      
      Const DISPLAY\_PRIMARY\_DEVICE = &H4 'Primary device
      
      'Holds the information of display adpter
      Private Structure DISPLAY\_DEVICE
      
      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Well did you step through it in the debugger and check the return values from the functions that do the work? You need to narrow it down to exactly which function call is not working as intended.

      The difficult we do right away... ...the impossible takes slightly longer.

      J 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Well did you step through it in the debugger and check the return values from the functions that do the work? You need to narrow it down to exactly which function call is not working as intended.

        The difficult we do right away... ...the impossible takes slightly longer.

        J Offline
        J Offline
        Jayme65
        wrote on last edited by
        #3

        It returns a 0 (DISP_CHANGE_SUCCESSFUL) !!

        Richard Andrew x64R 1 Reply Last reply
        0
        • J Jayme65

          It returns a 0 (DISP_CHANGE_SUCCESSFUL) !!

          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Did you study the documentation? ChangeDisplaySettingsEx function (Windows)[^]

          The difficult we do right away... ...the impossible takes slightly longer.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups