鼠标移到控件上时,控件会收到MouseMove事件,鼠标离开控件时,控件就收不到MouseMove事件了。所以MouseMove无法解决“离开时变回”的问题。应用SetCapture在控件收到MouseMove事件时为鼠标戴上追踪器,并判断鼠标是否离开控件,当鼠标离开控件后,用ReleaseCapture解下鼠标的追踪器。Private Declare Function SetCapture Lib "user32" Alias "SetCapture" (ByVal hwnd As Long) As Long Private Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
可以用GetPixel和SetPixel实现,但是有问题如下Private Type Color R As Long G As Long B As Long End Typedim temp as Color temp = GetPixel(Picture1.hdc, XX, YY)提示类型不匹配
dim temp as long temp = GetPixel(Picture1.hdc, XX, YY)GetPixel返回long
R = temp Mod 256 G = temp \ 256 Mod 256 B = temp \ 65536
505(五五)我用下面的代码得不到想要的效果,即在Picture2中得到一份Picture1的拷贝Private Sub Command1_Click() Dim temp As Long, R As Long, G As Long, B As Long, i As Integer, j As Integer For i = 0 To Picture1.Top For j = 0 To Picture1.Left temp = GetPixel(Picture1.hdc, Picture1.Left + i, Picture1.Top + j) ' R = temp Mod 256 And &HFF ' G = temp \ 256 Mod 256 And &HFF ' B = temp \ 65536 And &HFF SetPixel Picture2.hdc, Picture2.Left + i, Picture2.Top, temp Next j Next i End Sub
Picture1.ScaleMode = 3 Picture2.ScaleMode = 3 Private Sub Command1_Click() Dim temp As Long, R As Long, G As Long, B As Long, i As Integer, j As Integer For i = 0 To Picture1.Width-1 For j = 0 To Picture1.Height-1 temp = GetPixel(Picture1.hDC, i, j) ' R = temp Mod 256 And &HFF ' G = temp \ 256 Mod 256 And &HFF ' B = temp \ 65536 And &HFF SetPixel Picture2.hDC, i, j, temp Next j Next i End Sub
http://www.csdn.net/expert/topic/667/667096.xml?temp=.3140528
在www.dapha.net/bbs上,正在开专栏 在初学者板块!
Private Declare Function ReleaseCapture Lib "user32" Alias "ReleaseCapture" () As Long
R As Long
G As Long
B As Long
End Typedim temp as Color
temp = GetPixel(Picture1.hdc, XX, YY)提示类型不匹配
temp = GetPixel(Picture1.hdc, XX, YY)GetPixel返回long
如果GetPixel返回long的话,就得不到RGB值了
G = temp \ 256 Mod 256
B = temp \ 65536
Dim temp As Long, R As Long, G As Long, B As Long, i As Integer, j As Integer
For i = 0 To Picture1.Top
For j = 0 To Picture1.Left
temp = GetPixel(Picture1.hdc, Picture1.Left + i, Picture1.Top + j)
' R = temp Mod 256 And &HFF
' G = temp \ 256 Mod 256 And &HFF
' B = temp \ 65536 And &HFF
SetPixel Picture2.hdc, Picture2.Left + i, Picture2.Top, temp
Next j
Next i
End Sub
Picture2.ScaleMode = 3
Private Sub Command1_Click()
Dim temp As Long, R As Long, G As Long, B As Long, i As Integer, j As Integer
For i = 0 To Picture1.Width-1
For j = 0 To Picture1.Height-1
temp = GetPixel(Picture1.hDC, i, j)
' R = temp Mod 256 And &HFF
' G = temp \ 256 Mod 256 And &HFF
' B = temp \ 65536 And &HFF
SetPixel Picture2.hDC, i, j, temp
Next j
Next i
End Sub