bonjour tout le monde,

Je cherche un moyen de changer la résolution d'ecran via mon programme. J'ai trouvé un code sur le net qui fonctionne presque parfaitement :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Imports System.Runtime.InteropServices
Module Module1
 
 
    Private Declare Auto Function EnumDisplaySettings Lib "user32.dll" ( _
        <MarshalAs(UnmanagedType.LPTStr)> ByVal lpszDeviceName As String, _
        ByVal iModeNum As Int32, _
        ByRef lpDevMode As DEVMODE _
    ) As Boolean
 
    Private Declare Auto Function ChangeDisplaySettings Lib "user32.dll" ( _
        ByRef lpDevMode As DEVMODE, _
        ByVal dwFlags As Int32 _
    ) As Int32
 
    Private Const DM_BITSPERPEL As Int32 = &H40000
    Private Const DM_PELSWIDTH As Int32 = &H80000
    Private Const DM_PELSHEIGHT As Int32 = &H100000
 
    Private Const DISP_CHANGE_SUCCESSFUL As Int32 = 0
 
    <StructLayout(LayoutKind.Sequential)> _
    Private Structure POINTL
        Public x As Int32
        Public y As Int32
    End Structure
 
    <StructLayout(LayoutKind.Explicit)> _
    Private Structure DEVMODE_union1
        ' struct {
        <FieldOffset(0)> Public dmOrientation As Int16
        <FieldOffset(2)> Public dmPaperSize As Int16
        <FieldOffset(4)> Public dmPaperLength As Int16
        <FieldOffset(6)> Public dmPaperWidth As Int16
        ' }
        <FieldOffset(0)> Public dmPosition As POINTL
    End Structure
 
    <StructLayout(LayoutKind.Explicit)> _
    Private Structure DEVMODE_union2
        <FieldOffset(0)> Public dmDisplayFlags As Int32
        <FieldOffset(0)> Public dmNup As Int32
    End Structure
 
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
    Private Structure DEVMODE
        Private Const CCDEVICENAME As Int32 = 32
        Private Const CCFORMNAME As Int32 = 32
 
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
        Public dmDeviceName As String
        Public dmSpecVersion As Int16
        Public dmDriverVersion As Int16
        Public dmSize As Int16
        Public dmDriverExtra As Int16
        Public dmFields As Int32
        Public u1 As DEVMODE_union1
        Public dmScale As Int16
        Public dmCopies As Int16
        Public dmDefaultSource As Int16
        Public dmPrintQuality As Int16
        Public dmColor As Int16
        Public dmDuplex As Int16
        Public dmYResolution As Int16
        Public dmTTOption As Int16
        Public dmCollate As Int16
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> _
        Public dmFormName As String
        Public dmUnusedPadding As Int16
        Public dmBitsPerPel As Int16
        Public dmPelsWidth As Int32
        Public dmPelsHeight As Int32
        Public u2 As DEVMODE_union2
        Public dmDisplayFrequency As Int32
        Public dmICMMethod As Int32
        Public dmICMIntent As Int32
        Public dmMediaType As Int32
        Public dmDitherType As Int32
        Public dmReserved1 As Int32
        Public dmReserved2 As Int32
        Public dmPanningWidth As Int32
        Public dmPanningHeight As Int32
    End Structure
 
    Public Function SetResolution( _
        ByVal Width As Int32, _
        ByVal Height As Int32, _
        ByVal BitsPerPixel As Int16 _
    ) As Boolean
 
        Dim dm As DEVMODE
 
        If Not EnumDisplaySettings(Nothing, 0, dm) Then
            Return False
        Else
 
            With dm
                .dmFields = _
                    DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
                .dmPelsWidth = Width
                .dmPelsHeight = Height
                .dmBitsPerPel = BitsPerPixel
 
            End With
            Return (ChangeDisplaySettings(dm, 0) = DISP_CHANGE_SUCCESSFUL)
        End If
    End Function
 
End Module
Seulement de code me permet de changer la résolution seulement sur l'écran principal, celle de mon second écran ne change pas.
J'ai bien essayé de l'adapter en faisant une boucle avec Screen.Allscreens mais je n'y arrive pas. Avez vous une piste à me donner pour m'aider svp.