问题是这样的:
    显示器的分辨率是800×600的,如何可以得到在这个800×600的范围内的任何一个坐标的点(例如:50×50这点)的RGB颜色?

解决方案 »

  1.   

    模块中:
    Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    Public Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Type POINTAPI
            X As Long
            Y As Long
    End Type
    Public Function GetDesktopColor() As String
        Dim lpPoint As POINTAPI
        Dim hWndDesktop As Long
        Dim reColor As Long
        Dim cColor As Long
        Dim RColor As Long, GColor As Long, BColor As Long
        Dim hdc As Long
        hdc = GetDC(0)
    '获取当前鼠标位置的颜色点
        
        'hWndDesktop = GetDesktopWindow
        Call GetCursorPos(lpPoint)
        reColor = GetPixel(hdc, lpPoint.X, lpPoint.Y)
        Call ReleaseDC(0, hdc)
        RColor = reColor And &HFF
        GColor = (reColor And 65280) \ 256
        BColor = (reColor And &HFF0000) \ 65536
        GetDesktopColor = Trim(RColor) & Trim(GColor) & Trim(BColor)
    End Function
    窗口调用(反回是字符型R+G+B,自己可以改function为rgb分开的):dim a as string
    a=GetDesktopColor
      

  2.   

    获得指定点的rgb颜色, 声明同上,函数:Public Function GetDesktopColor1(Gx As Long, Gy As Long) As String
        Dim lpPoint As POINTAPI
        Dim hWndDesktop As Long
        Dim reColor As Long
        Dim cColor As Long
        Dim RColor As Long, GColor As Long, BColor As Long
        Dim hdc As Long
        hdc = GetDC(0)
    '获取指定位置点的颜色点
        
        'hWndDesktop = GetDesktopWindow
        'Call GetCursorPos(lpPoint)
        reColor = GetPixel(hdc, Gx, Gy)
        Call ReleaseDC(0, hdc)
        RColor = reColor And &HFF
        GColor = (reColor And 65280) \ 256
        BColor = (reColor And &HFF0000) \ 65536
        GetDesktopColor1 = Trim(RColor) & Trim(GColor) & Trim(BColor)
    End Function窗口调用:
    dim a as string
    a=GetDesktopColor1(50,50)