怎样用API实现取得屏幕上所有可见点的任意点颜色?不是仅仅在VB程序表单范围内,就如一些专门的吸色器软件一样。最好能提供源代码参考,谢谢!

解决方案 »

  1.   

    getdesktopwindow
    getdc(0)
    getpiexl
      

  2.   

    GetPixel Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long 
    说明 
    在指定的设备场景中取得一个像素的RGB值 
    返回值 
    Long,指定点的RGB颜色。如指定的点位于设备场景的剪切区之外,则返回CLR_INVALID 
    参数表 
    参数 类型及说明 
    hdc Long,一个设备场景的句柄 
    x,y Long,逻辑坐标中要检查的点 
      

  3.   

    option Explicit''Add a Timer Control to a Form, then use this code And point to anywhere on your screen to have
    'the RGB value appear In the Forms Caption.
    '
    private Type POINTAPI
        x as Long
        y as Long
    End Type
    '
    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 GetWindowDC Lib "user32" (byval hwnd as Long) as Long
    '
    private Sub Form_Load()
        Timer1.Interval = 100
    End Sub
    '
    private Sub Timer1_Timer()
        Dim tPOS as POINTAPI
        Dim sTmp as string
        Dim lColor as Long
        Dim lDC as Long
    '
        lDC = GetWindowDC(0)
        Call GetCursorPos(tPOS)
        lColor = GetPixel(lDC, tPOS.x, tPOS.y)
        Label2.BackColor = lColor
    '   
        sTmp = Right$("000000" & Hex(lColor), 6)
        Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2)
    End Sub
      

  4.   

    option Explicit
    '
    'Add a Timer Control to a Form, then use this code And point to anywhere on your screen to have
    'the RGB value appear In the Forms Caption.
    '
    private Type POINTAPI
        x as Long
        y as Long
    End Type
    '
    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 GetWindowDC Lib "user32" (byval hwnd as Long) as Long
    '
    private Sub Form_Load()
        Timer1.Interval = 100
    End Sub
    '
    private Sub Timer1_Timer()
        Dim tPOS as POINTAPI
        Dim sTmp as string
        Dim lColor as Long
        Dim lDC as Long
    '
        lDC = GetWindowDC(0)
        Call GetCursorPos(tPOS)
        lColor = GetPixel(lDC, tPOS.x, tPOS.y)
        Label2.BackColor = lColor
    '   
        sTmp = Right$("000000" & Hex(lColor), 6)
        Caption = "R:" & Right$(sTmp, 2) & " G:" & mid$(sTmp, 3, 2) & " B:" & Left$(sTmp, 2)
    End Sub