However, it takes advantage of Aeropeek in Vista/Win 7 rather than taking a sequence of screen shots. This means the thumbnail is updated in real time, so you can draw a picture around an embedded video, then float that on top of another windows... without any loss in framerate.
This is all done via a great bit of code by relmaul.esel, http://www.autohotke...topic70839.html
I've included two hotkeys,
win+w: sets up a thumbnail to show the entire active window
or
ctrl+shift+LButton: to drag a box around a specific region.
There are two scripts needed, the first needs to be saved as Thumbnail.ahk. This is relmaul.esel's code, but with a slight change (which i think is a bug in the original):
/************************************************************************************************************** title: Thumbnail functions wrapped by maul.esel Credits: - skrommel for example how to show a thumbnail (http://www.autohotkey.com/forum/topic34318.html) - RaptorOne & IsNull for correcting some mistakes in the code NOTE: *This requires Windows Vista or Windows7* (tested on Windows 7) Quick-Tutorial: To add a thumbnail to a gui, you must know the following: - the hwnd / id of your gui - the hwnd / id of the window to show - the coordinates where to show the thumbnail - the coordinates of the area to be shown 1. Create a thumbnail with Thumbnail_Create() 2. Set its regions with Thumbnail_SetRegion() a. optionally query for the source windows width and height before with <Thumbnail_GetSourceSize()> 3. optionally set the opacity with <Thumbnail_SetOpacity()> 4. show the thumbnail with <Thumbnail_Show()> *************************************************************************************************************** */ /************************************************************************************************************** Function: Thumbnail_Create() creates a thumbnail relationship between two windows params: handle hDestination - the window that will show the thumbnail handle hSource - the window whose thumbnail will be shown returns: handle hThumb - thumbnail id on success, false on failure Remarks: To get the Hwnds, you could use WinExist() *************************************************************************************************************** */ Thumbnail_Create(hDestination, hSource) { VarSetCapacity(thumbnail, 4, 0) if DllCall("dwmapi.dll\DwmRegisterThumbnail", "UInt", hDestination, "UInt", hSource, "UInt", &thumbnail) return false return NumGet(thumbnail) } /************************************************************************************************************** Function: Thumbnail_SetRegion() defines dimensions of a previously created thumbnail params: handle hThumb - the thumbnail id returned by <Thumbnail_Create()> int xDest - the x-coordinate of the rendered thumbnail inside the destination window int yDest - the y-coordinate of the rendered thumbnail inside the destination window int wDest - the width of the rendered thumbnail inside the destination window int hDest - the height of the rendered thumbnail inside the destination window int xSource - the x-coordinate of the area that will be shown inside the thumbnail int ySource - the y-coordinate of the area that will be shown inside the thumbnail int wSource - the width of the area that will be shown inside the thumbnail int hSource - the height of the area that will be shown inside the thumbnail returns: bool success - true on success, false on failure *************************************************************************************************************** */ Thumbnail_SetRegion(hThumb, xDest, yDest, wDest, hDest, xSource, ySource, wSource, hSource) { dwFlags := 0x00000001 | 0x00000002 VarSetCapacity(dskThumbProps, 45, 0) NumPut(dwFlags, dskThumbProps, 0, "UInt") NumPut(xDest, dskThumbProps, 4, "Int") NumPut(yDest, dskThumbProps, 8, "Int") NumPut(wDest+xDest, dskThumbProps, 12, "Int") NumPut(hDest+yDest, dskThumbProps, 16, "Int") NumPut(xSource, dskThumbProps, 20, "Int") NumPut(ySource, dskThumbProps, 24, "Int") NumPut(wSource+xSource, dskThumbProps, 28, "Int") NumPut(hSource+ySource, dskThumbProps, 32, "Int") return DllCall("dwmapi.dll\DwmUpdateThumbnailProperties", "UInt", hThumb, "UInt", &dskThumbProps) ? false : true } /************************************************************************************************************** Function: Thumbnail_Show() shows a previously created and sized thumbnail params: handle hThumb - the thumbnail id returned by <Thumbnail_Create()> returns: bool success - true on success, false on failure *************************************************************************************************************** */ Thumbnail_Show(hThumb) { static dwFlags := 0x00000008, fVisible := 1 VarSetCapacity(dskThumbProps, 45, 0) NumPut(dwFlags, dskThumbProps, 0, "UInt") NumPut(fVisible, dskThumbProps, 37, "Int") return DllCall("dwmapi.dll\DwmUpdateThumbnailProperties", "UInt", hThumb, "UInt", &dskThumbProps) ? false : true } /************************************************************************************************************** Function: Thumbnail_Hide() hides a thumbnail. It can be shown again without recreating params: handle hThumb - the thumbnail id returned by <Thumbnail_Create()> returns: bool success - true on success, false on failure *************************************************************************************************************** */ Thumbnail_Hide(hThumb) { static dwFlags := 0x00000008, fVisible := 0 VarSetCapacity(dskThumbProps, 45, 0) NumPut(dwFlags, dskThumbProps, 0, "Uint") NumPut(fVisible, dskThumbProps, 37, "Int") return DllCall("dwmapi.dll\DwmUpdateThumbnailProperties", "UInt", hThumb, "UInt", &dskThumbProps) ? false : true } /************************************************************************************************************** Function: Thumbnail_Destroy() destroys a thumbnail relationship params: handle hThumb - the thumbnail id returned by <Thumbnail_Create()> returns: bool success - true on success, false on failure *************************************************************************************************************** */ Thumbnail_Destroy(hThumb) { return DllCall("dwmapi.dll\DwmUnregisterThumbnail", "UInt", hThumb) ? false : true } /************************************************************************************************************** Function: Thumbnail_GetSourceSize() gets the width and height of the source window - can be used with <Thumbnail_SetRegion()> params: handle hThumb - the thumbnail id returned by <Thumbnail_Create()> ByRef int width - receives the width of the window ByRef int height - receives the height of the window returns: bool success - true on success, false on failure *************************************************************************************************************** */ Thumbnail_GetSourceSize(hThumb, ByRef width, ByRef height) { VarSetCapacity(Size, 8, 0) if DllCall("dwmapi.dll\DwmQueryThumbnailSourceSize", "Uint", hThumb, "Uint", &Size) return false width := NumGet(&Size + 0, 0, "int") height := NumGet(&Size + 0, 4, "int") return true } /************************************************************************************************************** Function: Thumbnail_SetOpacity() sets the current opacity level params: handle hThumb - the thumbnail id returned by <Thumbnail_Create()> int opacity - the opacity level from 0 to 255 (will wrap to the other end if invalid) returns: bool success - true on success, false on failure *************************************************************************************************************** */ Thumbnail_SetOpacity(hThumb, opacity) { static dwFlags := 0x00000004 VarSetCapacity(dskThumbProps, 45, 0) NumPut(dwFlags, dskThumbProps, 0, "UInt") NumPut(opacity, dskThumbProps, 36, "UChar") return DllCall("dwmapi.dll\DwmUpdateThumbnailProperties", "Uint", hThumb, "UInt", &dskThumbProps) ? false : true } /************************************************************************************************************** section: example This example sctript shows a thumbnail of your desktop in a GUI (start code) ; initializing the script: #SingleInstance force #NoEnv #KeyHistory 0 SetWorkingDir %A_ScriptDir% #include Thumbnail.ahk ; get the handles: Gui +LastFound hDestination := WinExist() ; ... to our GUI... hSource := WinExist("ahk_class Progman") ; ... and to the desktop ; creating the thumbnail: hThumb := Thumbnail_Create(hDestination, hSource) ; you must get the return value here! ; getting the source window dimensions: Thumbnail_GetSourceSize(hThumb, width, height) ; then setting its region: Thumbnail_SetRegion(hThumb, 25, 25 ; x and y in the GUI , 400, 350 ; display dimensions , 0, 0 ; source area coordinates , width, height) ; the values from Thumbnail_GetSourceSize() ; now some GUI stuff: Gui +AlwaysOnTop +ToolWindow Gui Add, Button, gHideShow x0 y0, Hide / Show ; Now we can show it: Thumbnail_Show(hThumb) ; but it is not visible now... Gui Show, w450 h400 ; ... until we show the GUI ; even now we can set the transparency: Thumbnail_SetOpacity(hThumb, 200) return GuiClose: ; in case the GUI is closed: Thumbnail_Destroy(hThumb) ; free the resources ExitApp HideShow: ; in case the button is clicked: if hidden Thumbnail_Show(hThumb) else Thumbnail_Hide(hThumb) hidden := !hidden return (end) *************************************************************************************************************** */
Then the following is my code, which you run to get the livewindows functionality:
; initializing the script: #SingleInstance force #NoEnv #KeyHistory 0 SetWorkingDir %A_ScriptDir% #include Thumbnail.ahk ;--- Script to monitior a window or section of a window (such as a progress bar, or video) in a resizable live preview window ;--- This is an update (in terms of functionality) to the original livewindows ahk script by Holomind http://www.autohotkey.com/forum/topic11588.html ;--- which takes advantage of windows vista/7 Aeropeak. The script relies on Thumbnail.ahk, a great script by relmaul.esel, http://www.autohotkey.com/forum/topic70839.html ;-------------------------------------------------------------------------------------------- Hotkey, ^+LButton , start_defining_region Hotkey, #w, watchWindow msgbox, Press win+w to watch the entire active window `n`nOr hold down ctrl+shift and drag a box around the `narea you are interested in to watch a specific region return ;-------------------------------------------------------------------------------------------- watchWindow: WinGetClass, class, A ; get ahk_id of foreground window targetName = ahk_class %class% ; get target window id WinGetPos, , , Rwidth, Rheight, A start_x := 0 start_y := 0 sleep, 500 ThumbWidth := 400 ThumbHeight := 400 thumbID := mainCode(targetName,ThumbWidth,ThumbHeight,start_x,start_y,Rwidth,Rheight) return start_defining_region: Gui, Destroy Thumbnail_Destroy(thumbID) CoordMode, Mouse, Relative ; relative to window not screen MouseGetPos, start_x, start_y ; start position of mouse SetTimer end_defining_region, 200 ; check every 50ms for mouseup Return end_defining_region: ; get the region dimensions MouseGetPos, current_x, current_y Rheight := abs(current_y - start_y) Rwidth := abs(current_x - start_x) WinGetPos, win_x, win_y, , , A P_x := start_x + win_x P_y := start_y + win_y if (current_x < start_x) P_x := current_x + win_x if (current_y < start_y) P_y := current_y + win_y ; draw a box to show what is being defined Progress, B1 CWffdddd CTff5555 ZH0 fs13 W%Rwidth% H%Rheight% x%P_x% y%P_y%, , ,getMyRegion WinSet, Transparent, 110, getMyRegion ; if mouse not released then loop through above code... If GetKeyState("LButton", "P") Return ;...otherwise, stop defining region, and start thumbnail -------------------------------> SetTimer end_defining_region, OFF Progress, off MouseGetPos, end_x, end_y if (end_x < start_x) start_x := end_x if (end_y < start_y) start_y := end_y WinGetClass, class, A ; get ahk_id of foreground window targetName = ahk_class %class% ; get target window id sleep, 500 ThumbWidth := Rwidth ThumbHeight := Rheight thumbID := mainCode(targetName,ThumbWidth,ThumbHeight,start_x,start_y,Rwidth,Rheight) return mainCode(targetName,windowWidth,windowHeight,RegionX,RegionY,RegionW,RegionH) { ; get the handles: Gui +LastFound hDestination := WinExist() ; ... to our GUI... hSource := WinExist(targetName) ; ; creating the thumbnail: hThumb := Thumbnail_Create(hDestination, hSource) ; you must get the return value here! ; getting the source window dimensions: Thumbnail_GetSourceSize(hThumb, width, height) ;-- make sure ratio is correct CorrectRatio := RegionW / RegionH testWidth := windowHeight * CorrectRatio if (windowWidth < testWidth) { windowHeight := windowWidth / CorrectRatio } ; else ; { ; windowWidth := testWidth ; } ; then setting its region: Thumbnail_SetRegion(hThumb, 0, 0 , windowWidth, windowHeight, RegionX , RegionY ,RegionW, RegionH) ; now some GUI stuff: Gui +AlwaysOnTop +ToolWindow +Resize ; Now we can show it: Thumbnail_Show(hThumb) ; but it is not visible now... Gui Show, w%windowWidth% h%windowHeight%, Live Thumbnail ; ... until we show the GUI OnMessage(0x201, "WM_LBUTTONDOWN") return hThumb } GuiSize: ;if ErrorLevel = 1 ; The window has been minimized. No action needed. ; return Thumbnail_Destroy(thumbID) ThumbWidth := A_GuiWidth ThumbHeight := A_GuiHeight thumbID := mainCode(targetName,ThumbWidth,ThumbHeight,start_x,start_y,Rwidth,Rheight) return ;---------------------------------------------------------------------- GuiClose: ; in case the GUI is closed: Thumbnail_Destroy(thumbID) ; free the resources ExitApp WM_LBUTTONDOWN(wParam, lParam) { mX := lParam & 0xFFFF mY := lParam >> 16 SendClickThrough(mX,mY) } SendClickThrough(mX,mY) { global convertedX := Round((mX / ThumbWidth)*Rwidth + start_x) convertedY := Round((mY / ThumbHeight)*Rheight + start_y) ;msgBox, x%convertedX% y%convertedY%, %targetName% ControlClick, x%convertedX% y%convertedY%, %targetName%,,,, NA ; sleep, 250 ; ControlClick, x%convertedX% y%convertedY%, %targetName%,,,, NA u }