QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Dav on March 02, 2021, 11:45:14 am

Title: Using the embedded icon handles in programs
Post by: Dav on March 02, 2021, 11:45:14 am
I was snooping around the image handles and noticed that image handles -10 and -11 are always taken when my programs start, and are assigned to the embedded QB64 icon images.  So, I thought it would nice to use it in programs to display a made in QB64 logo somewhere without having to include a logo image.

But are the used handle numbers the same in all versions of QB64?  I'm using QB64 32-bit Windows and it's always -10 and -11.

Here's a sample code borrowing the embedded images...

- Dav

Code: QB64: [Select]
  1. _ICON -11 'you don't need to use -11 here, just showing it works
  2. SCREEN _NEWIMAGE(600, 600, 32)
  3. 'show both images for a sec
  4. _PUTIMAGE (50, 50), -10: _PUTIMAGE (100, 100), -11
  5.  
  6.     x = RND * _WIDTH: y = RND * _HEIGHT
  7.     _PUTIMAGE (x, y)-(x + 10 + (RND * 150), y + 10 + (RND * 150)), -11
  8.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Using the embedded icon handles in programs
Post by: FellippeHeitor on March 02, 2021, 11:52:31 am
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

You have unlocked the ancient secret...

And yes... I believe the handles will always be the same for the internal icon...

With great power, comes... great retro icons.
Title: Re: Using the embedded icon handles in programs
Post by: FellippeHeitor on March 02, 2021, 11:59:52 am
I take it back. If you have $CONSOLE in your program, handle -10 is the console page. Handles will shift around in memory depending on which images had to be created before the icons were.
Title: Re: Using the embedded icon handles in programs
Post by: SpriggsySpriggs on March 02, 2021, 12:07:31 pm
Never mind. I wrote up something and it isn't good
Title: Re: Using the embedded icon handles in programs
Post by: FellippeHeitor on March 02, 2021, 12:08:42 pm
actually

Code: QB64: [Select]
  1. IF _CONSOLE < -1 THEN PRINT "-11 and -12 are icons" ELSE PRINT "-10 and -11 are icons"
Title: Re: Using the embedded icon handles in programs
Post by: SpriggsySpriggs on March 02, 2021, 12:09:17 pm
@FellippeHeitor Yep, I was trying to go that route but didn't realize you said $CONSOLE and not $CONSOLE:ONLY
Title: Re: Using the embedded icon handles in programs
Post by: SMcNeill on March 02, 2021, 12:35:18 pm
Code: [Select]
Icon1 = -10 + (_CONSOLE = -10)
Icon2 = -11 + (_CONSOLE = -10)


Wait...  Do we even have a _CONSOLE(function)?  It’s not listed in the wiki, if we do.
Title: Re: Using the embedded icon handles in programs
Post by: Dav on March 02, 2021, 12:54:37 pm
Hmm, interesting.   Thanks for the feedback.   

I will do some more experimenting!

- Dav
Title: Re: Using the embedded icon handles in programs
Post by: FellippeHeitor on March 02, 2021, 01:34:35 pm
Code: [Select]
Icon1 = -10 + (_CONSOLE = -10)
Icon2 = -11 + (_CONSOLE = -10)


Wait...  Do we even have a _CONSOLE(function)?  It’s not listed in the wiki, if we do.

We do. It's at play when you call _DEST _CONSOLE
Title: Re: Using the embedded icon handles in programs
Post by: Dav on March 03, 2021, 09:02:05 am
It looks like -11 is a valid icon handle in either mode, so I'll just stick with -11 when I need to grab the icon image for anything, like proudly displaying the logo ...

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(600, 600, 32)
  2. _PRINTSTRING (_WIDTH - 57, _HEIGHT - 75), "Made in"
  3. _PUTIMAGE (_WIDTH - 60, _HEIGHT - 60)-(_WIDTH, _HEIGHT), -11
  4.  

- Dav
Title: Re: Using the embedded icon handles in programs
Post by: RhoSigma on March 03, 2021, 10:39:38 am
To all,
although this is an interesting find, I want to warn everybody!

Using those undocumented (hidden) features and assuming they will be always available, is exactly one of those programming habits, which destroys the upward compatiblity of your programs.

