getpixelr=color mod 256
g=color \ 256 mod 256
b=color \ 65536 mod 256

解决方案 »

  1.   

    下面的代码是我用一个例子,但不能使用,能不能帮我看看'This project needs:
    '- two picture boxes
    '- a button
    Private Type POINTAPI
        X As Long
        Y As Long
    End TypePrivate Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
    Private Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Long
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
    Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As LongConst ScrCopy = &HCC0020
    Const Yellow = &HFFFF&
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim Cnt1 As Byte, Cnt2 As Byte, Point As POINTAPI
        'Set the graphic mode to persistent
        Me.AutoRedraw = True
        'API uses pixels
        Me.ScaleMode = vbPixels
        Picture1.ScaleMode = vbPixels
        Picture2.ScaleMode = vbPixels
        'No borders
        Picture1.BorderStyle = 0: Picture2.BorderStyle = 0
        'Set the button's caption
        Command1.Caption = "Paint && Stretch"
        'Set the graphic mode to 'non persistent'
        Picture1.AutoRedraw = False: Picture2.AutoRedraw = False
        For Cnt1 = 0 To 100 Step 3
            For Cnt2 = 0 To 100 Step 3
    next cnt2
    next cnt1
    end sub
      

  2.   

    下面是我写的自动扫雷程序中的一段代码,用来获得颜色的,简化了一下你看看,其中有一些声明跟获取颜色无关。就看timer事件中的代码就可以了。Private Declare Function GetCursor Lib "user32" () As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    Private Const WM_GETTEXTLENGTH = &HE
    Private Const WM_GETTEXT = &HD
    Private Const WM_SETTEXT = &HC
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPrivate Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypeConst cX As Long = 41
    Const cY As Long = 69
    Const cStep As Long = 36
    Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Dim gHdc As Long
    Dim lColor As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Dim R As RECT
    Dim Lshu As Long
    Dim WZ As POINTAPI
    Dim Hw As Long
    Dim k As Long
    Dim wHwnd As Long
    Dim wHDC As Long
    Dim gX As Long
    Dim gY As Long
    Dim cColor As LongPrivate Sub Timer2_Timer()k = GetCursorPos(WZ)
    Hw = WindowFromPoint(WZ.x, WZ.y)
    wHDC = GetDC(wHwnd)
    cColor = GetPixel(wHDC, WZ.x, WZ.y)
    Me.Caption = Hex(cColor)End Sub