Sign in to follow this  
Followers 0
Dangerous

PixelSearch in specific window

13 posts in this topic

I need some help with Pixelsearch:

usually Pixelsearch searches in an active window, is there any way script to search for pixels in minimized or background window and not in active window?

Please help, it will be more useful if you give me an example. Thanks :D

Share this post


Link to post
Share on other sites



You can not use pixelsearch on minimized or background windows, there are ways to do what you want though but you need to look in different functions(winapi)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can not use pixelsearch on minimized or background windows, there are ways to do what you want though but you need to look in different functions(winapi)

Thnx, and 1 more question, can pixelsearch search for pixels in captured screen i mean, first to use _ScreenCapture_CaptureWnd or _ScreenCapture_Capture, and then pixel search to search pixels int this captured screen?

Edited by Dangerous

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Think about it for a moment.

What does Screencapture do with the information? Put it in the clip-board? Export it to a file?

Does it display it on the screen? No?

Oh ... then pixelsearch won't work for that either.

And this thread has been languishing for three days ... and instead of experimenting, you bump. Why not post some code if you're stuck?

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Ok, first i was stuck in PixelSearch in a minimzed or Background window, but i solved that problem with this function:

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
_GDIPlus_Startup()
;$hGUI = GUICreate("Screen Capture", 400, 300, @DesktopWidth, @DesktopHeight)
;GUISetState()

$hGUI = WinGetHandle("AutoIt Help")
WinMove($hGUI, "", @DesktopWidth, @DesktopHeight)
$iWidth = _WinAPI_GetWindowWidth($hGUI)
$iHeight = _WinAPI_GetWindowHeight($hGUI)

$hParent = GUICreate("WindowViewer", 500, 400)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hParent)
GUISetState()

While 1
$hBMP = _WinCapture($hGUI, $iWidth, $iHeight)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight, 50, 50, 400, 300)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBMP)
Sleep(1000)
WEnd

Func _WinCapture($hWnd, $iWidth = -1, $iHeight = -1)
Local $iH, $iW, $hDDC, $hCDC, $hBMP
If $iWidth = -1 Then $iWidth = _WinAPI_GetWindowWidth($hWnd)
If $iHeight = -1 Then $iHeight = _WinAPI_GetWindowHeight($hWnd)
$hDDC = _WinAPI_GetDC($hWnd)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hCDC, $hBMP)
DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 0)
;_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, 0, 0, 0x00330008)

_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
;_ScreenCapture_SaveImage(@DesktopDir&"\Window.jpg", $hBMP)
;_WinAPI_DeleteObject($hBMP)
Return $hBMP
EndFunc ;==>_WinCapture

I used this function in my Script like this:

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
HotKeySet("S", "Scapture")
HotKeySet("E", "_Exit")
_GDIPlus_Startup()
$hGUI = WinGetHandle("Google - Windows Internet Explorer")
WinMove($hGUI, "", @DesktopWidth, @DesktopHeight)

$iWidth = _WinAPI_GetWindowWidth($hGUI)
$iHeight = _WinAPI_GetWindowHeight($hGUI)
$hParent = GUICreate("WindowViewer", 500, 400)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hParent)
$Pic1 = GUICtrlCreatePic("", 0, 0, 500, 396)
GUISetState()
Func Scapture()
$hBMP = _WinCapture($hGUI, $iWidth, $iHeight)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight, 50, 50, 400, 300)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBMP)
sleep(1000)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Niko\Desktop\Window.jpg", 0, 0, 500, 396)
$Search = PixelSearch(637, 382, 677, 396, 0xE9E9DF)
If Not @error Then
  ControlClick("Google - Windows Internet Explorer","", "", "left", 1, 606, 267)
EndIf
EndFunc
Func _WinCapture($hWnd, $iWidth = -1, $iHeight = -1)
Local $iH, $iW, $hDDC, $hCDC, $hBMP
If $iWidth = -1 Then $iWidth = _WinAPI_GetWindowWidth($hWnd)
If $iHeight = -1 Then $iHeight = _WinAPI_GetWindowHeight($hWnd)
$hDDC = _WinAPI_GetDC($hWnd)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hCDC, $hBMP)
DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 0)
_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, 0, 0, 0x00330008)

