Confused In Gdi

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
adrielalfeus
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
ExitApp
}

title=mygame hehe


IfWinNotExist, %title%
{
msgbox %title% not found
Gdip_Shutdown(pToken)
ExitApp, 
}
winget,hwnd,ID,%title%

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

return

Guiclose:
Gdip_Shutdown(pToken)
exitapp
[Mod edit: [code][/code] tags added]
adrielalfeus
Posts: 3
Joined: 06 Jul 2019, 04:58

Re: Confused In Gdi

29 Jul 2019, 07:38

pleasee help meee
swagfag
Posts: 6222
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 https://www.autohotkey.com/boards/viewtopic.php?f=76&t=64389)
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

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
noname
Posts: 515
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 .

https://github.com/Millimeter-Git/AhkGdip_ImageSearchForChrome/blob/master/Gdip_BitmapFromHWND_EX.ahk
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

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

UINT flags = PW_CLIENTONLY | PW_RENDERFULLCONTENT

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 (v1)”

Who is online

Users browsing this forum: filipemb, TAC109, wineguy and 283 guests