Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unit of measurement for the width and height..
Message
From
07/12/2006 13:41:01
 
 
To
07/12/2006 12:37:27
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 6
Miscellaneous
Thread ID:
01175467
Message ID:
01175800
Views:
6
>>Hi Hilmar, thanks for your reply. I did a google and found a site to convert pixel to inches. So, it isn't accurate too?
>
>As I said, it depends on the screen size. I forgot to say that it also depends on the screen resolution.
>
>For instance, with a 800 x 600 resolution, the same line will look bigger on a 21" screen than on a 14" screen >(50% bigger, actually).
>
>Also, on the same screen, with a higher resolution, the figure would look smaller.
>
>So, to calculate the size of a rectangle in cm., you would need to know:
># The dimensions of the rectangle in pixels
># The size of your screen, width x height. Note that 14", 17", etc. is the diagonal, and that it includes the >borders, not only the visible area.
># The screen resolution, for instance, 800 x 600.
>
>The last item you can easily get, in VFP, with sysmetric(). AFAIK, there is no way to automatically detect the >screen size.
>
>Once you know all this, the actual calculations are fairly simple.

You need to stay away from pixels -- this is dependent on the screen resolution and contrast etc. If you want an accurate size, then you need to use Twips (1/1440 inch). To convert pixels to Twips it is dependent on which direction (horizontal or vertical). The below UDF converts:
************************************************************************************************
* Based on Microsoft Knowledge Base Articles 94927, 210590
*
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL 
* IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE ARE HEREBY DISCLAIMED.
*
************************************************************************************************
* 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
To convert Twips to Pixels:
************************************************************************************************
* Based on Microsoft Knowledge Base Articles 94927, 210590
*
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL 
* IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE ARE HEREBY DISCLAIMED.
*
************************************************************************************************
* Function to Convert from Twips to Pixels
*
* Parameters:  
*     pnTwips        Value to convert to pixels
*     pcDirection    Screen direction; 'H' for horizontal and 'V' for vertical
*
* Returns:
*     Pixels value
*
FUNCTION TwipsToPixels
LPARAMETERS pnTwips, 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 pnTwips / 1440 * lnPixelsPerInch
ENDFUNC
Previous
Reply
Map
View

Click here to load this message in the networking platform