Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use GetTextExtentPoint32
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00829574
Message ID:
00829600
Views:
26
This code works:
DECLARE INTEGER GetTextExtentPoint32 IN gdi32;
	INTEGER hdc, STRING lpString,;
	INTEGER cbString, STRING @lpSize

DECLARE INTEGER GetActiveWindow IN user32
DECLARE INTEGER GetWindowDC IN user32 INTEGER hWnd
DECLARE INTEGER ReleaseDC IN user32 INTEGER hwnd, INTEGER hdc

LOCAL hWindow, hDC, cString, nX, nY, cBuffer
hWindow = GetActiveWindow()
hDC = GetWindowDC(hWindow)
cString = 'How to use GetTextExtentPoint32'
STORE 0 TO nX, nY
cBuffer = Repli(Chr(0), 8)

= GetTextExtentPoint32(hDC, cString, Len(cString), @cBuffer)
? buf2dword(SUBSTR(cBuffer, 1,4))
? buf2dword(SUBSTR(cBuffer, 5,4))
	
= ReleaseDC(hWindow, hDC)

FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
	BitLShift(Asc(SUBSTR(lcBuffer, 2,1)),  8) +;
	BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
	BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
It looks like you missed that last parameter in GetTextExtentPoint32 should be passed as a reference. That's why it stays unchanged when API call returns.
Previous
Reply
Map
View

Click here to load this message in the networking platform