Author Topic: Using the embedded icon handles in programs  (Read 5025 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Using the embedded icon handles in programs
« 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.  

  [ You are not allowed to view this attachment ]  

FellippeHeitor

  • Guest
Re: Using the embedded icon handles in programs
« Reply #1 on: March 02, 2021, 11:52:31 am »
  [ You are not allowed to view this attachment ]  

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.

FellippeHeitor

  • Guest
Re: Using the embedded icon handles in programs
« Reply #2 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.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Using the embedded icon handles in programs
« Reply #3 on: March 02, 2021, 12:07:31 pm »
Never mind. I wrote up something and it isn't good
Shuwatch!

FellippeHeitor

  • Guest
Re: Using the embedded icon handles in programs
« Reply #4 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"

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Using the embedded icon handles in programs
« Reply #5 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
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Using the embedded icon handles in programs
« Reply #6 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.
« Last Edit: March 02, 2021, 01:22:03 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Using the embedded icon handles in programs
« Reply #7 on: March 02, 2021, 12:54:37 pm »
Hmm, interesting.   Thanks for the feedback.   

I will do some more experimenting!

- Dav

FellippeHeitor

  • Guest
Re: Using the embedded icon handles in programs
« Reply #8 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

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Using the embedded icon handles in programs
« Reply #9 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

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: Using the embedded icon handles in programs
« Reply #10 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
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Using the embedded icon handles in programs
« Reply #11 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Using the embedded icon handles in programs
« Reply #12 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
« Last Edit: March 03, 2021, 11:55:39 am by Dav »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Using the embedded icon handles in programs
« Reply #13 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.
Shuwatch!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Using the embedded icon handles in programs
« Reply #14 on: March 04, 2021, 10:47:23 pm »
I want that made into a carpet, for my game room.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/