在线请教:关于DRAWTEXTEX 函数

csdndatura 2003-08-26 10:40:59
API函数申明和类型定义就不写了,以下是我的调用代码,但是在矩形中就是写不出字,
Private Sub Command1_Click()
Dim DrawRect As RECT
Dim FillName As String
Dim DrawPoint As DRAWTEXTPARAMS
Dim result As Long


DrawRect.Bottom = 70
DrawRect.Left = 80
DrawRect.Right = 200
DrawRect.Top = 10

Call FrameRect(Picture1.hdc, DrawRect, lPen)

FillName = "How are you!"

DrawPoint.cbSize = 5
DrawPoint.iLeftMargin = 1
DrawPoint.iRightMargin = 1
DrawPoint.iTabLength = 0
DrawPoint.uiLengthDrawn = Len(FillName)

Call DrawTextEx(Picture1.hdc, FillName, Len(FillName), DrawRect, DT_CENTER, DrawPoint)

End Sub
...全文
121 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdndatura 2003-08-27
  • 打赏
  • 举报
回复
谢谢两位,我已在论坛里找到了答案,在API声明中把lpDrawTextParams As RAWTEXTPARAMS 修改成lpDrawTextParams As Any,lpDrawTextParams的参数传入ByVal 0&。
firechun 2003-08-26
  • 打赏
  • 举报
回复
cbSize=5,呵呵,大概是楼主理解错误
cbSize是DRAWTEXTPARAMS结构在内存中所占的size,楼主可能把结构size和结构成员数混淆了。在VB中该结构的每个成员为Long类型,Long在内存中占4个字节,4*5=20,用len(变量名)可以得到结构所占内存size。
lingll 2003-08-26
  • 打赏
  • 举报
回复
关键是DrawPoint.cbSize的值,不知为何你把它设置为5
应该是DrawPoint.cbSize = Len(DrawPoint)

另,在测试中,我还去掉了Call FrameRect(Picture1.hdc, DrawRect, lPen)这句,
能正常显示,
改后的代码如下

Private Sub Command1_Click()
Dim DrawRect As RECT
Dim FillName As String
Dim DrawPoint As DRAWTEXTPARAMS
Dim result As Long


DrawRect.Bottom = 70
DrawRect.Left = 80
DrawRect.Right = 200
DrawRect.Top = 10

'Call FrameRect(Picture1.hDC, DrawRect, lPen)

FillName = "How are you!"
DrawPoint.cbSize = Len(DrawPoint)
'DrawPoint.cbSize = 5
DrawPoint.iLeftMargin = 1
DrawPoint.iRightMargin = 1
DrawPoint.iTabLength = 0
DrawPoint.uiLengthDrawn = Len(FillName)

Call DrawTextEx(Picture1.hDC, FillName, Len(FillName), DrawRect, DT_CENTER, DrawPoint)

End Sub

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