本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 [署名 4.0 国际 (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/deed.zh) 本文作者: 苏洋 创建时间: 2009年04月18日 统计字数: 963字 阅读时间: 2分钟阅读 本文链接: https://soulteary.com/2009/04/18/vb-textout.html ----- # [vb]TextOut例子 ```vb Option Explicit Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Sub cmdDrawA_Click() Dim lngDC As Long Dim strTmp As String lngDC = GetDC(&H0) strTmp = "凉风有信 秋月无边" Call TextOut(lngDC, 100, 100, strTmp, LenB(strTmp) - 1) Call ReleaseDC(Me.hwnd, lngDC) End Sub Private Sub cmdDrawB_Click() Dim lngHwnd As Long Dim lngDC As Long strTmp = "凉风有信 秋月无边" lngHwnd = FindWindow("Notepad", "无标题 - 记事本") If lngHwnd = 0 Then MsgBox "0" lngDC = GetDC(lngHwnd) Call TextOut(lngDC, 10, 10, strTmp, LenB(strTmp) - 1) End Sub Private Sub cmdDrawC_Click() Dim lngHwnd As Long Dim lngDC As Long strTmp = "凉风有信 秋月无边" lngDC = GetDC(Me.hwnd) Call TextOut(lngDC, 10, 10, strTmp, LenB(strTmp) - 1) End Sub ```