Jump to content

_ScreenCapture_CaptureWndV2


numdig
 Share

Recommended Posts

An alternative to the standard '_ScreenCapture_CaptureWnd' in order to capture the layered windows as well.

; #FUNCTION# ====================================================================================================================
; Name...........: _ScreenCapture_CaptureWndV2
; Description ...: Captures a screen shot of a specified window. This function is an alternative to '_ScreenCapture_CaptureWnd'.
;                  It is able to take screenshots of layered windows (drawn by the graphic card). See 'remarks' below.
; Syntax.........: _ScreenCapture_CaptureWndV2($sFileName, $hWnd[, $iLeft = 0[, $iTop = 0[, $iRight = -1[, $iBottom = -1[, $fCursor = True]]]]])
; Parameters ....: $sFileName   - Full path and extension of the image file
;                  $hWnd        - Handle to the window to be captured
;                  $iLeft       - X coordinate of the upper left corner of the client rectangle
;                  $iTop        - Y coordinate of the upper left corner of the client rectangle
;                  $iRight      - X coordinate of the lower right corner of the rectangle
;                  $iBottom     - Y coordinate of the lower right corner of the rectangle
;                  $fCursor     - If True the cursor will be captured with the image
; Return values .: See remarks
; Remarks .......: 1/ If FileName is not blank this function will capture the screen and save it to file. If FileName is blank, this
;                  function will capture the screen and return a HBITMAP handle to the bitmap image.  In this case, after you are
;                  finished with the bitmap you must call _WinAPI_DeleteObject to delete the bitmap handle.  All coordinates are  in
;                  client coordinate mode.
;
;                  2.1/ Layered windows do not appear on screenshots taken by '_ScreenCapture_Capture' because it uses the desktop's
;                  handle whereas the layered windows are drawn directly by the graphic card. 2.2/ '_ScreenCapture_CaptureWnd'
;                  is a wrapper of '_ScreenCapture_Capture' and, therefore, has the same limitations. 2.3/ Instead,
;                  '_ScreenCapture_CaptureWndV2', THIS FUNCTION, is using the handle of the targetted window to perfom its task
;                  (in a similar way than '_ScreenCapture_Capture'uses the Desktop's handle).
;
; Author ........: Patryk Szczepankiewicz (pszczepa at gmail dot com)
; History .......: JAN 21, 2009 - Created
;                  OCT 18, 2010 - First release on the AutoIT forum
;                  OCT 28, 2010 - Cleaned the border code and fixed the capture of the cursor.
;                  APR 06, 2011 - Updated for AutoIT 3.3.6.1
; Related .......: _WinAPI_DeleteObject
; Link ..........; http://www.autoitscript.com/forum/index.php?showtopic=65008
; Example .......; No
; Credits .......: Based on Paul Campbell's '_ScreenCapture_Capture' function and inspired by Jennico's '_WinGetBorderSize'.
; ===============================================================================================================================
Func _ScreenCapture_CaptureWndV2($sFileName, $hWnd, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)

    Local $tRect
    Local $iWndX, $iWndY, $iWndW, $iWndH

    Local $tClient
    Local $iBorderV, $iBorderT
    Local $iPicHeight, $iPicWidth
    Local $iPicCursorX, $iPicCursorY


    Local $hDDC, $hCDC, $hBMP, $aCursor, $aIcon, $hIcon

    ; Get the absolute coordinates of the window
    $tRect = _WinAPI_GetWindowRect($hWnd)

    ; Get useful variables
    $iWndX = DllStructGetData($tRect, "Left")
    $iWndY = DllStructGetData($tRect, "Top")
    $iWndW = DllStructGetData($tRect, "Right")
    $iWndH = DllStructGetData($tRect, "Bottom")

    ; Assign automatic values: the right and bottom are computed as
    ; the width and height of the absolute coordinates of the window.
    If $iRight = -1 Then $iRight = $iWndW - $iWndX
    If $iBottom = -1 Then $iBottom = $iWndH - $iWndY

    ; Check user values: check that caller is not putting the top-left
    ; corner out of the window.
    If $iLeft > $iWndW Then $iLeft = $iWndX
    If $iTop > $iWndH Then $iTop = $iWndY

    ; Check user values: check that caller is not asking for a
    ; screenshot bigger than the window itelf.
    If $iRight > $iWndW Then $iRight = $iWndW
    If $iBottom > $iWndH Then $iBottom = $iWndH

    ; Compute the size of the final picture.
    $iPicWidth = $iRight - $iLeft
    $iPicHeight = $iBottom - $iTop

    ; Compute the borders sizes
    $tClient = _WinAPI_GetClientRect($hWnd)
    $iBorderV = (($iWndW - $iWndX) - DllStructGetData($tClient, "Right")) / 2
    $iBorderT = ($iWndH - $iWndY) - DllStructGetData($tClient, "Bottom") - $iBorderV

    ; Transfert color data
    $hDDC = _WinAPI_GetDC($hWnd)
    $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iPicWidth, $iPicHeight)
    _WinAPI_SelectObject($hCDC, $hBMP)
    _WinAPI_BitBlt($hCDC, 0, 0, $iPicWidth, $iPicHeight, $hDDC, $iLeft - $iBorderV, $iTop - $iBorderT, $SRCCOPY)

    ; Add the cursor on the screenshot
    If $fCursor Then
        $aCursor = _WinAPI_GetCursorInfo()
        If $aCursor[1] Then
            $hIcon = _WinAPI_CopyIcon($aCursor[2])
            $aIcon = _WinAPI_GetIconInfo($hIcon)
            $iPicCursorX = $aCursor[3] - $aIcon[2] - $iWndX - $iLeft
            $iPicCursorY = $aCursor[4] - $aIcon[3] - $iWndY - $iTop
            _WinAPI_DrawIcon($hCDC, $iPicCursorX, $iPicCursorY, $hIcon)
        EndIf
    EndIf

    ; Clean and save data
    _WinAPI_ReleaseDC($hWnd, $hDDC)
    _WinAPI_DeleteDC($hCDC)
    If $sFileName = "" Then Return $hBMP
    _ScreenCapture_SaveImage($sFileName, $hBMP)

