Option ExplicitPrivate Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject 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 lstrlen Lib "KERNEL32" Alias "lstrlenA" (ByVal lpString As String) As Long Private Sub Command1_Click() Dim TempBrush As Long Dim tOB As Long TempBrush = CreateSolidBrush(RGB(0, 0, 0)) tOB = SelectObject(Me.hdc, TempBrush) TextOut Me.hdc, 4, 20, "我爱北京天安门", lstrlen("我爱北京天安门") SelectObject Me.hdc, tOB Rectangle Me.hdc, 15, 15, 50, 50 DeleteObject TempBrush End Sub
Option Explicit 'Api声明Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject 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 lstrlen Lib "KERNEL32" Alias "lstrlenA" (ByVal lpString As String) As Long'Api声明结束 Private Sub Command1_Click() Dim TempBrush As Long '临时画刷.. Dim tOB As Long '透明画刷
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject 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 lstrlen Lib "KERNEL32" Alias "lstrlenA" (ByVal lpString As String) As Long
Private Sub Command1_Click()
Dim TempBrush As Long
Dim tOB As Long
TempBrush = CreateSolidBrush(RGB(0, 0, 0))
tOB = SelectObject(Me.hdc, TempBrush)
TextOut Me.hdc, 4, 20, "我爱北京天安门", lstrlen("我爱北京天安门")
SelectObject Me.hdc, tOB
Rectangle Me.hdc, 15, 15, 50, 50
DeleteObject TempBrush
End Sub
'Api声明Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject 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 lstrlen Lib "KERNEL32" Alias "lstrlenA" (ByVal lpString As String) As Long'Api声明结束
Private Sub Command1_Click()
Dim TempBrush As Long '临时画刷..
Dim tOB As Long '透明画刷
TempBrush = CreateSolidBrush(RGB(0, 0, 0)) '创建一个实心的黑画刷
tOB = SelectObject(Me.hdc, TempBrush) '选择临时画刷做当前画刷 tOB 就变成 Me.hdc 的原画刷了
TextOut Me.hdc, 4, 20, "我爱北京天安门", lstrlen("我爱北京天安门")
SelectObject Me.hdc, tOB
Rectangle Me.hdc, 15, 15, 50, 50
DeleteObject TempBrush
DeleteObject tOB
End Sub
Dim hOldBr as LonghOldBr=SelectObject(hDC, GetStockObject(NULL_BRUSH))
Rectangle ……
Call SelectObject(hDC, hOldBr)
它们的功能一样都是不画任何东西的画刷