Jump to content

_ScreenCapture_CaptureWnd not working without focus


Recommended Posts

Hello..

I am trying to use _ScreenCapture_CaptureWnd but have run into an issue.

I have the hWnd of the window that I am tyring to capture and the propper cords of the area I want however, if that window is not active

then the _ScreenCapture_CaptureWnd function seems to only capture the pixes of the top most window on the screen.

For example, I postion the window on the screen and run the code while the app is active using WinActivate($hWnd) and this works great.

Next I position the Scite window on top of the app and move it so that Scite is covering that area of the target app.

When I rem out the line WinActivate($hWnd), what I end up with is a screen capture of Scite and not the target app.

It is almost like _ScreenCapture_CaptureWnd is ignoring the hWnd I passed and only looking at the enitre desktop.

I saw a converstaion on this topic but it does not go into enogh details http://www.autoitscript.com/forum/index.php?showtopic=59591

My main question is... if I am passing a handle why does it matter if the window is ontop of all others? Shouldn't the screen cap still work reguardless of its state (top, normal, maximized, minimized, etc)?

Thank you...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <ScreenCapture.au3>
dim $left=527,$top=50,$right=555,$bottom =70 ; cords of the icon on the target app.


Opt("WinTitleMatchMode", 4)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Local $hWnd = WinGetHandle("Agent")
Local $sHWND = String($hWnd)    ; Convert to a string for later use



;Here is the problem line - if this line is not run we get the pixes of the top most window
;if the window is minimized we get a black screen cap of a different size/shape using the same cords

;WinActivate($hWnd)


ConsoleWrite ("hwnd=" & $HWND & @CRLF)
sleep (1000)

FileDelete (@DesktopDir & "\test" & ".jpg")
$checksum = PixelChecksum($left,$top,$right,$bottom,1,$hWnd,0) ; This will be used later to determine the state of the icon/area



_GetScreenCap($hWnd,$left,$top,$right,$bottom)
;MsgBox(0,"",$sHWND)
; Wait for the region to change, the region is checked every 100ms to reduce CPU load
;~ While $checksum = PixelChecksum(527, 8,540, 20)
;~   Sleep(100)
;~ WEnd

;~ MsgBox(0, "", "Something in the region has changed!")


Exit

Func _GetScreenCap($hWnd,$left,$top,$right,$bottom )
$SsTake = _ScreenCapture_CaptureWnd("", $hWnd,$left,$top,$right,$bottom,False)
_ScreenCapture_SaveImage(@DesktopDir & "\test" & ".jpg", $SsTake)
EndFunc
Link to comment
Share on other sites

  • Moderators

stmdell,

Welcome to the AutoIt forum. :(

You need to sharpen up your searching skills (although I must admit that the Search function is not the best I have ever seen). :)

Take a look at this topic - using wraithdu's code from post #6 I have just saved an image of a window which is hidden by others.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

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