OVH Cloud OVH Cloud

VBA : Taille de l'écran en pixels

3 réponses
Avatar
Gerard Ducouret
Bonjour,
je voudrais pouvoir repérer en VBA la résolution de l'écran en pixels.
Comment faire ?
De même pour les dimensions de la fenêtre active.

Merci d'avance

Gérard

3 réponses

Avatar
Michel Pierron
Bonjour Gerard;
Private Declare Function GetSystemMetrics& _
Lib "user32" (ByVal nIndex&)
Private Declare Function GetForegroundWindow& _
Lib "user32" ()
Private Declare Function GetWindowRect& _
Lib "user32" (ByVal hwnd&, lpRect As RECT)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Sub Resolution()
Dim Info As String, hwnd As Long, R As RECT
Info = "Résolution écran:" & vbTab _
& GetSystemMetrics(0) & " x " _
& GetSystemMetrics(1) & vbLf
hwnd = GetForegroundWindow
GetWindowRect hwnd, R
Info = Info & "Fenêtre active:" & vbTab _
& (R.Right - R.Left) & " x " & R.Bottom - R.Top
Info = Info & vbLf & "Fenêtre Excel:" & vbTab _
& Application.Width * 4 / 3 & " x " & Application.Height * 4 / 3
MsgBox Info
End Sub

MP

"Gerard Ducouret" a écrit dans le message
de news:u0RZnG%
Bonjour,
je voudrais pouvoir repérer en VBA la résolution de l'écran en pixels.
Comment faire ?
De même pour les dimensions de la fenêtre active.

Merci d'avance

Gérard




Avatar
Gerard Ducouret
Merci Michel, ça marche !

Mais où pourrais-je trouver de la doc sur les mots clés tels que :
GetForegroundWindow
GetSystemMetrics
GetWindowRect
...
car l'aide en ligne de VBA ne dit rien là dessus ,
Merci encore

Gérard

"Michel Pierron" a écrit dans le message de
news:uYoz5d%
Bonjour Gerard;
Private Declare Function GetSystemMetrics& _
Lib "user32" (ByVal nIndex&)
Private Declare Function GetForegroundWindow& _
Lib "user32" ()
Private Declare Function GetWindowRect& _
Lib "user32" (ByVal hwnd&, lpRect As RECT)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Sub Resolution()
Dim Info As String, hwnd As Long, R As RECT
Info = "Résolution écran:" & vbTab _
& GetSystemMetrics(0) & " x " _
& GetSystemMetrics(1) & vbLf
hwnd = GetForegroundWindow
GetWindowRect hwnd, R
Info = Info & "Fenêtre active:" & vbTab _
& (R.Right - R.Left) & " x " & R.Bottom - R.Top
Info = Info & vbLf & "Fenêtre Excel:" & vbTab _
& Application.Width * 4 / 3 & " x " & Application.Height * 4 / 3
MsgBox Info
End Sub

MP

"Gerard Ducouret" a écrit dans le
message

de news:u0RZnG%
Bonjour,
je voudrais pouvoir repérer en VBA la résolution de l'écran en pixels.
Comment faire ?
De même pour les dimensions de la fenêtre active.

Merci d'avance

Gérard







Avatar
Michel Pierron
Re Gerard;
la bible se trouve là :
'URL: http://www.allapi.net/
'

télécharger le Api-guide.exe
MP

"Gerard Ducouret" a écrit dans le message
de news:uuEIB2$
Merci Michel, ça marche !

Mais où pourrais-je trouver de la doc sur les mots clés tels que :
GetForegroundWindow
GetSystemMetrics
GetWindowRect
...
car l'aide en ligne de VBA ne dit rien là dessus ,
Merci encore

Gérard

"Michel Pierron" a écrit dans le message de
news:uYoz5d%
Bonjour Gerard;
Private Declare Function GetSystemMetrics& _
Lib "user32" (ByVal nIndex&)
Private Declare Function GetForegroundWindow& _
Lib "user32" ()
Private Declare Function GetWindowRect& _
Lib "user32" (ByVal hwnd&, lpRect As RECT)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Sub Resolution()
Dim Info As String, hwnd As Long, R As RECT
Info = "Résolution écran:" & vbTab _
& GetSystemMetrics(0) & " x " _
& GetSystemMetrics(1) & vbLf
hwnd = GetForegroundWindow
GetWindowRect hwnd, R
Info = Info & "Fenêtre active:" & vbTab _
& (R.Right - R.Left) & " x " & R.Bottom - R.Top
Info = Info & vbLf & "Fenêtre Excel:" & vbTab _
& Application.Width * 4 / 3 & " x " & Application.Height * 4 / 3
MsgBox Info
End Sub

MP

"Gerard Ducouret" a écrit dans le
message

de news:u0RZnG%
Bonjour,
je voudrais pouvoir repérer en VBA la résolution de l'écran en pixels.
Comment faire ?
De même pour les dimensions de la fenêtre active.

Merci d'avance

Gérard