OVH Cloud OVH Cloud

Résolution de l'écran

3 réponses
Avatar
Patrick FREDIN
Bonjour,

Comment puis-je connaître la résolution de écran ?
Je voudrais utiliser ce résultat pour redimensionner des fenêtres.

Merci pour votre aide.

--
Patrick

3 réponses

Avatar
François Picalausa
Bonjour/soir,

une technique simple est d'utiliser:

Largeur = Screen.Width / Screen.TwipsPerPixelX
Hauteur = Screen.Height/ Screen.TwipsPerPixelY

Mais cette technique comporte un bug, comme décrit dans
http://support.microsoft.com/default.aspx?scid%3940

La résolution proposée par cette fiche pourrait être codée comme ceci (non
testé):
Private Declare Function GetDeviceCaps _
Lib "gdi32" _
( _
ByVal hDC As Long, _
ByVal nIndex As Long _
) _
As Long
Private Declare Function GetDC _
Lib "user32" _
( _
ByVal hwnd As Long _
) _
As Long
Private Declare Function GetWindowDC _
Lib "user32" _
( _
ByVal hwnd As Long _
) _
As Long
Private Declare Function GetDesktopWindow _
Lib "user32" _
( _
) _
As Long

Const HORZRES = 8
Const VERTRES = 10

Dim ScreenDC As Long
Dim ScreenWidth As Long
Dim ScreenHeight As Long

ScreenDC = GetWindowDC(GetDesktopWindow)

ScreenWidth = GetDeviceCaps(ScreenDC, HORZRES)
ScreenHeight = GetDeviceCaps(ScreenDC, VERTRES)

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


"Patrick FREDIN" a écrit dans le message de
news:uEUPM7%
Bonjour,

Comment puis-je connaître la résolution de écran ?
Je voudrais utiliser ce résultat pour redimensionner des fenêtres.

Merci pour votre aide.


Avatar
ng
Salut,

Tu peux obtenir la résolution en pixel très simplement grace a l'objet
Screen :

Dim ResX As Integer, ResY As Integer
ResX = Screen.Width / Screen.TwipsPerPixelX
ResY = Screen.Height / Screen.TwipsPerPixelY
MsgBox "La resolution est de " & ResX & "x" & ResY & "px"

Rq: si on ne divise pas par Screen.TwipsPerPixelX/Y on obtient la résolution
en Twips.

--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/


"Patrick FREDIN" a écrit dans le message de news:
uEUPM7#
Bonjour,

Comment puis-je connaître la résolution de écran ?
Je voudrais utiliser ce résultat pour redimensionner des fenêtres.

Merci pour votre aide.

--
Patrick




Avatar
Laurent Castagnetti
Dim lW As Long
Dim lH As Long

lW = Screen.Width / Screen.TwipsPerPixelX
lH = Screen.Height / Screen.TwipsPerPixelY

MsgBox lW & " x " & lH

Laurent.

"Patrick FREDIN" a écrit dans le message de news:
uEUPM7#
Bonjour,

Comment puis-je connaître la résolution de écran ?
Je voudrais utiliser ce résultat pour redimensionner des fenêtres.

Merci pour votre aide.

--
Patrick