Code: Select all
fromHwnd(hwnd, wOffset := 0, hOffset := 0, xOffset := 0, yOffset := 0) {
WinGetPos x, y, w, h, % "ahk_id" hwnd
hbm1 := CreateDIBSection(w, h)
hdc1 := CreateCompatibleDC()
obm1 := SelectObject(hdc1, hbm1)
DllCall("PrintWindow", "Ptr", hwnd, "Ptr", hdc1, "UInt", 2)
w -= wOffset
h -= hOffset
hbm2 := CreateDIBSection(w, h)
hdc2 := CreateCompatibleDC()
obm2 := SelectObject(hdc2, hbm2)
BitBlt(hdc2, 0, 0, w, h, hdc1, xOffset, yOffset)
pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm2)
SelectObject(hdc1, obm1)
SelectObject(hdc2, obm2)
DeleteObject(hbm1)
DeleteObject(hbm2)
DeleteDC(hdc1)
DeleteDC(hdc2)
return pBitmap
}
but ull have to readjust the offsets(probably on a per app basis) to get rid of the black bars
Code: Select all
#Include <Gdip_All>
hwnd := WinExist("some folder")
fromHwnd(hwnd)
fromHwnd(hwnd, 16, 9, 8, 1)
Esc::ExitApp
fromHwnd(hwnd, wOffset := 0, hOffset := 0, xOffset := 0, yOffset := 0) {
WinGetPos x, y, w, h, % "ahk_id" hwnd
hbm1 := CreateDIBSection(w, h)
hdc1 := CreateCompatibleDC()
obm1 := SelectObject(hdc1, hbm1)
DllCall("PrintWindow", "Ptr", hwnd, "Ptr", hdc1, "UInt", 2)
w -= wOffset
h -= hOffset
hbm2 := CreateDIBSection(w, h)
hdc2 := CreateCompatibleDC()
obm2 := SelectObject(hdc2, hbm2)
BitBlt(hdc2, 0, 0, w, h, hdc1, xOffset, yOffset)
Gui New
Gui Add, Picture, w%w% h%h%, HBITMAP: %hbm2%
Gui Show
}