Jump to content

question about winapi_loadimage and pixelsearch from memory


Recommended Posts

Ok So I been studying up on this and I know about a couple udfs that have similar features but I'd rather know what I'm putting to paper than just copying and pasting others code.

So here's the deal I found this example c from another post

#include <WinAPI.au3>
#Include <WinAPIEx.au3>
#include <Array.au3>
$window = "[CLASS:Notepad]"
$handle = WinGetHandle($window)
$aWinPos = WinGetPos($handle)
$hDC = _WinAPI_GetWindowDC($handle)

$hMemDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aWinPos[2], $aWinPos[3]) _WinAPI_SelectObject($hMemDC, $hBitmap) _PrintWindow($handle, $hMemDC)
$lookup = _PixelSearchEx($hBitmap, 0x00FFFF) _ArrayDisplay($lookup) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC($handle, $hDC) _WinAPI_DeleteObject($hBitmap)


Func _PixelSearchEx($hBitmap, $iColor) Static $pProc = 0
If Not $pProc Then
If @AutoItX64 Then ; Not implemented! Return SetError(1, 0, 0) Else $pProc = __Init(Binary( _ '0x5553575631C0505050837C24280074118B6C2428837D14007407B801000000EB' & _ '0231C021C0747F8B6C24288B5D084B891C2431C03B04247F6DC7442404000000' & _ '008B6C24288B5D044B3B5C24047C528B6C24288B5D148B7C24048B34248B6C24' & _ '280FAF750401F7C1E70201FB895C24088B6C24088B5D0081E3FFFFFF003B5C24' & _ '2475188B5C24048B6C24288B7D082B3C244FC1E71009FB89D8EB14FF44240471' & _ 'A0FF0C24718CB8FFFFFFFFEB0231C083C40C5E5F5B5DC21000')) EndIf EndIf Local $tDIB, $tInt, $tPos, $aPos, $Ret, $Error = True $hBitmap = _WinAPI_CopyBitmap($hBitmap) If @error Then Return SetError(1, 0, 0) EndIf Do $tDIB = DllStructCreate($tagDIBSECTION) If (Not _WinAPI_GetObject($hBitmap, DllStructGetSize($tDIB), DllStructGetPtr($tDIB))) Or (DllStructGetData($tDIB, 'bmBitsPixel') <> 32) Or (DllStructGetData($tDIB, 'biCompression')) Then ExitLoop EndIf $Ret = _WinAPI_CallWindowProc($pProc, 0, $iColor, DllStructGetPtr($tDIB), 0) If (@error) Or ($Ret = -1) Then ExitLoop EndIf $Error = False Until 1 _WinAPI_DeleteObject($hBitmap) If $Error Then Return SetError(1, 0, 0) EndIf $tInt = DllStructCreate('int') $tPos = DllStructCreate('ushort;ushort', DllStructGetPtr($tInt)) DllStructSetData($tInt, 1, $Ret) Dim $aPos[2] For $i = 0 To 1 $aPos[$i] = DllStructGetData($tPos, $i + 1) Next Return $aPos EndFunc ;==>_PixelSearchEx Func _PrintWindow($hWnd, $hMemDC, $iFlag = 0) $aRet = DllCall("User32.dll", "int", "PrintWindow", _ "hwnd", $hWnd, _ "hwnd", $hMemDC, _ "int", $iFlag) Return $aRet[0] EndFunc ;==>_PrintWindow

I've studied this and I feel like I thoroughly understand what's happening with the exception of the search function.

However this is for a screen capture which is also useful. But I'm interested in using winapi_loadimage.

If in the above example I would use winapi_loadimage instead of winapi_getwindowdc as well as couple other charges of course, would it work in that general order or is there some other step or conversion that would need to happen.

The idea is I want to load an image into memory and then find it on the screen. I googled winapi_loadimage and really couldn't find much. I read the wiki on it and pretty much understand the parameters ect

Edit...maybe I'm completely delirious but I can't even get the above code to work hmmm

Edit got it working just gives same results no matter what I do

Edited by markyrocks
Link to comment
Share on other sites

ok so looks like im making some progress here.  not exactly with the above code.  Ill fix up that post in a min but heres where i'm at now

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <Color.au3>
sleep(10000)


_GDIPlus_Startup ()


        $MemoryContext = DllCall("gdi32.dll", "int", "CreateCompatibleDC", "int", 0)
        $MemoryContext = $MemoryContext[0]


            $HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight,false)
            DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $MemoryContext, "hwnd", $HBITMAP)

            ;Orange
            $Color = DLLCall("gdi32.dll","int","GetPixel","int",$MemoryContext,"int",88,"int",118)
            MsgBox("","color",hex($Color[0]))




 DllCall("gdi32.dll", "int", "DeleteDC", "hwnd", $MemoryContext)
    _GDIPlus_ShutDown ()

so looking at the _screencapture_capture function was kinda what i was originally trying to do but not quite either way im on the right track.  I plan to use the dllcall in a loop to basically map an object pixel by pixel.

the issue I have now is the autoit info tool says the color was 0xB7BAEC.  the msgbox displayed the color as 00ECBAB7.  now i know 00 and 0x are basically the same thing as far as the hex being reversed for the rest.... I'd kinda like some info on that.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...