Page 1 of 1
image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 1:52 am
by jassing
If I use
img = CatchImage(-1,?myimage)
the image is loaded, and I get a handle/id...
But if I try to use this id in CreatePopupImageMenu(), it fails.
I have to use a non negative number(ie: CatchImage(0...)) and ImageID(0) to get it to work.
Shouldn't it work the 1st way? Or what am I missing?
Code: Select all
UsePNGImageDecoder()
OpenWindow(0,100,100,300,200,"Test")
If CreatePopupImageMenu(0)
CompilerIf #true
;- this way works.
img = CatchImage(0, ?MenuCopy)
Debug ImageID(0)
Debug img
MenuItem(1, "Copy jSysLogClient() call", ImageID(0))
CompilerElse
;- this way does not work
img = CatchImage(#PB_Any, ?MenuCopy)
Debug img
MenuItem(1, "Copy jSysLogClient() call", img)
CompilerEndIf
MenuItem(2, "Use Alternate method")
MenuItem(3, "Quit")
Else
Debug "Failed to create menu"
EndIf
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
Select EventMenu()
Case 1 : Debug "Copy"
Case 3 : PostEvent(#PB_Event_CloseWindow)
EndSelect
Case #PB_Event_RightClick
DisplayPopupMenu(0,WindowID(0))
EndSelect
ForEver
DataSection ;- Image for menu
MenuCopy:
IncludeBinary #PB_Compiler_Home+"\Examples\Sources\Data\ToolBar\Copy.png"
EndDataSection
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 2:13 am
by Thunder93
"MenuItem(MenuItemID, Text$ [, ImageID])"
Parameters
ImageID (optional) The image to be displayed next to the menu item. The menu must be created with CreateImageMenu() or CreatePopupImageMenu() for the image to be displayed. This value can be obtained using the ImageID() function.
... You've skipped the ImageID() function in the MenuItem()
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 2:39 am
by jassing
Hmm. I guess I misunderstand the return value from CatchImage()
it appears to be the ImageID(), so calling CatchImage(-1) then calling ImageID() results in an error...
Oh well; thanks... I'll just change the code to use static image #'s -- I wanted to avoid that...
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 3:26 am
by jacdelad
If you don't use #PB_Any with CatchImage the return value only indicates if the function succeeded (non-zero) or not (zero). I've read in several thread that the return value of this is the ImageID() of the handle, but this is not clearly written into the help, so I would trust on it (and you can also always use ImageID() to get the desired value).
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 3:35 am
by Demivec
jassing wrote: Thu Apr 06, 2023 2:39 am
Hmm. I guess I misunderstand the return value from CatchImage()
it appears to be the ImageID(), so calling CatchImage(-1) then calling ImageID() results in an error...
Oh well; thanks... I'll just change the code to use static image #'s -- I wanted to avoid that...
Are you saying it doesn't work when you use code such as?
Code: Select all
img = CatchImage(#PB_Any, ?MenuCopy)
MenuItem(1, "Copy jSysLogClient() call", ImageID(img))
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 4:35 am
by jacdelad
No, this is the right way. The wrong way (or not offical way) would be:
Code: Select all
img = CatchImage(0, ?MenuCopy)
MenuItem(1, "Copy jSysLogClient() call", img)
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 4:44 am
by jassing
I apologize for not being clear.
If I use #PB_ANY, it doesn't work.
if I use 0, 1,23, etc it works fine.
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 5:33 am
by Paul
jassing wrote: Thu Apr 06, 2023 4:44 am
If I use #PB_ANY, it doesn't work.
Because as Demivec said, you have to use
Code: Select all
img = CatchImage(#PB_Any, ?MenuCopy)
MenuItem(1, "Copy jSysLogClient() call", ImageID(img))
and you used...
Code: Select all
img = CatchImage(#PB_Any, ?MenuCopy)
MenuItem(1, "Copy jSysLogClient() call", img)
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 6:39 am
by Bisonte
There are two types of ID's, PureBasic ID and OS ID.
Purebasic functions ALWAYS want a Purebasic ID !
Example :
CatchImage( PureBasicID, ....)
ImageID( PureBasicID )
If the help of a function says that an ImageID is needed, like for
displaying images (ImageGadget(), DisplayImage() ....) then you
have to convert the PureBasicID.
#PB_Any is a constant with the value -1 (that's why your -1 always worked).
The help for CatchImage() says that if #PB_Any (i.e. -1) is used, the return
value is an PureBasicID.
I hope the translation from DeepL worked
Translated with
www.DeepL.com/Translator (free version)
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 7:00 am
by RASHAD
Gentlemen
jassing is a very good coder he doesn't need all these instructions
Just survey his posts
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 7:29 am
by Denis
Bisonte wrote: Thu Apr 06, 2023 6:39 am
#PB_Any is a constant with the value -1 (that's why your -1 always worked).
The help for CatchImage() says that if #PB_Any (i.e. -1) is used, the return
value is an ImageHandle (which is actually what is needed for display).
The French documentation does not say that.
May be an error in the English documentation ?
Maybe I misunderstood ???
#Image Le numéro d'identification de l'image.
#PB_Any peut être utilisé pour générer automatiquement ce numéro.
#Image The identification number of the image.
#PB_Any can be used to automatically generate this number.
The only function to get the handle is ImageID(), nothing more nothing less.
Sometimes some functions can return the handle but this is not the right way.
We just have to follow documentation.
Re: image popup, catchimage(-1/0 issue
Posted: Thu Apr 06, 2023 2:35 pm
by mk-soft
@bisonte
#PB_Any is a constant with the value -1 (that's why your -1 always worked).
The help for CatchImage() says that if #PB_Any (i.e. -1) is used, the return
value is an ImageHandle (which is actually what is needed for display).
That is not quite right. Creating an object in PB with 'PB_Any' always returns a
dynamic pb object number. This must be relaese with Free[xyz](object_variable).
The return value when creating a PB object with a constant returns (unofficially) the handle under Windows or the OS object under macOS, Linux.