Sign in to follow this  
Followers 0

_CaptureBehindWindow

19 posts in this topic

Posted (edited)

hi

this my first script in this forum , it is a tiny script for capture screen

behind a specific window

edit : okay important improvements on the script , now it works like magic

no flushing , no delaying

it works fine for me but not for some users (maybe all) for unknown reasons

so it seems that it will not work for any one but i will leave it here

if any one wanted it

Demo & a Little Function

#include <WinAPI.au3>
#include <Constants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

_CaptureBehindWindow("","", @ScriptDir & "\Behind Current window.bmp")
ShellExecute(@ScriptDir & "\Behind Current window.bmp")

Func _CaptureBehindWindow($sTitle, $sText, $sFile)
    Local Const $WS_EX_COMPOSITED = 0x2000000
    $hWnd = WinGetHandle($sTitle, $sText)

    $Old_EX_STYLE = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitOR($WS_EX_LAYERED, $WS_EX_COMPOSITED))

    _ScreenCapture_Capture($sFile, 0, 0, -1, -1, False)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, $Old_EX_STYLE)
EndFunc   ;==>_CaptureBehindWindow
Edited by komalo

Share this post


Link to post
Share on other sites



Posted

any opinion ?

Share this post


Link to post
Share on other sites

Posted (edited)

any opinion ?

Might as well put the includes in there.

#Include <WinAPI.au3>

#Include <ScreenCapture.au3>

#Include <Constants.au3>

edit: Doesn't seem to work quite right. Maybe add a delay till picture is done?

Edited by spudw2k

Share this post


Link to post
Share on other sites

Posted

Very buggy =( and you also didnt specify what includes were requires :P

Heres the screenshot that was taken on my system. (only half draws a window)

Posted Image

Share this post


Link to post
Share on other sites

Posted

Good try, but it doesn't work that way.

Share this post


Link to post
Share on other sites

Posted

Might as well put the includes in there.

#Include <WinAPI.au3>

#Include <ScreenCapture.au3>

#Include <Constants.au3>

edit: Doesn't seem to work quite right. Maybe add a delay till picture is done?

Very buggy =( and you also didnt specify what includes were requires :P

Heres the screenshot that was taken on my system. (only half draws a window)

Posted Image

Good try, but it doesn't work that way.

sorry guys , that's my first script shared here so i didn't know what to do .

i put all the includes now .

about that delay , the script works fine with me but maybe there's timing between

apply the style and taking the screen shot so i modified the script and put a sleep

between SetTrans and capture.

you can try it now .

Share this post


Link to post
Share on other sites

Posted (edited)

okay important improvements on the script , now it works like magic

no flushing , no delaying , see first post for the update

Edited by komalo

Share this post


Link to post
Share on other sites

Posted

Still doesn't repaint the picture the area behind the window when it is needed. You should look into GDI a bit more. :P

Share this post


Link to post
Share on other sites

Posted

first it works for me fine now so i don't really get it , why it is not captured for you :P

second i am not using GDI Here :(

Share this post


Link to post
Share on other sites

Posted (edited)

What OS are you running? Vista has made a lot of changes in the way this works. Win XP SP3 here.

Edit: It does work for me in most non-user drawn forms. But it still makes huge flashes.

Edited by Manadar

Share this post


Link to post
Share on other sites

Posted

I run the script and absolutely noting happens : /

Share this post


Link to post
Share on other sites

Posted

I run the script and absolutely noting happens : /

That's because it's an UDF style script. It's an #include basically.

Try this:

#include <WinAPI.au3>
#include <Constants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

;#VARIBLES#===============================================================================
Global Const $WS_EX_COMPOSITED = 0x2000000

;#FUNCTION#===============================================================================
;
; Name...........: _CaptureBehindWindow
; Description ...: Capture the screen behind a specific window
; Syntax.........: _CaptureBehindWindow($sTitle , $sText , $sFile)
; Parameters ....: $sTitle = The title of the window . See Title special definition.
;                  $sText = text The text of the window .
;                  $sFile = Full path and extension of the image file to save the capture image in
; Return values .: None
; Author ........: komalo
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _CaptureBehindWindow("","", @ScriptDir & "\Behind Current window.bmp")
;
;==========================================================================================

Func _CaptureBehindWindow($sTitle, $sText, $sFile)
    $hWnd = WinGetHandle($sTitle, $sText)

    $Old_EX_STYLE = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitOR($WS_EX_LAYERED, $WS_EX_COMPOSITED))

    _ScreenCapture_Capture($sFile, 0, 0, -1, -1, False)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, $Old_EX_STYLE)
EndFunc   ;==>_CaptureBehindWindow


Opt("WinTitleMatchMode", 2)

;; THE ACTUAL SCRIPT
_CaptureBehindWindow(" - SciTE", "", "C:\test.jpg")
ShellExecute("C:\test.jpg")

Share this post


Link to post
Share on other sites

Posted

I run the script and absolutely noting happens : /

That's because it's an UDF style script. It's an #include basically.

Try this:

#include <WinAPI.au3>
#include <Constants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

;#VARIBLES#===============================================================================
Global Const $WS_EX_COMPOSITED = 0x2000000

;#FUNCTION#===============================================================================
;
; Name...........: _CaptureBehindWindow
; Description ...: Capture the screen behind a specific window
; Syntax.........: _CaptureBehindWindow($sTitle , $sText , $sFile)
; Parameters ....: $sTitle = The title of the window . See Title special definition.
;                  $sText = text The text of the window .
;                  $sFile = Full path and extension of the image file to save the capture image in
; Return values .: None
; Author ........: komalo
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _CaptureBehindWindow("","", @ScriptDir & "\Behind Current window.bmp")
;
;==========================================================================================

Func _CaptureBehindWindow($sTitle, $sText, $sFile)
    $hWnd = WinGetHandle($sTitle, $sText)

    $Old_EX_STYLE = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitOR($WS_EX_LAYERED, $WS_EX_COMPOSITED))

    _ScreenCapture_Capture($sFile, 0, 0, -1, -1, False)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, $Old_EX_STYLE)