_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
_ScreenCapture_SaveImage(@DesktopDir&"\Window.jpg", $hBMP)
_WinAPI_DeleteObject($hBMP)
Return $hBMP
EndFunc ;==>_WinCapture
Func _Exit()
Exit
EndFunc
while 2
Sleep(100)
WEnd

So this script takes a photo to IE and saves the picture on the desktop, then this picture appears in my gui. Pixelsearch searches in gui appeared picture. But the problem is that controlclick does not work=(

ControlClick does not work in this script either:

Sleep(3000)
$Title = WinGetTitle("[Active]")
MsgBox(0, "The title is:", $Title)
Sleep(1000)
$Text = WinGetText("[Active]")
MsgBox(0, "The text is", $Text)
ControlClick($Title, $Text, "", "left", 1, 597, 265)

i activate IE window, script gets title and text very well but does not clicks

(As Click Coordinates i use ControlClick Coords and not MouseCoords so i dont think there is a problem with coords)

Share this post


Link to post
Share on other sites

Bear in mind that ControlClick() wants to click a control. not just a window. I'm not saying that it cannot work in the way you want

but it certainly might give unexpected results.

Supply the function with a control ID to get your expected results.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I used ControlClick on Local Drive D disk and it worked perfectly:

HotKeySet("C", "CC")
HotKeySet("E", "_Exit")
Func CC()
ControlClick("Local Disk (D:)", "", 1, "left", 1,8, 9)
EndFunc
Func _Exit()
Exit
EndFunc
while 1
sleep(100)
WEnd

I used Autoit Window info to get ControlID(it was 1):

Posted Image

But Autoit Window info can not find any ControlId for IE:

Posted Image

Is there any other way to get control ID?

Share this post


Link to post
Share on other sites

That would be why there is an entire UDF library called _IE.au3. Look for it in the Helpfile.

Share this post


Link to post
Share on other sites

I looked at _IE functions but did not get them very well ;) , can anyone give me an example like the script creates IE window with google.com url and clicks Search Button?

Btw i got how to create IE window with url but i can not make script click on button...

#include <IE.au3>
$IEWindow = _IECreate()
_IENavigate($IEWindow, "google.com")
;Or
;$IEWindow1 = _IECreate("google.com")

But button click... :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I have solved my problem with this:

AutoIt accepts the integer Control ID, the ClassNameNN, the control handle, or an advanced specification (i.e. "[CLASS:Button; INSTANCE:1]"). So you can take the ClassNameNN and use it directly for the control ID in most AutoIt functions. If you really must find the integer ID, get the handle first and pass it to _WinAPI_GetDlgCtrlID().

;)

and

How about just this, which works on non-AutoIt GUIs for which you know the ClassNameNN, but not the control ID. It also doesn't require the window to be visible, in focus, or have the mouse over it:

#include <GuiConstantsEx.au3>
#include <WinAPI.au3>

$sMsg = ""
$iPID = Run("Notepad.exe")
WinWait("Untitled - Notepad")
$hNotepad = WinGetHandle("Untitled - Notepad")
$sMsg &= "$hNotepad = " & $hNotepad & @CRLF
$hEdit1 = ControlGetHandle($hNotepad, "", "Edit1") ; Get handle using known ClassNameNN
$sMsg &= "$hEdit1 = " & $hEdit1 & @CRLF
$idEdit1 = _WinAPI_GetDlgCtrlID($hEdit1) ; Get control ID from handle
$sMsg &= "$idEdit1 = " & $idEdit1 & @CRLF
ControlSetText($hNotepad, "", $idEdit1, $sMsg)

:)

i got the ID of IE, like this (it was 0) and then used ControlClick and it worked perfectly :)

Thanks a lot to everyone who helped me :D

Edited by Dangerous

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