Even if it's unlikely this particular thing will change soon, it may change at any time and without warning, latest if some new people get involved in the QB64 development, who have no idea that somebody was depending exactly on that specific behavior, which they just bugfixed, overhauled or whatever change.

And if this happens in 3, 5 or 10 years, I bet you search your ass off to find out, why your program (which was working perfect all the years) does suddenly spit "Invalid handle" messages or at least showing not the expected content anymore.

I'd strongly recommend to everybody:
If you want that QB64 icon in your program, then provide it along and use the documented $EXEICON/_LOADIMAGE/_ICON ways to work with it. There are also several tools in this forum to embed those images.

Best regards
Title: Re: Using the embedded icon handles in programs
Post by: SMcNeill on March 03, 2021, 10:59:41 am
To all,
although this is an interesting find, I want to warn everybody!

Using those undocumented (hidden) features and assuming they will be always available, is exactly one of those programming habits, which destroys the upward compatiblity of your programs.

Even if it's unlikely this particular thing will change soon, it may change at any time and without warning, latest if some new people get involved in the QB64 development, who have no idea that somebody was depending exactly on that specific behavior, which they just bugfixed, overhauled or whatever change.

And if this happens in 3, 5 or 10 years, I bet you search your ass off to find out, why your program (which was working perfect all the years) does suddenly spit "Invalid handle" messages or at least showing not the expected content anymore.

I'd strongly recommend to everybody:
If you want that QB64 icon in your program, then provide it along and use the documented $EXEICON/_LOADIMAGE/_ICON ways to work with it. There are also several tools in this forum to embed those images.

Best regards

+1

I agree with this sentiment wholeheartedly, though it'd be nice if the team decided to set aside a single image/font/sound file with each download in a default /resources folder.  The main purpose of these files would be for when people ask questions either on the forums, or via Discord, so that examples could we written for them, without the need to always upload external files.

Say someone asks, "How do I change font size?"

At the moment, one has to write a program which showcases the _LOADFONT and _FONT commands, and then attach whatever font they use for the demonstration to the post. 

It'd save a lot of hassle (and probably even server storage space over time) if we had a default set of resources which came pre-packaged with QB64, which could then always be pointed to, and used, when writing/sharing code examples to help people figure out how to solve specific problems they might be having with various commands.
Title: Re: Using the embedded icon handles in programs
Post by: Dav on March 03, 2021, 11:19:38 am
Yeah I agree with that.  I hope I'm still here 10 years down the road...

Edit: speaking of resources, it would be great to see QB64 one day have adding resource files capability. Declare a resource file, like an image, and have it included in the EXE.

- Dav
Title: Re: Using the embedded icon handles in programs
Post by: SpriggsySpriggs on March 03, 2021, 02:03:48 pm
Using those undocumented (hidden) features and assuming they will be always available, is exactly one of those programming habits, which destroys the upward compatiblity of your programs.

Well it's not an unexpected thing for programs to always be compatible as things change. Updates, hotfixes, etc. take care of such things.
Title: Re: Using the embedded icon handles in programs
Post by: Pete on March 04, 2021, 10:47:23 pm
I want that made into a carpet, for my game room.

Pete
Title: Re: Using the embedded icon handles in programs
Post by: George McGinn on March 20, 2021, 10:47:49 pm
Dav,

Ah, maybe a systems project I can work on, if I have spare time...

I do have code in TechBASIC on the iPad that will read a binary file, byte-by-byte, or bit-by-bit, and can create a new image file by name.

I also remember Rbytes has some BASIC programs that embed data into image files.

I will look into how QB64 handles reading and writing binary streams. It seems (theoretically possible) that a utility can be created that reads an image file and create DATA statements, that your code can then write out a temporary image file to use like a resource file, and then all the image statements in QB64 should work fine. When your program is done, just delete the temporary image file.

It seems simple, but so was my debacle with loading and printing FONTS in my programs!!!! (It's what happens when my mind is on some other problem)

Up for a challenge?


Yeah I agree with that.  I hope I'm still here 10 years down the road...

Edit: speaking of resources, it would be great to see QB64 one day have adding resource files capability. Declare a resource file, like an image, and have it included in the EXE.

- Dav
Title: Re: Using the embedded icon handles in programs
Post by: NOVARSEG on March 21, 2021, 03:48:04 am
next