VB6.0把文字輸出到屏幕需要使用GetDC、ReleaseDC和DrawText等三個API函數實現。
實現代碼:
Option?ExplicitPrivate?Declare?Function?GetDC?Lib?"user32.dll"?(ByVal?hwnd?As?Long)?As?Long
Private?Declare?Function?ReleaseDC?Lib?"user32.dll"?(ByVal?hwnd?As?Long,?ByVal?hdc?As?Long)?As?Long
Private?Declare?Function?DrawText?Lib?"user32.dll"?Alias?"DrawTextA"?(ByVal?hdc?As?Long,?ByVal?lpstr?As?String,?ByVal?nCount?As?Long,?lpRect?As?RECT,?ByVal?wFormat?As?Long)?As?Long
Private?Type?RECT
Left?As?Long
Top?As?Long
Right?As?Long
Bottom?As?Long
End?Type
Private?Sub?Command1_Click()
Dim?lngDC?As?Long
Dim?rt?As?RECT
Dim?strText?As?String
strText?=?"Hello?!"
'屏幕打印位置
With?rt
.Left?=?500
.Top?=?200
.Right?=?600
.Bottom?=?600
End?With
lngDC?=?GetDC(0)
DrawText?lngDC,?strText,?Len(strText),?rt,?0
ReleaseDC?0,?lngDC
End?Sub