Confused In Gdi

Get help with using AutoHotkey and its commands and hotkeys
Posts: 3
Joined: 06 Jul 2019, 04:58

Confused In Gdi

27 Jul 2019, 01:20

So i just start to use GDIP script to do image search in background but when i ran the script its shows blackscreen.. i dont know why

this is my script

Code: Select all

SetWorkingDir, %a_scriptdir%
settitlematchmode 2
#Include Gdip_all.ahk
If !pToken := Gdip_Startup()
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system

title=mygame hehe

IfWinNotExist, %title%
msgbox %title% not found

pBitmapHayStack :=Gdip_BitmapFromHWND(hwnd)
Gdip_SaveBitmapToFile(pBitmapHayStack, "haystack.png") 
sleep 3000
Gui, add,picture,,haystack.png
Gui, show,autosize


[Mod edit: [code][/code] tags added]
Posts: 3
Joined: 06 Jul 2019, 04:58

Re: Confused In Gdi

29 Jul 2019, 07:38

pleasee help meee
Posts: 4092
Joined: 11 Jan 2017, 17:59

Re: Confused In Gdi

29 Jul 2019, 07:54

if a black image is being saved the call to Gdip_BitmapFromHWND(hwnd) probably has failed. numerous things can be the cause of this - passing an invalid hwnd, hwnd is an exlusive fullscreen application, hwnd doesnt handle WM_PRINT(eg chrome, see
Posts: 2058
Joined: 29 Mar 2015, 09:41

Re: Confused In Gdi

29 Jul 2019, 08:55

The application can use protection from taking screenshots.
SetWindowDisplayAffinity function
This function and GetWindowDisplayAffinity are designed to support the window content protection feature that is new to Windows 7. This feature enables applications to protect their own onscreen window content from being captured or copied through a specific set of public operating system features and APIs. However, it works only when the Desktop Window Manager(DWM) is composing the desktop.
User avatar
Posts: 510
Joined: 19 Nov 2013, 09:15

Re: Confused In Gdi

30 Jul 2019, 05:31

Maybe it is worth trying a function made by Millimeter-Git , it does not rely on the "printwindow" call but uses Bitbild .
Posts: 617
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Confused In Gdi

30 Jul 2019, 05:55

Did you modify the flag in Print Window?

enum PrintWindowFlags
0x1 = Client Area Only
0x2 = Direct X or something


So you should combine both flags which gives you 3.

Code: Select all

            image := (type = "window") ? 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”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], Google [Bot], miracle, songdg and 31 guests