Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert pixels to inches/cm?
Message
From
22/08/2006 10:42:48
Mike Sue-Ping
Cambridge, Ontario, Canada
 
 
To
22/08/2006 10:29:23
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01147454
Message ID:
01147589
Views:
18
>>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.

Thanks for the code Greg. It could be useful if Cetin's reply does not work for me. Much appreciated.

Mike
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform