回复 9楼 csyx
如果只是显示用也可以不用editbox,直接用form就无需转来转去,且可以使用Unicode。可以测试一下
程序代码:
cText = '在Visual FoxPro (VFP)中,AutoYield 属性用于控制程序在执行代码时' ;
+ '是否允许处理Windows事件(如鼠标点击、键盘输入等)。默认情况下,' ;
+ 'AutoYield是开启的(.T.),这意味着VFP会在代码执行期间定期处理事件。';
+ 0h0d0a0d0a ;
+ 'DrawTextEx是一个在Windows图形设备接口(GDI)中用于绘制复杂文本的函数。' ;
+ '它提供了多种文本格式化选项,如文字换行、字体选择、对齐方式等,' ;
+ '允许开发者精确控制文本在屏幕或打印输出上的显示效果。'+0h00
DECLARE long GetDC IN user32 long
DECLARE long ReleaseDC IN user32 long,long
DECLARE long DrawTextExW IN user32 long,string,long,string,long,string
DECLARE long SetParent IN user32 long,long
DECLARE long PostMessageA IN user32 long,long,long,long
#define MY_MESSAGE 0x0401
#define DT_WORDBREAK 0x00000010
#define DT_EXPANDTABS 0x00000040
#define DT_TABSTOP 0x00000080
#define DT_NOCLIP 0x00000100
#define DT_EXTERNALLEADING 0x00000200
#define DT_CALCRECT 0x00000400
#define DT_NOPREFIX 0x00000800
#define DT_EDITCONTROL 0x00002000
of = CREATEOBJECT("form1")
of.show(1)
CLEAR ALL
RETURN
DEFINE CLASS form1 as Form
width = 500
height = 330
minwidth = 200
minheight = 200
AutoCenter = .t.
AllowOutput = .f.
oChild = 0
leftMargin = 0
topMargin = 0
rightMargin = 0
bottomMargin = 0
cFontStyle = "N"
ADD OBJECT combo1 as combobox WITH left=10, top=10,width=200,height=24,Style=2
ADD OBJECT button1 as commandbutton WITH left=220,top=10,width=100,height=24,caption="SetFont"
PROCEDURE init
BINDEVENT(this.hWnd, MY_MESSAGE, this, "msgPaint")
this.oChild = CREATEOBJECT("formChild", 10, 50, 400, 200, 0, 8, this)
SetParent(this.oChild.hWnd, this.hWnd)
this.leftMargin = this.oChild.Left - this.Left
this.topMargin = this.oChild.Top - this.Top
this.rightMargin = this.Left+this.Width - this.oChild.left - this.oChild.width
this.bottomMargin = this.Top +this.Height - this.oChild.Top - this.oChild.Height
this.oChild.show
ENDPROC
PROCEDURE ReSize
this.oChild.width = this.Width - this.leftMargin - this.rightMargin
this.oChild.height = this.Height - this.topMargin - this.bottomMargin
PostMessageA(this.hWnd, MY_MESSAGE, 0, 0)
ENDPROC
PROCEDURE Destroy
UNBINDEVENTS(this.hWnd)
ENDPROC
PROCEDURE combo1.init
AFONT(arr)
FOR i=1 TO ALEN(arr)
this.AddItem(arr[i])
ENDFOR
this.value = "宋体"
ENDPROC
PROCEDURE combo1.InteractiveChange
thisform.oChild.fontname = ALLTRIM()
PostMessageA(thisform.hWnd, MY_MESSAGE, 0, 0)
ENDPROC
PROCEDURE button1.click
IF ALINES(arr,GETFONT(thisform.oChild.fontname,thisform.oChild.fontsize,thisform.cFontStyle),5,",") == 3
thisform.oChild.FontName = arr[1]
thisform.oChild.FontBold = IIF(INLIST(arr[3],"B","BI"), .t., .f.)
thisform.oChild.FontItalic = IIF(INLIST(arr[3],"I","BI"), .t., .f.)
= arr[1]
thisform.cFontStyle = arr[3]
PostMessageA(thisform.hWnd, MY_MESSAGE, 0, 0)
ENDIF
ENDPROC
FUNCTION msgPaint(hWnd, uMsg, wParam, lParam)
this.oChild.cls && 会触发paint事件重绘
ENDPROC
ENDDEFINE
DEFINE CLASS formChild as Form
Backcolor = 0x00FFFFFF
BorderStyle = 1
TitleBar = 0
FontName = "宋体"
AllowOutput = .f.
margin = 0
minFontSize = 8
oParent = 0
hdc = 0
fmtDrawn = BITOR(DT_EDITCONTROL,DT_EXPANDTABS,DT_EXTERNALLEADING,DT_NOCLIP,DT_NOPREFIX,DT_TABSTOP,DT_WORDBREAK)
fmtNotDrawn = BITOR(this.fmtDrawn, DT_CALCRECT)
PROCEDURE Destroy
ReleaseDC(this.hWnd, this.hdc)
ENDPROC
PROCEDURE init(nLeft, nTop, nWidth, nHeight, nMargin, nMinFontSize, oParent)
this.Left = nLeft
this.Top = nTop
this.Width = nWidth
this.Height = nHeight
this.margin = nMargin
this.minFontSize = nMinFontSize
this.oParent = oParent
this.hdc = GetDC(this.hWnd)
ENDPROC
PROCEDURE paint
this. = .f.
this.oParent.button1.Enabled = .f.
rec = BINTOC(this.margin,"4rs")+BINTOC(this.margin,"4rs")+BINTOC(this.width-this.margin,"4rs")+BINTOC(this.height-this.margin,"4rs")
nDrawnHeight = this.height - this.margin*2
this.FontSize = this.minFontSize
DO WHILE (this.FontSize < 128) AND (nDrawnHeight >= DrawTextExW(this.hdc, STRCONV(cText,5), -1, rec, this.fmtNotDrawn, NULL))
this.oParent.caption = " 稍候... FontSize: "+TRANSFORM(this.FontSize)
this.FontSize = this.FontSize + 1
ENDDO
this.FontSize = this.FontSize - 1
this.oParent.caption = " FontSize: "+TRANSFORM(this.FontSize)
DrawTextExW(this.hdc, STRCONV(cText,5), -1, rec, this.fmtDrawn, NULL)
this. = .t.
this.oParent.button1.Enabled = .t.
ENDPROC
ENDDEFINE
修复窗口最大化、最小化缩放重新绘制问题
[此贴子已经被作者于2025-11-4 16:25编辑过]








