Gdip_BitmapFromHWND returns blank window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Brazolek123
Posts: 187
Joined: 06 Jun 2016, 16:02

Gdip_BitmapFromHWND returns blank window

15 Dec 2018, 07:16

My code:
#Warn All, off
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen

#Include gdip.ahk ; is in the post attachment if anyone needs

If (!pToken := Gdip_Startup()){
ExitApp
}
return

f1::
WinGet, id, ID, A
return

f2::
pBitmap := Gdip_BitmapFromHWND(id)
Gdip_SaveBitmapToFile(pBitmap, "screen.bmp", 100)
Gdip_DisposeImage(pBitmap)
return

f12::
exitapp


My result:
Image

I'm testing it on Win10 x64 and being honest I'm out of ideas. Not sure if it returns blank window because of win10, graphic card, because of the target app itself... Have you got any tips for me? What can be wrong?

Thanks in advance
Attachments
gdip.ahk
(128.62 KiB) Downloaded 54 times
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Gdip_BitmapFromHWND returns blank window

15 Dec 2018, 08:30

You want to make a screenshot from a window? You receive a hwnd to a window instead with Winget. There are much screenshot functions around in this forum. I'm not on my computer at moment, so I can't post one.
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

Re: Gdip_BitmapFromHWND returns blank window

19 Dec 2018, 19:21

Code: Select all


image := 0x187410 ; Some sort of hwnd. 

               image := WinExist(image) ? WinExist(image) : image
               if DllCall("IsIconic", "ptr",image)
                  DllCall("ShowWindow", "ptr",image, "int",4) ; Restore if minimized!
               VarSetCapacity(rc, 16)
               DllCall("GetClientRect", "ptr",image, "ptr",&rc)
               hbm := CreateDIBSection(NumGet(rc, 8, "int"), NumGet(rc, 12, "int"))
               VarSetCapacity(rc, 0)
               hdc := CreateCompatibleDC()
               obm := SelectObject(hdc, hbm)
               DllCall("PrintWindow", "ptr",image, "ptr",hdc, "uint",0x3)
               pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
               SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
               return pBitmap

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, mebelantikjaya, rc76 and 309 guests