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

解决方案 »

  1.   

    关键是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
      

  2.   

    cbSize=5,呵呵,大概是楼主理解错误
    cbSize是DRAWTEXTPARAMS结构在内存中所占的size,楼主可能把结构size和结构成员数混淆了。在VB中该结构的每个成员为Long类型,Long在内存中占4个字节,4*5=20,用len(变量名)可以得到结构所占内存size。
      

  3.   

    谢谢两位,我已在论坛里找到了答案,在API声明中把lpDrawTextParams As RAWTEXTPARAMS 修改成lpDrawTextParams As Any,lpDrawTextParams的参数传入ByVal 0&。