EndFunc   ;==>_CaptureBehindWindow


Opt("WinTitleMatchMode", 2)

;; THE ACTUAL SCRIPT
_CaptureBehindWindow(" - SciTE", "", "C:\test.jpg")
ShellExecute("C:\test.jpg")

Share this post


Link to post
Share on other sites

Posted (edited)

That's because it's an UDF style script. It's an #include basically.

Try this:

#include <WinAPI.au3>
#include <Constants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

;#VARIBLES#===============================================================================
Global Const $WS_EX_COMPOSITED = 0x2000000

;#FUNCTION#===============================================================================
;
; Name...........: _CaptureBehindWindow
; Description ...: Capture the screen behind a specific window
; Syntax.........: _CaptureBehindWindow($sTitle , $sText , $sFile)
; Parameters ....: $sTitle = The title of the window . See Title special definition.
;                  $sText = text The text of the window .
;                  $sFile = Full path and extension of the image file to save the capture image in
; Return values .: None
; Author ........: komalo
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _CaptureBehindWindow("","", @ScriptDir & "\Behind Current window.bmp")
;
;==========================================================================================

Func _CaptureBehindWindow($sTitle, $sText, $sFile)
    $hWnd = WinGetHandle($sTitle, $sText)

    $Old_EX_STYLE = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitOR($WS_EX_LAYERED, $WS_EX_COMPOSITED))

    _ScreenCapture_Capture($sFile, 0, 0, -1, -1, False)
    _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, $Old_EX_STYLE)
EndFunc   ;==>_CaptureBehindWindow


Opt("WinTitleMatchMode", 2)

;; THE ACTUAL SCRIPT
_CaptureBehindWindow(" - SciTE", "", "C:\test.jpg")
ShellExecute("C:\test.jpg")
@Manadar : thank you for replaying to others

now i knew why it wasn't working for you

if you try this

_CaptureBehindWindow("Untitled -", "", "C:\test.jpg")
ShellExecute("C:\test.jpg")

with notepad you will not get the flushing

I am XP SP2 User

Edited by komalo

Share this post


Link to post
Share on other sites

Posted

I'm not a complete novice at AutoIt you know :(

Ofc i wrote out the function yet still nothing happened.

:P

Share this post


Link to post
Share on other sites

Posted

Yeah, so I try this:

;; THE ACTUAL SCRIPT
Opt("WinTitleMatchMode", 2)

WinActivate("Untitled - ")
_CaptureBehindWindow("Untitled -", "", "C:\test.jpg")
ShellExecute("C:\test.jpg")

I don't see what the difference is between getting a winhandle using the first part of the string, or the last part of the string. A window handle is a window handle.

Result: You can clearly see where the window was before.

Posted Image

Share this post


Link to post
Share on other sites

Posted

i am getting board , it works for me that what i want

so i will leave this script here

just for clearing the idea of the script :

bitblt function doesn't get Bits by layered windows

so i get the exstyle of the window and sets the exstyle

to $WS_EX_LAYERED make a screencapture which is

made by bitblt and sets the exstyle to the orginal

Share this post


Link to post
Share on other sites

Posted

just for clearing the idea of the script :

bitblt function doesn't get Bits by layered windows

so i get the exstyle of the window and sets the exstyle

to $WS_EX_LAYERED make a screencapture which is

made by bitblt and sets the exstyle to the orginal

You should be able to do this quite effectively using BitBlt and GetDC using a specific hWnd and not null.

Share this post


Link to post
Share on other sites

Posted (edited)

ScreenCapture_Capture Uses Desktop's handle ( _WinAPI_GetDesktopWindow )

and i am able to finish it , what i don't get it

is why it is not working right for you

Edited by komalo

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

  • Recently Browsing   0 members

    No registered users viewing this page.