Gui,Add,Picture with bitmap handle not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Gui,Add,Picture with bitmap handle not working

17 Oct 2021, 15:26

AHK 1.1.33.10 U64
W10 x64 21H1 10.0.19043

Hi Folks,

Doing a Gui,Add,Picture with a file works perfectly:

Code: Select all

pToken:=Gdip_Startup()
ImageFile:="c:\temp\test.png"
pBitmap:=Gdip_BitmapFromScreen("1000|300|400|200")
Gdip_SaveBitmapToFile(pBitmap,ImageFile)
Gui,Add,Picture,w500 h-1 vImage,%ImageFile%
Gui,Show,w500 h300 x200 y100
msgbox this works perfectly
ExitApp
Doing a Gui,Add,Picture with a bitmap handle fails:

Code: Select all

pToken:=Gdip_Startup()
pBitmap:=Gdip_BitmapFromScreen("1000|300|400|200")
Gui,Add,Picture,w500 h-1 vImage,HBITMAP:%pBitmap%
Gui,Show,w500 h300 x200 y100
msgbox this does not work - but handle is good: %pBitmap%
ExitApp
Can anyone explain why the bitmap handle method is not capturing the specified screen rectangle? Thanks, Joe
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Gui,Add,Picture with bitmap handle not working

17 Oct 2021, 15:46

Code: Select all

Gui, Add, Picture,, % "HBITMAP:*" Gdip_CreateHBITMAPFromBitmap(pBitmap)
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Gui,Add,Picture with bitmap handle not working

17 Oct 2021, 16:27

Hi Mikey,
I prefer clarity in my code, not brevity, so I tend to avoid forcing expressions and putting lots of code in a single line. My coding style usually makes it a lot easier in a year or two when I try to figure out what I was doing. :) Thus, I would tend to write your line as:

Code: Select all

handle:=Gdip_CreateHBITMAPFromBitmap(pBitmap)
Gui,Add,Picture,w500 h-1,HBITMAP:*%handle%
That said, I tried both...your line as is and my two-line version of it...neither worked. Did you test it on your end? Does it work? Btw, I had already tried the asterisk in front of the handle...with no difference in the result. Regards, Joe
User avatar
mikeyww
Posts: 26934
Joined: 09 Sep 2014, 18:38

Re: Gui,Add,Picture with bitmap handle not working  Topic is solved

17 Oct 2021, 16:45

Yes. My working script is below.

Code: Select all

#Include d:\Q\vis2\lib\Gdip_All.ahk ; Adjust as needed
width   := 500
height  := 300
pToken  := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen("100|100|" width "|" height)
handle  := Gdip_CreateHBITMAPFromBitmap(pBitmap)
Gui, Add, Picture, w%width% h-1, HBITMAP:*%handle%
Gui, Show,, Test HBITMAP
Output:

image211017-1750-001.png
image211017-1750-001.png (188.44 KiB) Viewed 501 times
User avatar
JoeWinograd
Posts: 2200
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Gui,Add,Picture with bitmap handle not working

17 Oct 2021, 17:53

Hi Mikey,
That code works perfectly! Thanks very much for your help. Regards, Joe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, jaka1, LuckyJoe, Rohwedder and 331 guests