antoineraymond
Messages postés99Date d'inscriptionmardi 6 avril 2004StatutMembreDernière intervention 4 décembre 2008
-
18 mai 2005 à 20:19
Neo.balastik
Messages postés796Date d'inscriptionjeudi 17 mai 2001StatutMembreDernière intervention 5 mai 2009
-
19 mai 2005 à 08:53
J'aimerais savoir si il y a un équivalent à "Screen.TwipsPerPixelX" dans VBA (Access)
Neo.balastik
Messages postés796Date d'inscriptionjeudi 17 mai 2001StatutMembreDernière intervention 5 mai 20097 18 mai 2005 à 22:04
Salut ;O)
Non ! Aucune équivalence.
Mais voici 2 fonctions (à mettre dans un module) qui te feront certainement plaisir :
fTwipsToPixels
fPixelsToTwips
'API DECLARATION
Public Declare Function apiGetDC Lib "user32" Alias "GetDC" (ByVal hWnd As Long) As Long
Public Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Function fTwipsToPixels(lngTwips As Long, lngDirection As Long) As Long
' Function to convert Twips to pixels for the current screen resolution
' Accepts:
' lngTwips - the number of twips to be converted
' lngDirection - direction (x or y - use either DIRECTION_VERTICAL or DIRECTION_HORIZONTAL)
' Returns:
' the number of pixels corresponding to the given twips
On Error GoTo E_Handle
Dim lngDeviceHandle As Long
Dim lngPixelsPerInch As Long
lngDeviceHandle = apiGetDC(0)
If lngDirection = DIRECTION_HORIZONTAL Then
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSX)
Else
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSY)
End If
lngDeviceHandle = apiReleaseDC(0, lngDeviceHandle)
fTwipsToPixels = lngTwips / 1440 * lngPixelsPerInch
fExit:
On Error Resume Next
Exit Function
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume fExit
End Function
Function fPixelsToTwips(lngPixels As Long, lngDirection As Long) As Long
On Error GoTo E_Handle
Dim lngDeviceHandle As Long
Dim lngPixelsPerInch As Long
lngDeviceHandle = apiGetDC(0)
If lngDirection = DIRECTION_HORIZONTAL Then
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSX)
Else
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSY)
End If
lngDeviceHandle = apiReleaseDC(0, lngDeviceHandle)
fPixelsToTwips = lngPixels * 1440 / lngPixelsPerInch
fExit:
On Error Resume Next
Exit Function
E_Handle:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error: " & Err.Number
Resume fExit
End Function
Neo.balastik
Messages postés796Date d'inscriptionjeudi 17 mai 2001StatutMembreDernière intervention 5 mai 20097 18 mai 2005 à 22:31
En fait, à relire ta question, ces fonctions n'y répondent pas directement. Elles ne donnent pas une équivalence à TwipsPerPixelX, mais j'ai supposé que tu cherchais à convertir tes Twips en pixels et vice-versa...
Guy
Vous n’avez pas trouvé la réponse que vous recherchez ?
Neo.balastik
Messages postés796Date d'inscriptionjeudi 17 mai 2001StatutMembreDernière intervention 5 mai 20097 19 mai 2005 à 08:53
Daniel > voilà ce qui fait la différence entre VB et VBA. Bcp de fonctions de ce genre sont inexistantes et donc, passer par API est la seule alternative.
ScaleX et ScaleY sont inconnus au bataillon de VBA...