Page 1 of 1

Confused In Gdi

Posted: 27 Jul 2019, 01:20
by adrielalfeus
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]

Re: Confused In Gdi

Posted: 29 Jul 2019, 07:38
by adrielalfeus
pleasee help meee

Re: Confused In Gdi

Posted: 29 Jul 2019, 07:54
by swagfag
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)

Re: Confused In Gdi

Posted: 29 Jul 2019, 08:55
by teadrinker
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.

Re: Confused In Gdi

Posted: 30 Jul 2019, 05:31
by noname
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

Re: Confused In Gdi

Posted: 30 Jul 2019, 05:55
by iseahound
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