Sign in to follow this  
Followers 0
BitByteBit

Homebrew PixelGetColor for inactive windows.

1 post in this topic

After calling the following function the window I'm reading is all messed up.

Parts of it are redrawn but not others, _WinAPI_RedrawWindow doesn't seem to help and I wondered if I'm doing something wrong?

Thanks.

$hWnd = WinGetHandle('Spot')
ConsoleWrite($hWnd & @CRLF)
ConsoleWrite(_PixelGet2($hWnd, 1, 20) & @CRLF)
Func _PixelGet2($hWnd, $iX, $iY)
    $iState = WinGetState($hWnd)
    If Not BitAND($iState, 2) Or BitAND($iState, 16) Then Return 0
    Local $hDDC, $hCDC, $hBMP, $ret
    $iPos = WinGetPos($hWnd)

    $hDDC = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd)
    $hCDC = DllCall("gdi32.dll", "handle", "CreateCompatibleDC", "handle", $hDDC[0])
    $hBMP = DllCall("gdi32.dll", "handle", "CreateCompatibleBitmap", "handle", $hDDC[0], "int", $iPos[2], "int", $iPos[3])
    DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hCDC[0], "handle", $hBMP[0])
    DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC[0], "int", 0)

    $ret = DllCall("gdi32", "int", "GetPixel", "ptr", $hCDC[0], "int", $iX, "int", $iY)

    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "handle", $hDDC[0])
    DllCall("gdi32.dll", "bool", "DeleteDC", "handle", $hCDC[0])
    DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hBMP[0])
    Return '0x' & StringTrimLeft(Hex($ret[0]), 2)
EndFunc   ;==>_PixelSearch2

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0