主题:自动检测相应坐标(X、Y表示)所对应的RGB值
zhousanhua
[专家分:0] 发布于 2007-09-01 14:48:00
如何能在form1_load中写入代码,让程序一运行就自动检测相应坐标(X、Y表示)所对应的RGB值。
回复列表 (共7个回复)
沙发
wwc7654321 [专家分:1590] 发布于 2007-09-01 16:09:00
可以用GetCursorPos获得鼠标位置,然后用GetPixel判断
桌面的HDC用getdc(0)获得
[color=#ffffff]
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim D
Private Sub Form_Load()
D = GetDC(0)
Show
Do
DoEvents
Dim c As POINTAPI
GetCursorPos c
BackColor = GetPixel(D, c.X, c.Y)
Caption = "&H" & Hex(BackColor)
Sleep 40
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
[/color]
板凳
superajl [专家分:190] 发布于 2007-09-01 20:56:00
用point岂不是更简单?
3 楼
天天学习 [专家分:4570] 发布于 2007-09-02 10:08:00
point只在本程序窗口范围内有效,鼠标移到窗口外就不行了.
4 楼
zhousanhua [专家分:0] 发布于 2007-09-02 16:59:00
还有一个问题要你们帮忙:我现在想获取某个范围内的RGB值等于我所设定的
RGB值,不知是否有办法?
5 楼
LUANJINLING [专家分:450] 发布于 2007-09-02 21:46:00
用1楼所给出的方法探测出鼠标处的RGB值,然后用IF句进行判断,若等于你设定的RGB便罢,若不等呢,就用一个API函数进行设定..
6 楼
wmd [专家分:200] 发布于 2007-09-05 12:41:00
关注中,正在学此方面的东东,望各位大虾能说清楚点
7 楼
chq6 [专家分:0] 发布于 2007-09-05 21:34:00
呵呵,我也想知道呀
我来回复