image popup, catchimage(-1/0 issue

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

image popup, catchimage(-1/0 issue

Post 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
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: image popup, catchimage(-1/0 issue

Post 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()
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: image popup, catchimage(-1/0 issue

Post 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...
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: image popup, catchimage(-1/0 issue

Post 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).
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: image popup, catchimage(-1/0 issue

Post 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))
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: image popup, catchimage(-1/0 issue

Post 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)
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: image popup, catchimage(-1/0 issue

Post 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.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: image popup, catchimage(-1/0 issue

Post 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)
Image Image
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: image popup, catchimage(-1/0 issue

Post 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)
Last edited by Bisonte on Fri Apr 14, 2023 6:46 am, edited 2 times in total.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: image popup, catchimage(-1/0 issue

Post by RASHAD »

Gentlemen :)
jassing is a very good coder he doesn't need all these instructions
Just survey his posts
Egypt my love
Denis
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Re: image popup, catchimage(-1/0 issue

Post 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.
A+
Denis
User avatar
mk-soft
Always Here
Always Here
Posts: 6252
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: image popup, catchimage(-1/0 issue

Post 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.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply