DECLARE INTEGER GdipCreateFontFamilyFromName IN GdiPlus.dll STRING familyname, INTEGER FontCollection, INTEGER @FontFamily
DECLARE INTEGER GdipCreateFont IN GdiPlus.dll;
INTEGER fontFamily, SINGLE emSize,;
INTEGER fntstyle, INTEGER unit, INTEGER @fnt
DECLARE INTEGER GdipCreateStringFormat IN GdiPlus.dll INTEGER formatAttributes, INTEGER language, INTEGER @nFormat
DECLARE LONG GdipSetStringFormatAlign IN GDIPLUS LONG StringFormat, LONG
DECLARE LONG GdipSetStringFormatLineAlign IN GDIPLUS LONG StringFormat, LONG align
DECLARE LONG GdipSetStringFormatTrimming IN GDIPLUS LONG StringFormat, LONG trimming
DECLARE LONG GdipCreatePen1 IN GDIPLUS LONG Colr, SINGLE nWidth, LONG unit, LONG @pen
DECLARE LONG GdipSetPenMode IN GDIPLUS LONG pen, LONG penMode
DECLARE LONG GdipCreatePath IN GDIPLUS LONG brushmode, LONG @path
DECLARE LONG GdipAddPathString IN GDIPLUS LONG path, STRING str, LONG length, LONG family, LONG style, SINGLE emSize, STRING @layoutRect, LONG StringFormat
DECLARE LONG GdipGetPathWorldBounds IN GDIPLUS LONG path, STRING @bounds, LONG matrix, LONG pen
DECLARE LONG GdipDrawPath IN GDIPLUS LONG graphics, LONG pen, LONG path
DECLARE LONG GdipDrawRectangles IN GDIPLUS LONG graphics, LONG pen, STRING @rects, LONG Count
DECLARE LONG GdipCreateFromHDC IN GDIPLUS LONG hdc, LONG @graphics
DECLARE INTEGER GetDC IN win32api INTEGER hwnd
lctext="我要测量长和宽"
lcFontName="宋体"
lnsize=127
lnsize0=lnsize*96/72
lnFontFamily=0
GdipCreateFontFamilyFromName(STRCONV(lcFontName+CHR(0),5),0,@lnFontFamily)
lnFont=0
lnfontstyle=0
GdipCreateFont(lnFontFamily,lnSize0,lnFontStyle, 2 ,@lnFont)
lnFormatHandle = 0
=GdipCreateStringFormat(0x1004, 0, @lnFormatHandle )
=GdipSetStringFormatAlign(lnFormatHandle,0)
=GdipSetStringFormatLineAlign(lnFormatHandle, 0)
=GdipSetStringFormatTrimming(lnFormatHandle,0)
lnpen=0
lnColor = RGB(0,0,0)
=GdipCreatePen1(CTOBIN(CHR(255)+LEFT(BINTOC(lnColor,'4RS'),3),'4S'), 0, 2, @lnpen)
=GdipSetPenMode(lnpen,1)
lctxtrect= replicate(chr(0), 16)
lctxtrect= BINTOC(20,"f")+BINTOC(200,"f")+replicate(chr(0), 8)
lnpath=0
GdipCreatePath(0,@lnpath)
GdipAddPathString( lnpath, strconv(lctext+chr(0), 5),-1, lnFontFamily, lnFontStyle, lnSize0, @lctxtRect, lnFormatHandle)
GdipGetPathWorldBounds(lnpath,@lctxtrect,0,lnpen)
Graphics=0
hDC=GetDC(_screen.HWnd)
GdipCreateFromHDC(hdc, @Graphics)
GdipDrawPath(Graphics,lnpen,lnpath)
GdipDrawRectangles(Graphics,lnpen, @lctxtrect,1)
=INKEY(0)
?"x=",CTOBIN(SUBSTR(lctxtrect,1,4),"n"),CTOBIN(SUBSTR(lctxtrect,1,4),"n")/96*254
?"y=",CTOBIN(SUBSTR(lctxtrect,5,4),"n"),CTOBIN(SUBSTR(lctxtrect,5,4),"n")/96*254
?"w=",CTOBIN(SUBSTR(lctxtrect,9,4),"n"),CTOBIN(SUBSTR(lctxtrect,9,4),"n")/96*254
?"h=",CTOBIN(SUBSTR(lctxtrect,13,4),"n"),CTOBIN(SUBSTR(lctxtrect,13,4),"n")/96*254
[此贴子已经被作者于2023-11-7 12:26编辑过]