GDI 是图形设备接口。
在vba中用GDI在屏幕上写字的步骤如下:
1.先用GetDC函数获取屏幕的DC(device contex)句柄。
2.然后用TextOut函数在屏幕上输出要写的字符串。
3.最后用ReleaseDC函数释放屏幕的DC句柄。
代码如下:
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal nXStart As Long, ByVal nYStart As Long, ByVal lpString As String, ByVal cchString As Long) As Long Sub QQ1722187970() Dim hdc As Long hdc = GetDC(0) Dim str As String str = "我爱你中国!!!" TextOut hdc, 100, 100, str, LenB(str) ReleaseDC 0, hdc End Sub
发表评论