1,488
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Declare Function GetDC& Lib "user32" (ByVal hwnd As Long)
Private Declare Function Ellipse& Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long)
Private Declare Function ReleaseDC& Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long)
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
Dim PicDC As Long
Form1.AutoRedraw = True
'BitBlt hdc, 0, 0, 1000, 1000, Picture1.hdc, 0, 0, vbSrcCopy
PicDC = GetDC(hwnd) '获取设备场景句柄
Ellipse PicDC, 0, 0, 100, 100 '画空心圆
ReleaseDC hwnd, PicDC '释放设备场景
End Sub
Private Sub Command1_Click()
Form1.AutoRedraw = True '有显示和缓冲两个设备
BitBlt hdc, 0, 0, 100, 100, Picture1.hdc, 0, 0, vbSrcCopy '向缓冲设备绘图
End Sub
Option Explicit
Private Declare Function GetDC& Lib "user32" (ByVal hwnd As Long)
Private Declare Function Ellipse& Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long)
Private Declare Function ReleaseDC& Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long)
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
Dim PicDC As Long
Form1.AutoRedraw = True
Debug.Print "GetDC(hwnd)="; GetDC(hwnd)
Debug.Print "hdc="; hdc
BitBlt hdc, 0, 0, 100, 100, Picture1.hdc, 0, 0, vbSrcCopy
Debug.Print "hdc="; hdc
PicDC = GetDC(hwnd) '获取设备场景句柄
Debug.Print "GetDC(hwnd)="; GetDC(hwnd)
Dim r As Long
r = Ellipse(PicDC, 100, 100, 200, 200) '画空心圆
Debug.Print "GetDC(hwnd)="; GetDC(hwnd)
ReleaseDC hwnd, PicDC '释放设备场景
End Sub
Private Sub Picture1_Click()
Dim PicDC As Long
Form1.AutoRedraw = False
Debug.Print "GetDC(hwnd)="; GetDC(hwnd)
Debug.Print "hdc="; hdc
BitBlt hdc, 0, 0, 100, 100, Picture1.hdc, 0, 0, vbSrcCopy
Debug.Print "hdc="; hdc
PicDC = GetDC(hwnd) '获取设备场景句柄
Debug.Print "GetDC(hwnd)="; GetDC(hwnd)
Dim r As Long
r = Ellipse(PicDC, 100, 100, 200, 200) '画空心圆
Debug.Print "GetDC(hwnd)="; GetDC(hwnd)
ReleaseDC hwnd, PicDC '释放设备场景
End Sub
'Example Name:Draw On Screen
'This Project needs
'- two timers, interval=100
'- a button
'in general section
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Ellipse 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 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 GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Timer2.Interval = 100
Timer2.Enabled = True
Command1.Caption = "Draw Text"
End Sub
'This will draw an Ellipse on the active window
Sub Timer1_Timer()
Dim Position As POINTAPI
'Get the cursor position
GetCursorPos Position
'Draw the Ellipse on the Screen's DC
Ellipse GetWindowDC(0), Position.x - 5, Position.y - 5, Position.x + 5, Position.y + 5
End Sub
Sub Command1_Click()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim intCount As Integer, strString As String
strString = "Cool, text on screen !"
For intCount = 0 To 30
'Draw the text on the screen
TextOut GetWindowDC(0), intCount * 20, intCount * 20, strString, Len(strString)
Next intCount
End Sub
Private Sub Timer2_Timer()
'Draw the text to the active window
TextOut GetWindowDC(GetActiveWindow), 50, 50, "This is a form", 14
End Sub