'API Function FResolutionX/Y() GetSystemMetrics(0/1)=X/Y ou les 3 suivantes
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
'Val BitParPixel (4=16 Color) (8=256 Color) (16=High Color) (24,32=True Color)
'Val FreqRefresh (0, 1=Hardware default) (sinon=User-selected)
'1 pixel = 0.75 points 72 points par pouce (sur 25,4 mm)
'hDC& = GetDC(0)
'ScreenX& = GetDeviceCaps(hDC&, 8) ' 8 = horizontal
'ScreenY& = GetDeviceCaps(hDC&, 10) ' 10 = vertical
'BitPixel& = GetDeviceCaps(hDC&, 12) ' 12 = Bit par Pixel
'PointPixel& = GetDeviceCaps(hDC&, 88) ' 88 = Point par Pixel
'FreqRefresh& = GetDeviceCaps(hDC&, 116) '116 = Freq de REFRESH
'ReleaseDC 0, hDC
'PointsPixel! = 72 / PointPixel&
'---------------------------------------------------------------------------
Sub ESSAI_TEMP() 'essai avec F5
M$ = "point par pixel = " & FPointsParPixel & vbLf & _
"résolution en cours: " & FResolutionX & "x" & FResolutionY & vbLf & _
"dim écran en points: " & FScreenWidth & "x" & FScreenHeight
MsgBox M$
End Sub
'---------------------------------------------------------------------------
Public Function FPointsParPixel() As Single
hDC& = GetDC(0): FPointsParPixel = 72 / GetDeviceCaps(hDC&, 88): ReleaseDC 0, hDC&
End Function
Public Function FResolutionX() 'X pixel
'FResolutionX = GetSystemMetrics(0) '< ceci avec la Function GetSystemMetrics
hDC& = GetDC(0): FResolutionX = GetDeviceCaps(hDC&, 8): ReleaseDC 0, hDC&
End Function
Public Function FResolutionY() 'Y pixel
'FResolutionY = GetSystemMetrics(1) '< ceci avec la Function GetSystemMetrics
hDC& = GetDC(0): FResolutionY = GetDeviceCaps(hDC&, 10): ReleaseDC 0, hDC&
End Function
Public Function FScreenWidth() 'W point
FScreenWidth = FResolutionX * FPointsParPixel
End Function
Public Function FScreenHeight() 'H point
FScreenHeight = FResolutionY * FPointsParPixel
End Function