EndFunc   ;==>_ScreenCapture_CaptureWndV2

_ScreenCapture_CaptureWndV2.au3

Link to comment
Share on other sites

An alternative to the standard '_ScreenCapture_CaptureWnd' in order to capture the layered windows as well.

What are layered windows?

I have tried to capture AIMP3 window, but no luck :)

Or even Calculator by Yashied, not captured as well, and it's have $WS_EX_LAYERED style.

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Handles matter

A layered window is drawn by the graphic card, not by the OS.

So you have to use the right handle. One should use the window's handle directly. If you use the $hDesktopWnd, the window will be invisible.

=> This is the issue that arises in both _ScreenCapture_Capture and _ScreenCapture_CaptureWnd.

(NOTE: _ScreenCapture_CaptureWnd doesn't actually use the window handle -- except to get the window coordinates -- and the main work is done in _ScreenCapture_Capture.)

Here, _ScreenCapture_CaptureWndV2, is a function that really uses the handle of the window that you want to take a screenshot of.

(Credits to Paul Campbell's and Jennico for a couple pieces of code.)

And Next?...

Next, one would have to write a _ScreenCapture_CaptureV2 that takes into account the layered windows as well... But this will be a bit more difficult.

One will have to:

1/ make a list of all the visible windows (sorted by increasing Z-order!)

2/ take a screenshot of the desktop,

3/ take a screenshot of all the visible windows

4/ paste all the windows' screenshots on top of the desktop's screenshot

5/ return the final screenshot

Link to comment
Share on other sites

Another way. All layered windows will be drawn.

#Include <ClipBoard.au3>
#Include <GDIPlus.au3>

_ScreenCapture(@ScriptDir & '\Screenshot.bmp')

Func _ScreenCapture($sFile)

    Local $Result, $Timer, $hImage, $hBitmap = 0

    ClipPut('')
    Send('{PRINTSCREEN}')
    $Timer = TimerInit()
    While TimerDiff($Timer) < 1000
        _ClipBoard_Open(0)
        $hBitmap = _ClipBoard_GetDataEx($CF_BITMAP)
        _ClipBoard_Close()
        If $hBitmap Then
            ExitLoop
        EndIf
        Sleep(10)
    WEnd
    If Not $hBitmap Then
        Return 0
    EndIf
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    $Result = _GDIPlus_ImageSaveToFile($hImage, $sFile)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    Return $Result
EndFunc   ;==>_ScreenCapture
Link to comment
Share on other sites

Another way

Not so good if you want to capture some control inside a window (with «_ScreenCapture_CaptureWnd» we can capture control element if we pass it's handle as $hWnd).

Chess

Thanks for the info.

But i still don't see how this function different from the original one.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Not so good if you want to capture some control inside a window (with «_ScreenCapture_CaptureWnd» we can capture control element if we pass it's handle as $hWnd).

This is just an example. The resulting bitmap can be crops to the window of interest. This is not a problem.
Link to comment
Share on other sites

This is just an example. The resulting bitmap can be crops to the window of interest. This is not a problem.

Can you show please an example of capturing child control element of the window?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

still don't see how this function different from the original one.

Well you just need to have a look at the code _ScreenCapture_CaptureWnd:

Func _ScreenCapture_CaptureWnd($sFileName, $hWnd, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)
    Local $tRect = _WinAPI_GetWindowRect($hWnd)
    $iLeft += DllStructGetData($tRect, "Left")
    $iTop += DllStructGetData($tRect, "Top")
    If $iRight = -1 Then $iRight = DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left")
    If $iBottom = -1 Then $iBottom = DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top")
    $iRight += DllStructGetData($tRect, "Left")
    $iBottom += DllStructGetData($tRect, "Top")
    If $iLeft > DllStructGetData($tRect, "Right") Then $iLeft = DllStructGetData($tRect, "Left")
    If $iTop > DllStructGetData($tRect, "Bottom") Then $iTop = DllStructGetData($tRect, "Top")
    If $iRight > DllStructGetData($tRect, "Right") Then $iRight = DllStructGetData($tRect, "Right")
    If $iBottom > DllStructGetData($tRect, "Bottom") Then $iBottom = DllStructGetData($tRect, "Bottom")
    Return _ScreenCapture_Capture($sFileName, $iLeft, $iTop, $iRight, $iBottom, $fCursor)
EndFunc   ;==>_ScreenCapture_CaptureWnd

Here is how it works:

- it takes the coordinates of the window

- it calls '_ScreenCapture_Capture'

And here is what '_ScreenCapture_Capture' does:

- it calls '_WinAPI_GetDesktopWindow' to retrieve a handle to the desktop window.

- it takes a screenshot of the desktop (with all the DC tricks, etc.)

- it crops the screenshot of the desktop according to the parameters (which happen to be the coords of our original window)

=> as a result layered windows are invisible using this technique, because the desktop handles have no knowledge of those windows.

Finally, here is how _ScreenCapture_CaptureWndV2 works:

- we use the handle and the DC of the window itslef

(and the desktop's handle is not even mentionned in my code).

=> when you use the handle + DC of the window, it is visible even if it is layered.

Link to comment
Share on other sites

Another way.

Send('{PRINTSCREEN}')
$hBitmap = _ClipBoard_GetDataEx($CF_BITMAP)
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$Result = _GDIPlus_ImageSaveToFile($hImage, $sFile)

Coool... It will do the trick indeed. I did some heavy mspaint.exe automation to retrieve the content of the clipboard. So I'll use that instead from now on. :)

I would rather call it _PrtnScnCapture_Capture though (to indicate that it uses the PrtScn keyboard and plays with the clipboard).

NOTE: One could also write a function _PrtnScnCapture_CaptureWnd indeed. Would just have to crop the desktop window (cf. _ScreenCapture_Capture and _ScreenCapture_CaptureWnd, it's the same thing). ;-)

Link to comment
Share on other sites

Well you just need to have a look at the code _ScreenCapture_CaptureWnd:

I did, what i meant is that there is no differens in functions final result.

=> when you use the handle + DC of the window, it is visible even if it is layered.

But it's not!

P.S

I use WinXP SP3.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

what i meant is that there is no differens in functions final result.

How did you retrieve your window handle? I'll have a look at those apps you mentionned before. I'll let you know what I find...

Link to comment
Share on other sites

  • Moderators

Func _ScreenCapture_CaptureWndV2($sFileName, $hWnd, $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)

Wouldn't this make more sense? ( I'm sure you're trying to make it backwards compatible, but even the other one drives me crazy with its setup. )

Func _ScreenCapture_CaptureWndV2($hWnd, $sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $fCursor = True)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

How did you retrieve your window handle? I'll have a look at those apps you mentionned before. I'll let you know what I find...

WinGetHandle("AIMP3")
;Or
WinGetHandle("Calculator")

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Wouldn't this make more sense?

$hWnd, $sFileName = ""

In my dream world, the $hWnd parameter would be also optional and would be set by default to to "[ACTIVE]". But you are absolutely right. 'CaptureWnd' is not coherent with 'Capture', and it should...
Link to comment
Share on other sites

WinGetHandle("AIMP3")
;Or
WinGetHandle("Calculator")

OK. So...

I checked and I confirm: it doesn't work on your exemple, but it does work on mine.

#include <_ScreenCapture_CaptureWndV2.au3>
$hWnd = HWnd(0x00460C26)
WinActivate($hWnd)
WinWaitActive($hWnd)
Sleep(500)
_ScreenCapture_CaptureWnd($hWnd & "-_ScreenCapture_CaptureWnd.png", $hWnd)
_ScreenCapture_CaptureWndV2($hWnd & "-_ScreenCapture_CaptureWndV2.png", $hWnd)

=> See screenshots in attachment...

The styles differences are as follows:

BUBBLE                      CALCULATOR

WS_POPUP                    WS_POPUP
WS_VISIBLE                  WS_VISIBLE
WS_CLIPSIBLINGS             WS_CLIPSIBLINGS
                            WS_BORDER
                            WS_SYSMENU


WS_EX_LEFT                  WS_EX_LEFT
WS_EX_LTRREADING            WS_EX_LTRREADING
WS_EX_RIGHTSCROLLBAR        WS_EX_RIGHTSCROLLBAR
WS_EX_TOPMOST               WS_EX_TOPMOST
WS_EX_TOOLWINDOW
WS_EX_LAYERED               WS_EX_LAYERED

=> I tried changing the Calculator application and recompiling it with different settings/styles. So, I replaced $WS_EX_LAYERED by BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW)), without luck.

An interesting test would be to remove the WS_BORDER and WS_SYSMENU styles and see if it still doesn't work.

Last but not least, we should ask the author of this application whether he is doing anything special that might stop us from taking a screenshot of the window?

post-45499-0-00976400-1311958816_thumb.p

post-45499-0-00611800-1311958825_thumb.p

post-45499-0-80521500-1311958833_thumb.p

post-45499-0-25258100-1311958843_thumb.p

Link to comment
Share on other sites

we should ask the author of this application whether he is doing anything special that might stop us from taking a screenshot of the window

I think we should find out how PrntScrn works instead :)

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

One possible and SIMPLE way to fix this issue is to add the CAPTUREBLT flag to the BitBlt call in the original '_ScreenCapture_Capture' function.

_WinAPI_BitBlt( ... , BitOR($SRCCOPY, $CAPTUREBLT))

Created Ticket 1991 to address this issue... consider amending your UDF in the meantime.

I will not include this into '_ScreenCapture_CaptureV2' because it is out of scope. The whole point of '_ScreenCapture_CaptureWndV2' is to use the DC of the window itself instead of just being a wrapper for '_ScreenCapture_Capture'.

Thanks

--

Edited Wednesday, 3 August 2011, 11:40 AM

Eventually this could become an additional parameter - that way users could choose whether to have the layered windows visible or not on the screenshots.

post-45499-0-61137400-1312361633_thumb.p

Edited by Chess
Link to comment
Share on other sites

but how to capture selected region(a rectangle including several windows or parts of several windows) by _ScreenCapture_CaptureWndV2 ?

You can't. Please see my comment above to see how to fix _ScreenCapture_Capture and use that instead.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...