Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to convert pixels to inches/cm?
Message
De
22/08/2006 10:29:23
 
 
À
21/08/2006 20:04:22
Mike Sue-Ping
Cambridge, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01147454
Message ID:
01147582
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
>Does anyone know how I can convert the grid's column width from pixels to inches?

convert to twips -- 1440 twips equals 1 inch:
************************************************************************************************
* Function to Convert from Pixels to Twips
*
* Parameters:  
*     pnPixels       Value to convert to twips
*     pcDirection    Screen direction; 'H' for horizontal and 'V' for vertical
*
* Returns:
*     Twips value
*
FUNCTION PixelsToTwips
LPARAMETERS pnPixels, pcDirection
LOCAL lhDeviceHdl, lnPixelsPerInch
#DEFINE LOGPIXELSX  88
#DEFINE LOGPIXELSY  90
DECLARE LONG GetDeviceCaps IN "gdi32"  LONG hdc,  LONG nIndex
DECLARE LONG ReleaseDC     IN "user32" LONG hwnd, LONG hdc
DECLARE LONG GetDC         IN "user32" LONG hwnd
lhDeviceHdl = GetDC(0)
DO CASE
   CASE pcDirection = "H"        && Horizontal
      lnPixelsPerInch = GetDeviceCaps(lhDeviceHdl,LOGPIXELSX)
   CASE pcDirection = "V"        && Vertical
      lnPixelsPerInch = GetDeviceCaps(lhDeviceHdl,LOGPIXELSY)
ENDCASE
lhDeviceHdl = ReleaseDC(0,lhDeviceHdl)
RETURN pnPixels * 1440 / lnPixelsPerInch
ENDFUNC
In the above code on the RETURN statement, do not multiply by 1440 to get inches returned. You have to be sensitive to the vertical and horizontal directions as these can provide different values.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform