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:29:23
 
 
To
21/08/2006 20:04:22
Mike Sue-Ping
Cambridge, Ontario, Canada
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:
01147582
Views:
15
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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform