ntprohd Posted February 6, 2016 Share Posted February 6, 2016 I have a question how to use Image Search on any one window, while moving and hide windows can still find pictures Link to comment Share on other sites More sharing options...
Developers Jos Posted February 6, 2016 Developers Share Posted February 6, 2016 Welcome, I am not really sure what your question is but am relatively sure the question is asked before, so did you search the forums? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 6, 2016 Share Posted February 6, 2016 The ImageSearch.dll file can search a hBitmap (handle to a bitmap object) instead of just a defined area. You'll need to capture the window (Just a hint, you'll need #ReqauireAdmin if you want to capture the window even if it's hidden) and pass the $hBitmap object in the DLL call. Be sure to delete your object when you're done. Link to comment Share on other sites More sharing options...
ntprohd Posted February 10, 2016 Author Share Posted February 10, 2016 On 6/2/2016 at 9:34 PM, InunoTaishou said: The ImageSearch.dll file can search a hBitmap (handle to a bitmap object) instead of just a defined area. You'll need to capture the window (Just a hint, you'll need #ReqauireAdmin if you want to capture the window even if it's hidden) and pass the $hBitmap object in the DLL call. Be sure to delete your object when you're done. Can you tell me more how I can do that, if you have a script that is available you can share it to me, I am a novice to learn about AutoIt. thank you! Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 10, 2016 Share Posted February 10, 2016 (edited) expandcollapse popup#include-once Func CaptureWindow($iLeft = 0, $iTop = 0, $iWidth = -1, $iHeight = -1, Const $save_image = False, Const $hWnd_window) Local $rect_window = WinGetPos($hWnd_window) Local $hDC = _WinAPI_GetWindowDC($hWnd_window) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp) _WinAPI_PrintWindow($hWnd_window, $hSrcDC, True) ScreenToClient($hWnd_window, $iLeft, $iTop) If ($iWidth > 0 and $iHeight > 0) Then _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY) Else _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $rect_window[2] - 16 - $iLeft, $rect_window[3] - 38 - $iTop, $hSrcDC, $iLeft, $iTop, $MERGECOPY) EndIf _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_ReleaseDC($hWnd_window, $hDC) _WinAPI_DeleteDC($hDestDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBmp) If ($save_image) Then _ScreenCapture_SaveImage(@ScriptDir & "\CaptureWindow.jpg", $hBitmap, False) Return $hBitmap EndFunc ;==>CaptureWindow Func ScreenToClient(Const ByRef $hWnd, ByRef $iX, ByRef $iY) DllStructSetData($struct_client_screen, 1, $iX) DllStructSetData($struct_client_screen, 2, $iY) DllCall($HWND_DLL_USER32, "int", "ScreenToClient", "hwnd", $hWnd, "ptr", DllStructGetPtr($struct_client_screen)) $iX = DllStructGetData($struct_client_screen, 1) $iY = DllStructGetData($struct_client_screen, 2) EndFunc ;==>ClientToScreen Edited February 10, 2016 by InunoTaishou Link to comment Share on other sites More sharing options...
ntprohd Posted February 11, 2016 Author Share Posted February 11, 2016 12 hours ago, InunoTaishou said: expandcollapse popup#include-once Func CaptureWindow($iLeft = 0, $iTop = 0, $iWidth = -1, $iHeight = -1, Const $save_image = False, Const $hWnd_window) Local $rect_window = WinGetPos($hWnd_window) Local $hDC = _WinAPI_GetWindowDC($hWnd_window) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp) _WinAPI_PrintWindow($hWnd_window, $hSrcDC, True) ScreenToClient($hWnd_window, $iLeft, $iTop) If ($iWidth > 0 and $iHeight > 0) Then _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY) Else _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $rect_window[2] - 16 - $iLeft, $rect_window[3] - 38 - $iTop, $hSrcDC, $iLeft, $iTop, $MERGECOPY) EndIf _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_ReleaseDC($hWnd_window, $hDC) _WinAPI_DeleteDC($hDestDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBmp) If ($save_image) Then _ScreenCapture_SaveImage(@ScriptDir & "\CaptureWindow.jpg", $hBitmap, False) Return $hBitmap EndFunc ;==>CaptureWindow Func ScreenToClient(Const ByRef $hWnd, ByRef $iX, ByRef $iY) DllStructSetData($struct_client_screen, 1, $iX) DllStructSetData($struct_client_screen, 2, $iY) DllCall($HWND_DLL_USER32, "int", "ScreenToClient", "hwnd", $hWnd, "ptr", DllStructGetPtr($struct_client_screen)) $iX = DllStructGetData($struct_client_screen, 1) $iY = DllStructGetData($struct_client_screen, 2) EndFunc ;==>ClientToScreen thank you for the enthusiasm to help but I do not really understand when you look at what you write, you can send me a complete example of application, as I said I only learn about AutoIt, you have can give me your skype so I can ask you a few things, my skype is: xoancpa88 Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 11, 2016 Share Posted February 11, 2016 No, the forums are for asking for help with your scripts. That function takes x, y, width, height coordinates and a handle to the window you're trying to capture (although things are a bit out of order, the way I was using it the $hWnd_window had a default value, I removed it for this post). I won't explain everything but _WinApi_PrintWindow captures the client area (the true at the end means client, changing that false captures the whole window, I was only ever interested in the client for my purposes) and saves the object in $hSrcDC. I transformed the coordinates to work with to client coordinates (since I wanted my script to work on my window regardless of where it was and I was unable to use ControlClick for my automation, I could not use client coordinates by default) I then transferred the DC using _WinAPI_BitBlt to the $hDestDC object. I did not scale the image, instead (for my purposes) i just left the unused part of the image black (since you're doing image searching the black area does not matter but if I ever wanted to save it I wanted to see what area was actually being preserved). After that I cleaned up resources, saved image if requested, and returned an $hBitmap object (this is a handle to a bitmap, same as _ScreenCapture_Capture) To use the $hBitmap for image searching you can do this Local $hBitmap = CaptureWindow(100, 100, 400, 200, False, WinGetHandle("Notepad++")) $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearchEx", "int", $left, "int", $top, "int", $right, "int", $bottom, "str", $image_to_find, "ptr", $hBitmap) I don't know what your imagesearch function looks like, mine has been altered. But the function you call will be ImageSearchEX and you pass the $hBitmap object in the last parameter. Link to comment Share on other sites More sharing options...
ntprohd Posted February 11, 2016 Author Share Posted February 11, 2016 2 hours ago, InunoTaishou said: No, the forums are for asking for help with your scripts. That function takes x, y, width, height coordinates and a handle to the window you're trying to capture (although things are a bit out of order, the way I was using it the $hWnd_window had a default value, I removed it for this post). I won't explain everything but _WinApi_PrintWindow captures the client area (the true at the end means client, changing that false captures the whole window, I was only ever interested in the client for my purposes) and saves the object in $hSrcDC. I transformed the coordinates to work with to client coordinates (since I wanted my script to work on my window regardless of where it was and I was unable to use ControlClick for my automation, I could not use client coordinates by default) I then transferred the DC using _WinAPI_BitBlt to the $hDestDC object. I did not scale the image, instead (for my purposes) i just left the unused part of the image black (since you're doing image searching the black area does not matter but if I ever wanted to save it I wanted to see what area was actually being preserved). After that I cleaned up resources, saved image if requested, and returned an $hBitmap object (this is a handle to a bitmap, same as _ScreenCapture_Capture) To use the $hBitmap for image searching you can do this Local $hBitmap = CaptureWindow(100, 100, 400, 200, False, WinGetHandle("Notepad++")) $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearchEx", "int", $left, "int", $top, "int", $right, "int", $bottom, "str", $image_to_find, "ptr", $hBitmap) I don't know what your imagesearch function looks like, mine has been altered. But the function you call will be ImageSearchEX and you pass the $hBitmap object in the last parameter. you can send me a specific example, and I have something to ask you to help you with any code like but do not take up rat MouseClickDrag ControlClickDrag Link to comment Share on other sites More sharing options...
Burak Posted October 29, 2016 Share Posted October 29, 2016 (edited) On 10.02.2016 at 8:08 PM, InunoTaishou said: expandcollapse popup#include-once Func CaptureWindow($iLeft = 0, $iTop = 0, $iWidth = -1, $iHeight = -1, Const $save_image = False, Const $hWnd_window) Local $rect_window = WinGetPos($hWnd_window) Local $hDC = _WinAPI_GetWindowDC($hWnd_window) Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap) Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $rect_window[2] - 16, $rect_window[3] - 38) Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp) _WinAPI_PrintWindow($hWnd_window, $hSrcDC, True) ScreenToClient($hWnd_window, $iLeft, $iTop) If ($iWidth > 0 and $iHeight > 0) Then _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $iWidth, $iHeight, $hSrcDC, $iLeft, $iTop, $MERGECOPY) Else _WinAPI_BitBlt($hDestDC, $iLeft, $iTop, $rect_window[2] - 16 - $iLeft, $rect_window[3] - 38 - $iTop, $hSrcDC, $iLeft, $iTop, $MERGECOPY) EndIf _WinAPI_SelectObject($hDestDC, $hDestSv) _WinAPI_SelectObject($hSrcDC, $hSrcSv) _WinAPI_ReleaseDC($hWnd_window, $hDC) _WinAPI_DeleteDC($hDestDC) _WinAPI_DeleteDC($hSrcDC) _WinAPI_DeleteObject($hBmp) If ($save_image) Then _ScreenCapture_SaveImage(@ScriptDir & "\CaptureWindow.jpg", $hBitmap, False) Return $hBitmap EndFunc ;==>CaptureWindow Func ScreenToClient(Const ByRef $hWnd, ByRef $iX, ByRef $iY) DllStructSetData($struct_client_screen, 1, $iX) DllStructSetData($struct_client_screen, 2, $iY) DllCall($HWND_DLL_USER32, "int", "ScreenToClient", "hwnd", $hWnd, "ptr", DllStructGetPtr($struct_client_screen)) $iX = DllStructGetData($struct_client_screen, 1) $iY = DllStructGetData($struct_client_screen, 2) EndFunc ;==>ClientToScreen Unfortunately, this Code does not work as stable. Making parts of the image as black. One screen shows a complete black out in the resolution. Prepared with AutoIt example "MyBot" we are looking for the feature is available. Visual scanning in the background present. Edited October 29, 2016 by Burak Link to comment Share on other sites More sharing options...
AutoBert Posted October 30, 2016 Share Posted October 30, 2016 Some apllications prevents themself from screencapturing. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now