下面的代码  取屏幕任意一点的颜色,  这个代码在游戏没打开之前都好用,游戏打开以后不管取哪个窗口的颜色,返回值都为0,关掉游戏以后又能正常运行了,是GetPixel被禁用了吗  还是有别的原因呢
 'Form里----------------------------------------
   Dim pi As POINTAPI
    Dim Ret As Long
    Ret = GetCursorPos(pi)
    Dim crtHwnd As Long
    crtHwnd = WindowFromPoint(pi.x, pi.y)
    Dim rect As rect
    Ret = GetWindowRect(crtHwnd, rect)
    Me.TXT_BloodX.BackColor = GetColorFromPoint(crtHwnd, pi.x - rect.Left, pi.y - rect.Top)
'Module里----------------------------------------Public Function GetColorFromPoint(ByVal hwnd As Long, ByVal x As Long, ByVal y As Long) As Long
    Dim hDC     As Long
    hDC = GetWindowDC(hwnd)
    Dim lngColor     As Long
    lngColor = GetPixel(hDC, x, y)
    Dim lngRet As Long
    lngRet = ReleaseDC(hwnd, hDC)
    GetColorFromPoint = lngColor
 End Function

解决方案 »

  1.   

    將句柄 傳入改這樣 ,看看dc = GetWindowDC(GetDesktopWindow())
    ret = GetPixel(dc, nRect.X, nRect.Y)
      

  2.   

    MSDN中对GetPixel有一下说明:
    Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function.
      

  3.   

    楼主正解。你可以试一下其它函数:GetDIBits
      

  4.   

    to  Tiger_Zhao 
    可能游戏不支持GetPixel,它会影响到别的程序也不支持这个函数吗,有谁遇到过同样现象?to  chenhui530 
    被hook了是个什么思路呢,能具体讲讲吗?ps 游戏是《英雄》  谁愿意可以试一下
      

  5.   

    用下面的函数验证一下,是否返回FalsePrivate Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    Private Const RASTERCAPS As Long = 38
    Private Const RC_BITBLT As Long = 1Function CanGetPixel(ByVal hdc As Long) As Boolean
        CanGetPixel = (GetDeviceCaps(hdc, RASTERCAPS) And RC_BITBLT) <> 0
    End Function
      

  6.   

    先拷屏再用getpixel不知道可以不,不过如果游戏是DX的拷屏就麻烦了…………
      

  7.   

    用工具查查hook了哪几个API,修正一下入口点,不过只要一来有的游戏就退出了就麻烦了。