表问怎么获取目标窗口的DC,首先用N种方法可以获得该窗口的句柄,用FindWindow最easy了
dim hwnd as long
dim hdc as long
hwnd=findwindow(vbnullstring,"窗口标题")
hdc=getDC(hwnd)
ok,hdc就是你要截取的窗口的DC句柄了,下面随意你蹂躏他咯
Private Type POINTAPI
x As Long
y As Long
End Type
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 Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetCursor Lib "user32" () As Long
Private Sub Command1_Click()
Dim hdc As Long, nWidth As Integer, nHeight As Integer, nScreenWidth As Integer, nScreenHeight As Integer
Dim CurPos As POINTAPI
Dim Cur As Long
Me.Hide
DoEvents
Picture1.AutoRedraw = True
hdc = GetDC(0)
nScreenWidth = Screen.Width
nScreenHeight = Screen.Height
Picture1.Width = nScreenWidth
Picture1.Height = nScreenHeight
nWidth = nScreenWidth / Screen.TwipsPerPixelX
nHeight = nScreenHeight / Screen.TwipsPerPixelY
BitBlt Picture1.hdc, 0, 0, nWidth, nHeight, hdc, 0, 0, vbSrcCopy
Me.Show
GetCursorPos CurPos
Cur = GetCursor
DrawIcon Picture1.hdc, CurPos.x - 10, CurPos.y - 10, Cur
ReleaseDC 0, hdc
Picture1.AutoRedraw = False
End Sub
------------
这种还能截到鼠标的呢!