首页 > 代码库 > VB API 之 第六课 字体应用三
VB API 之 第六课 字体应用三
直接上源码不做解释自己看吧
Option ExplicitPrivate Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As LongPrivate Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Declare Function GetBoundsRect Lib "gdi32" (ByVal hdc As Long, lprcBounds As RECT, ByVal flags As Long) As LongPrivate Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As LongPrivate Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As LongPrivate Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPrivate Const DT_BOTTOM = &H8Private Const DT_CALCRECT = &H400Private Const DT_CENTER = &H1Private Const DT_CHARSTREAM = 4Private Const DT_DISPFILE = 6Private Const DT_EXPANDTABS = &H40Private Const DT_EXTERNALLEADING = &H200Private Const DT_INTERNAL = &H1000Private Const DT_LEFT = &H0Private Const DT_METAFILE = 5Private Const DT_NOCLIP = &H100Private Const DT_NOPREFIX = &H800Private Const DT_RIGHT = &H2Private Const DT_SINGLELINE = &H20Private Const DT_TABSTOP = &H80Private Const DT_TOP = &H0Private Const DT_VCENTER = &H4Private Const DT_WORDBREAK = &H10Private Const DCB_RESET = &H1Private Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypeDim ARR(4) As RECTDim str1, str2, str3 As StringPrivate Sub Form_Click() Dim A As Long Dim B As Long Dim C As Long ARR(0).Top = 0 ARR(0).Left = 0 ARR(0).Right = 70 ARR(0).Bottom = 50 B = GetDC(Me.Command1.hwnd) C = GetBoundsRect(B, ARR(0), DCB_RESET) SetTextColor B, RGB(255, 0, 0) SetBkMode B, 0 str1 = "同志工作室" str2 = str1 + str1 str3 = str1 + str2 A = DrawText(B, str1 + Chr(13) + str2 + Chr(13) + str3, -1, ARR(0), DT_RIGHT)End Sub
运行效果如图所示:
VB API 之 第六课 字体应用三
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。