Jump to content

PixelSearch on inactive window


Recommended Posts

Ok what I want to do is find a color in the inactive window based upon the handle of that window.

CODE
Opt("PixelCoordMode", 0)

$t = WinGetHandle("Untitled - Paint")

$coord = PixelSearch( 0, 0, 20, 300, 0x000000, $t )

If Not @error Then

MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])

MsgBox(0, "", @error)

Else

MsgBox(0, "", @error)

EndIf

The @errors are very random it seems. If the window is not active and the pane is filled with black it returns 0. Then even if I change the color I still get 0. I realized then it wasnt searching the range of the window it was just doing the screen. Very confused, sad to say been working on this for a few days now. Thanks for any replies

Link to comment
Share on other sites

With a inactive window you cannot use PixelSearch and also with a window that is behind another window. You end up getting a answer but depending on which part your focusing on.

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

As I was reviewing your question I also found out that you aren't declaring a Hwnd as $h is setting the shade-variation of pure white

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

Here is more of what you want

Opt("PixelCoordMode", 0)

$t = WinGetHandle("Untitled - Paint")
If Not @error Then
    $coord = PixelSearch(0, 0, 20, 300, 0xFFFFFF, 0, 1, $t)
    If Not @error Then
        MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
        MsgBox(0, "", @error)
    Else
        MsgBox(0, "", @error)
    EndIf
EndIfoÝ÷ غm¶®º+ý7êجmq« ÖÞq«¬zØ^*.®×¥)àÛh~e£az{¥Ëkx0'!ʱêïzØ^±ÊÞzqÞ­è¬jz-êðk*v§+m¡«­¢+Ù=ÁÐ ÅÕ½ÐíA¥á±
½½É5½ÅÕ½Ðì°À¤((ÀÌØíÐô]¥¹Ñ!¹± ÅÕ½ÐíU¹Ñ¥Ñ±´A¥¹ÐÅÕ½Ðì¤)%ÉɽÈQ¡¸á¥Ð(ÀÌØí½½ÉôA¥á±MÉ  À°À°ÈÀ°ÌÀÀ°Áá°À°Ä°ÀÌØíФ)%9½ÐÉɽÈQ¡¸(%5Í   ½à À°ÅÕ½Ðí`¹dÉèÅÕ½Ðì°ÀÌØí½½ÉlÁtµÀìÅÕ½Ðì°ÅÕ½ÐìµÀìÀÌØí½½ÉlÅt¤(%5Í    ½à À°ÅÕ½ÐìÅÕ½Ðì°ÉɽȤ)±Í(%5Í ½à À°ÅÕ½ÐìÅÕ½Ðì°ÉɽȤ)¹%

whichever you like better

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

I have tested it throughly and this is what I got.

With the Untitled - Paint windows

showing - passed - passed

not showing - passed - failed

Without a window

not showing - failed

Due note I also changed the 0x000000 just to see if it would affect anything. I didn't want to get X and Y are: 0,0 each time. Also remember your dealing with just the titles at 0,0,20,300.

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Link to comment
Share on other sites

Well, you don't have to see the window whether it's active or not.

You can initially move the window off the screen and do the search there ;]

#include <Array.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
Opt('PixelCoordMode', 0)

Dim $hWnd = WinGetHandle('[CLASS:SciTEWindow]')
Dim $Pos = WinGetPos($hWnd)
WinMove($hWnd, '', -65536, -65536)
Sleep(1000)

_GDIPlus_Startup()

Dim $hDC = _WinAPI_GetWindowDC($hWnd)
Dim $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
Dim $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $Pos[2], $Pos[3])
_WinAPI_SelectObject($hMemDC, $hBitmap)

DllCall('user32.dll', 'int', 'PrintWindow', 'hwnd', $hWnd, 'ptr', $hMemDC, 'uint', 0)

Dim $hGUI = GUICreate('Test', $Pos[2], $Pos[3])
Dim $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Dim $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
GUISetState()
_GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
Do
    Sleep(20)
Until GUIGetMsg() = -3

_WinAPI_DeleteObject($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($hWnd, $hDC)
GUIDelete($hGUI)
_GDIPlus_Shutdown()
WinMove($hWnd, '', $Pos[0], $Pos[1])
Exit
Link to comment
Share on other sites

Yes, that I do know. Except in your function if a person exits out of the script before it ends then have the windows stuck offscreen. Anyways you should have it check to see if the windows is minimized before you send it else you would see it going offscreen then back if you waited. Here is a better way to do what you wanted.

Dim $aiPos

Opt("PixelCoordMode", 0)

$hHandle = WinGetHandle("[CLASS:SciTEWindow]")
If @error Then Exit
If BitAND(WinGetState("[CLASS:SciTEWindow]", ""), 16) Then
    $aiPos = WinGetPos($hHandle)
    WinMove($hHandle, "", 32000, 32000)
EndIf

$aiCoord = PixelSearch(0, 0, 20, 300, 0xFFFFFF, 0, 1, $hHandle)
If Not @error Then
    MsgBox(0, "X and Y are:", $aiCoord[0] & "," & $aiCoord[1])
    MsgBox(0, "", @error)
Else
    MsgBox(0, "", @error)
EndIf

If IsDeclared($aiPos) Then WinMove($hHandle, "", $aiPos[0], $aiPos[1])

0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

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...