I've noticed that I have to activate two times the GUI otherwise it won't be shown the first time the hotkey is triggered... I mean:
At line #15 is the first it's displayed (although "invisible" at this point), then at line #37... if I delete the 15th line, the image will be shown the second time the function is executed, what's the reason behind this?
Right now the script only shows a static image, what about having the contents in semi-real time? I guess "Gdip_BitmapFromHWND" is not effective inside a loop?
Would "PrintWindow" and "BitBlt" be useful in this case? What's the approach in a nutshell?... Check the commented part where I tried to code
http://p.ahkscript.org/?p=a4f5753e
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance, Force
#Persistent
#include Gdip.ahk
pToken := Gdip_Startup()
OnExit, Exit
Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA ;???
hwnd := WinExist()
hdc_gui := GetDC(hwnd)
space::
id := WinExist("A")
WinGetPos, x, y, w, h, ahk_id %id%
;---
pBitmap := Gdip_BitmapFromHWND(id) ;create Window Bitmap
hbm := Gdip_CreateHBITMAPFromBitmap(pBitmap) ;convert to GDI bmp
hdc_bmp := CreateCompatibleDC() ;source DC
obm := SelectObject(hdc_bmp, hbm) ;select converted GDI bmp into source DC
G := Gdip_GraphicsFromHDC(hdc_bmp) ;get its Graphics
Gdip_DrawImage(G, pBitmap) ;draw the captured bmp into it
Gdip_DisposeImage(pBitmap) ;delete as is not longer used
Gdip_DeleteGraphics(G)
UpdateLayeredWindow(hwnd, hdc_bmp, 0, 0, w, h)
;BitBlt(hdc_gui, 0, 0, w, h, hdc_bmp, 0, 0)
Gui, 1: Show, NA ;???
KeyWait, space
Gui, 1: Cancel
SelectObject(hdc_bmp, obm), DeleteObject(hbm)
DeleteDC(hdc_bmp)
/*
hbm := CreateDIBSection(w, h), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Loop
{
if (first)
{
first := !first
Gui, 1: Show, NA ;???
}
if (!Mod(A_Index, 50))
{
;PrintWindow(hwnd, hdc)
pBitmap := Gdip_BitmapFromHWND(id) ; ----> ???
Gdip_DrawImage(G, pBitmap)
BitBlt(hdc_gui, 0, 0, w, h, hdc, 0, 0)
Gdip_DisposeImage(pBitmap)
}
if (!GetKeyState("space", "P"))
break
}
Gui, 1: Cancel
Gdip_DeleteGraphics(G)
SelectObject(hdc, obm), DeleteObject(hbm)
DeleteDC(hdc)
*/
return
Exit:
DeleteDC(hdc_gui)
Gdip_Shutdown(pToken)
ExitApp
return