Jump to content

Recommended Posts

Posted

i am trying to make my scripts to run even on an inactive window. One of my script uses pixel search a lot which cannot be used on a inactive window so i searched and found this script called pixelsearch EX which is even faster and can be used on a inactive window. But i don't want the whole window to be searched, just a portion of the window so i tried to use the _WinAPI_BitBlt but i couldn't get it to work. Any help is Appreciated. Thank you.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Include <WinAPIEx.au3>
#include <Array.au3>

GUICreate("File Sender", 270, 50, 1070, 300, Default,$WS_EX_TOPMOST)
GUISetState(@SW_SHOW)

$window = "[CLASS:HospitalDataStruc]"
$handle = WinGetHandle($window)
$aWinPos = WinGetPos($handle)

HotKeySet ("{numpaddot}", "MyExit")
HotKeySet ("{numpad1}", "Start")

Func Start()
$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, 0xF04847)

_ArrayDisplay($lookup)

_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($handle, $hDC)
_WinAPI_DeleteObject($hBitmap)

EndFunc

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

Func _PrintWindow($hWnd, $hMemDC, $iFlag = 0)
    $aRet = DllCall("User32.dll", "int", "PrintWindow", _
                                         "hwnd", $hWnd, _
                                         "hwnd", $hMemDC, _
                                         "int", $iFlag)
    Return $aRet[0]
EndFunc

Func MyExit()
   Exit
EndFunc

While 1
   Sleep(10)
WEnd

 

Posted

Looks like i didn't use proper controls, I tried using the above script in paint and the values for pixel location are always offset as the script searches the whole window instead of only the white canvas. i tried using $window = "[CLASS:Afx:00007FF6CD820000:8; INSTANCE:1]" and the $winpos values ended up as error. Using MSPaintApp as Class just searches the whole paint window. How to make it search only the canvas?

Posted

i got the pixel search to work properly using proper handles. 
But i still cant use the winapi bitblt to search only the part of the window. i tried the following by setting the rectangle to a small box on the top where the desired pixel is not present but when i call the function it still finds the pixel outside of the rectangle.

Func Start()
$hDC = _WinAPI_GetWindowDC($handle)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)

$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aWinPos[2], $aWinPos[3])
_WinAPI_SelectObject($hMemDC, $hBitmap)

_PrintWindow($handle, $hMemDC)

_WinAPI_BitBlt($hMemDC, 0, 0, 10, 10, $hDC, 0, 0, $SRCCOPY)

$lookup = _PixelSearchEx($hBitmap, 0xF04847)
_ArrayDisplay($lookup)

_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($handle, $hDC)
_WinAPI_DeleteObject($hBitmap)

EndFunc

i'm stuck on this and have no idea how to proceed. 

Posted

BitBlt doesn't read from the screen, it transfers to the screen.

Quote

The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.

Do you have any idea how any of what you posted actually works?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

@BrewManNH i am a noob, i just got some of my work done with basic functions but i want to make my scripts run in the background hence i searched for a pixelsearch that worked on inactive windows and found this script- i tried it and it worked for my scripts but the problem was to get it search a specific area.I read that a person had a similar problem and he solved it using _winapi_bitblt so i asked my friend who also uses autoit and he said i was right in using that and should offset the x and y values to get the desired area but i couldnt get it to work. since i didnt want to bother him anymore i posted it here hoping some one would help me understand.

Posted

@FrancescoDiMuro Its an software for categorizing patients and labelling them, its pretty simple and color coded. i use a script to make my work easier as all it does is find for a uncategorized profile(red color) and shows No. of uncategorized ones as a message and functions like controlsend didn't work on it.

 

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
  • Recently Browsing   0 members

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