Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to use GetTextExtentPoint32
Message
 
 
À
16/09/2003 15:01:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00829574
Message ID:
00829580
Vues:
26
Hi Doug,

You've to pass parameter by reference if it's output parameter.
declare long GetTextExtentPoint32 in Win32API long hdc, ;
  string cString, long nSize, string @ cSize
...
lnReturn = GetTextExtentPoint32(lnHDC, lcString, lnLen, @lcSize)
? long2num(LEFT(lcSize,4))
? long2num(RIGHT(lcSize,4))
RETURN
FUNCTION Long2Num(tcLong)
DECLARE RtlMoveMemory IN WIN32API Long @Dest, ;
		String @Source, Long Length
LOCAL lnNum
lnNum = 0
= RtlMoveMemory(@lnNum, tcLong, 4)
RETURN lnNum
>Hi Everyone.
>
>I'm trying to calculate the length of a string and TXTWIDTH does things in foxels rather than pixels, which is ugly. So, I'm trying to use the GetTextExtentPoint32 API function. Here's the code I'm using:
declare long GetTextExtentPoint32 in Win32API long hdc, ;
>  string @ cString, long nSize, string @ cSize
>declare integer GetDC in Win32API integer hwnd
>declare integer ReleaseDC in Win32API integer hwnd
>
>loForm = createobject('Form')
>loForm.FontName = 'Arial'
>loForm.FontSize = 10
>lnHWnd   = loForm.HWnd
>lnHDC    = GetDC(lnHWnd)
>lcSize   = replicate(chr(0), 8)
>lcString = '$99,999,999.99'
>lnLen    = len(lcString)
>lnReturn = GetTextExtentPoint32(lnHDC, lcString, lnLen, lcSize)
>* Get the text height and width from lcSize
>ReleaseDC(lnHDC)
However, while GetTextExtentPoint32 returns a successful value (1), lcSize doesn't contain the proper size (it's still 8 CHR(0)).
>
>Any ideas about the correct way to use this function in VFP? TIA
>
>Doug
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform