質問

My goal is to make a GUI looping print screens from the desktop and all processes being used. The only problem I'm having right now is: Some processes don't have any viewable interface (OS processes for example).

I am using these commands to capture the screen:

_ScreenCapture_Capture(@MyDocumentsDir & "desktop.jpg")
_ScreenCapture_CaptureWnd(@MyDocumentsDir & "process.jpg", _
                          $processes[$window], -1, -1, -1, -1, True)

But as I said, there are programs without an Interface which would return a fail in the _ScreenCapture command. Is there a way to know if a process has a user-interface?

役に立ちましたか?

解決

There are some improvements:

  • You have to put a "\" before your filenames
  • You don't need to specify the default parameters
  • When you use ProcessList(), the second parameter to receive the PID should always be 0, not $window as well. But you cannot use a PID to call the screen capture function!
  • Instead of using ProcessList() you should just use WinList() and filter all the windows for those visible
  • The third and fourth default parameters for _ScreenCapture_CaptureWnd(...) function is 0, not -1
  • You should probably make sure, the window to capture is active, befor you capture it... else it might be hidden behind another window and only a part of the topmost windows would be captured

So here's a working solution to your problem:

#include <Array.au3>
#include <ScreenCapture.au3>

Local $var = WinList()

$visibleProcesses = "-1"
For $i = 1 To $var[0][0]
    $handle = $var[$i][1]
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" And BitAND(WinGetState($handle), 2) Then
        If _ArraySearch(StringSplit($visibleProcesses, "|", 2), $handle) == -1 _
        Then
            $visibleProcesses &= "|" & $handle 
        EndIf
    EndIf
Next
$visibleProcesses = StringSplit($visibleProcesses, "|", 2)
_ArrayDelete($visibleProcesses, 0)

_ScreenCapture_Capture(@MyDocumentsDir & "\desktop.jpg")
For $handle In $visibleProcesses
    _ScreenCapture_CaptureWnd(@MyDocumentsDir & "\process" & $handle & ".jpg", _
                              HWnd($handle))
Next

This basically uses WinList() to receive all programs with a GUI. Then it filters them for having a title and being visible (WinGetState(...) must return 2). The process handle is only added to the delimiter separated string if its not yet included and finally the list is converted to an array and its first dummy entry is removed. Without the dummy entry you'd have to remove the first leading delimiter.

In the end, your functions are being called properly, the handle was converted to a string in the array, so it has to be converted to a handle again.

If you want to include a WinActivate(Hwnd($handle)) before the capture to make the window the active one before it is captured, you might consider to add a _ArrayReverse($visibleProcesses) before the final loop as WinList() should return a list being sorted from top the topmost to the bottommost. And iterating through this list backwards will preserve the order of the windows on top of each other after setting every single one as the active window - and so becoming the topmost - beginning from the bottommost.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top