Click here to Skip to main content
15,885,216 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
Sascha Lefèvre26-Jan-16 10:15
professionalSascha Lefèvre26-Jan-16 10:15 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
satc26-Jan-16 10:27
satc26-Jan-16 10:27 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
Sascha Lefèvre26-Jan-16 11:23
professionalSascha Lefèvre26-Jan-16 11:23 
Questionbouton imprimer DGV complet Pin
Dorsaf Ouersighni25-Jan-16 4:54
Dorsaf Ouersighni25-Jan-16 4:54 
SuggestionRe: bouton imprimer DGV complet Pin
Richard Deeming25-Jan-16 5:15
mveRichard Deeming25-Jan-16 5:15 
GeneralRe: bouton imprimer DGV complet Pin
Dorsaf Ouersighni25-Jan-16 20:45
Dorsaf Ouersighni25-Jan-16 20:45 
QuestionXML Datagridview control & saving changes Pin
Dan Chapin25-Jan-16 3:40
Dan Chapin25-Jan-16 3:40 
QuestionSetting Primary Display Pin
Jayme6518-Jan-16 23:33
Jayme6518-Jan-16 23:33 
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!!

VB
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
 
    <Flags()> _
    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
        Public cb As Integer
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> Public DeviceName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public DeviceString As String
        Public StateFlags As Short
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public DeviceID As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public DeviceKey As String
    End Structure
 
    'Holds the setting of display adapter
    Private Structure DEVMODE
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
        Public dmDeviceName As String
        Public dmSpecVersion As Short
        Public dmDriverVersion As Short
        Public dmSize As Short
        Public dmDriverExtra As Short
        Public dmFields As Integer
        Public dmOrientation As Short
        'Public dmPaperSize As Short
        'Public dmPaperLength As Short
        'Public dmPaperWidth As Short
        'Public dmScale As Short
        Public dmPositionX As Integer
        Public dmPositionY As Integer
        Public dmCopies As Short
        Public dmDefaultSource As Short
        Public dmPrintQuality As Short
        Public dmColor As Short
        Public dmDuplex As Short
        Public dmYResolution As Short
        Public dmTTOption As Short
        Public dmCollate As Short
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> _
        Public dmFormName As String
        Public dmLogPixels As Short
        Public dmBitsPerPel As Short
        Public dmPelsWidth As Integer
        Public dmPelsHeight As Integer
        Public dmDisplayFlags As Integer
        Public dmDisplayFrequency As Integer
        Public dmICMMethod As Integer
        Public dmICMIntent As Integer
        Public dmMediaType As Integer
        Public dmDitherType As Integer
        Public dmReserved1 As Integer
        Public dmReserved2 As Integer
        Public dmPanningWidth As Integer
        Public dmPanningHeight As Integer
        'Public dmPosition As Point
        'Public dmPositionX As Integer
        'Public dmPositionY As Integer
    End Structure
 
    'API declaration set or get display adpter information
    <DllImport("user32.dll")> _
    Private Shared Function EnumDisplayDevices(ByVal Unused As Integer, _
    ByVal iDevNum As Short, ByRef lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Integer) As Integer
    End Function
 
    <DllImport("user32.dll")> _
    Private Shared Function EnumDisplaySettings(ByVal lpszDeviceName As String, _
    ByVal iModeNum As Integer, ByRef lpDevMode As DEVMODE) As Integer
    End Function
 
    <DllImport("user32.dll")> _
    Private Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, _
    ByRef lpDevMode As DEVMODE, ByVal hWnd As Integer, ByVal dwFlags As Integer, _
    ByVal lParam As Integer) As Integer
    End Function
    <DllImport("user32.dll")> _
    Private Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, _
    ByRef lpDevMode As IntPtr, ByVal hWnd As Integer, ByVal dwFlags As Integer, _
    ByVal lParam As Integer) As Integer
    End Function
 
Public Sub SetAsPrimaryMonitor(id As UInteger)
        Dim device = New DISPLAY_DEVICE()
        Dim deviceMode = New DEVMODE()
        device.cb = Marshal.SizeOf(device)
 
        EnumDisplayDevices(Nothing, id, device, 0)
        EnumDisplaySettings(device.DeviceName, -1, deviceMode)
        Dim offsetx = deviceMode.dmPositionX
        Dim offsety = deviceMode.dmPositionY
        deviceMode.dmPositionX = 0
        deviceMode.dmPositionY = 0
 
        ChangeDisplaySettingsEx(device.DeviceName, deviceMode, 0, (CDS_SET_PRIMARY Or CDS_UPDATEREGISTRY Or CDS_NORESET), 0)
 
        device = New DISPLAY_DEVICE()
        device.cb = Marshal.SizeOf(device)
 
        ' Update remaining devices
        Dim otherid As UInteger = 0
        While EnumDisplayDevices(Nothing, otherid, device, 0)
 
            If device.StateFlags = DisplayDeviceStateFlags.AttachedToDesktop AndAlso otherid <> id Then
                device.cb = Marshal.SizeOf(device)
                Dim otherDeviceMode = New DEVMODE()
 
                EnumDisplaySettings(device.DeviceName, -1, otherDeviceMode)
 
                otherDeviceMode.dmPositionX -= offsetx
                otherDeviceMode.dmPositionY -= offsety
 
                ChangeDisplaySettingsEx(device.DeviceName, otherDeviceMode, 0, (CDS_UPDATEREGISTRY Or CDS_NORESET), 0)
            End If
 
            device.cb = Marshal.SizeOf(device)
            otherid += 1
        End While
 
        ' Apply settings
        ChangeDisplaySettingsEx(Nothing, 0, 0, CDS_NONE, 0)
    End Sub
 
    Private Sub Button1_Click_1(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
        SetAsPrimaryMonitor(0)
    End Sub
End Class


modified 19-Jan-16 5:55am.

AnswerRe: Setting Primary Display Pin
Richard Andrew x6419-Jan-16 4:39
professionalRichard Andrew x6419-Jan-16 4:39 
GeneralRe: Setting Primary Display Pin
Jayme6519-Jan-16 6:46
Jayme6519-Jan-16 6:46 
GeneralRe: Setting Primary Display Pin
Richard Andrew x6419-Jan-16 8:05
professionalRichard Andrew x6419-Jan-16 8:05 
QuestionThread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx14-Jan-16 7:49
professionaljkirkerx14-Jan-16 7:49 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Sascha Lefèvre14-Jan-16 8:10
professionalSascha Lefèvre14-Jan-16 8:10 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx14-Jan-16 8:33
professionaljkirkerx14-Jan-16 8:33 
AnswerRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Sascha Lefèvre14-Jan-16 9:40
professionalSascha Lefèvre14-Jan-16 9:40 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx14-Jan-16 11:06
professionaljkirkerx14-Jan-16 11:06 
AnswerRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus15-Jan-16 0:05
Wombaticus15-Jan-16 0:05 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx15-Jan-16 6:06
professionaljkirkerx15-Jan-16 6:06 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus15-Jan-16 6:19
Wombaticus15-Jan-16 6:19 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx15-Jan-16 7:13
professionaljkirkerx15-Jan-16 7:13 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus15-Jan-16 7:38
Wombaticus15-Jan-16 7:38 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx15-Jan-16 9:00
professionaljkirkerx15-Jan-16 9:00 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus16-Jan-16 7:22
Wombaticus16-Jan-16 7:22 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx17-Jan-16 6:59
professionaljkirkerx17-Jan-16 6:59 
QuestionHow to alert checked items from checkedlistbox Pin
Daniel Elmnas11-Jan-16 2:46
Daniel Elmnas11-Jan-16 2:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.