Announcement

Collapse
No announcement yet.

icons in resource file (the misery of)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • icons in resource file (the misery of)

    Resource files. Ugh.

    Why on earth can't this be simpler to do?

    How hard would it be to write an application which maintained a list of icons in a resource file?

    Why doesn't PB Forms do it?

  • #2
    Most programmers think it's just a simple thing to add an icon to an application.
    Windows is much more complicated than that.

    In general, each icon should be a collection of icons.
    One ico file contains more than one of the same icon but for different resolutions.
    *Windows* picks the icon which 'best fit' from that list.
    Only with (severe) circumvention you can load an icon with index #3 for example.

    This is the main purpose of including icons in applications.
    Nearly all static stuff is meant to be a resource, this is how Windows works.

    Since Windows 95 it is possible to update resources.
    Which imo is uncommon.
    hellobasic

    Comment


    • #3
      How hard would it be to write an application which maintained a list of icons in a resource file
      Well, I am reluctant to quantify it but program resources are maintainable once the executable (EXE or DLL) has been compiled. See the BeginUpdateResource, UpdateResource and EndUpdateResource WinAPI functions.
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        BeginUpdateResource, UpdateResource and EndUpdateResource
        Thanks, a search on those was helpful.

        Comment


        • #5
          FWIW, if you want to do the UpdateResource stuff on Win/9x, it is supported via the Microsoft Layer For Unicode.

          This is the way I serialize my shelfware products. I encrypt the serial number in a program resource; to create an individually-serialized version, I don't recompile the program, I just insert a fresh resource.

          It's also the way I handle updates... everybody on maintenance can download an common update program (built with Inno Setup). During that update the script finds the installed executable, grabs the user's serial number, and updates the 'generic' new executable. Voila! the user's updated executables have the same serial number.

          Using MSLU demo: PB/CC: IsTextUnicode with Microsoft Unicode Layer for Win95/98/ME April 11, 2002
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Originally posted by Michael Mattias View Post
            This is the way I serialize my shelfware products. ...It's also the way I handle updates...
            Excellent trick. When I have overcome my resource-aversion I may copy it.

            Comment


            • #7
              An island of sanity in this sea of resource madness - the sunny isle of Binbas, owned by one Edwin Knoppert.

              Using the Binbas utility, which can be downloaded from Edwin's PwrDev site's downloads section, icon files can be translated into DATA statements, which can be embedded in the application and used to recreate the icon, using the method described here: http://www.powerbasic.com/support/pbforums/showthread.php?t=22930&highlight=binbas+icon+semen

              Comment


              • #8
                >sea of resource madness

                It's not madness at all... using DATA statements requires the program be recompiled to change the resource.

                Using direct resource update, recompilation is not necessary... i.e, it can be done "in the field" without selling the user a PB compiler license.

                MCM
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Originally posted by Michael Mattias View Post
                  Using direct resource update, recompilation is not necessary... i.e, it can be done "in the field"
                  No doubt, but for my current requirement it means that I don't have to use a resource in order to load icons, as per subject of thread.

                  Example posted to Source Code Forum., also DBtree application posted to Source Code Forum to show another benefit of this technique!
                  Last edited by Chris Holbrook; 20 May 2008, 04:25 AM. Reason: add links to Source Code Forum

                  Comment


                  • #10
                    Well, one ALWAYS has the option to supply the resource (be it an icon, dialog, program data or anything else) as a disk file and load what you need from that.

                    I was just trying to show that you can change the appearance or behavior of your program without recompiling anything, be it compiling a resource or compiling an executable, and do so without the need to supply extra files to the user.

                    I find the 'update program resource' technique useful precisely because of that.
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Originally posted by Michael Mattias View Post
                      ... you can change the appearance or behavior of your program without recompiling anything, be it compiling a resource or compiling an executable, and do so without the need to supply extra files to the user.
                      Yes. Apparently you can also do that by modifying the .exe, for example by changing the contents of a string literal, again avoiding the dreaded resource. I'm sure that you will come up with something that I can't do without resources in the end though!

                      Comment


                      • #12
                        > avoiding the dreaded resource.

                        The "dreaded" resource?

                        Real Men Ain't Afraid of No Stinkin' Resources!
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Real Men Ain't Afraid of No Stinkin' Resources!
                          Bingo, Bango, Bongo.....

                          Using this route, I have no need for stinkin' setup programs, registry issues or otherwise.... (although I will admit it took a lot to figure out, and some of the well written programs here in PB could do the setup better in some areas"

                          I have avoided "UpdateResource", but only because of time to research (which I REALLY have to look into. (Especially if it means I can customize an app, that way the changes stay with that app and do not have to recompile a new version for "Just One Person")

                          Unfortunately the only links I have found all lead to broken links, so I can not even begin to investigate without the original dll or file.

                          What I would like to see is something as simple as a common icon, or even better yet, a *.ini file, update on close, "UpdateResource" type of example...but unfortunately I have not found one to date
                          Engineer's Motto: If it aint broke take it apart and fix it

                          "If at 1st you don't succeed... call it version 1.0"

                          "Half of Programming is coding"....."The other 90% is DEBUGGING"

                          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                          Comment


                          • #14
                            Icons as type ICON resources (or BITMAP, or DIALOG/DIALOGEX) are a little more difficult to update in situ with Updateresource, since the new data must be passed in the resource form for that particular resource.

                            What you might consider for that is just storing an *.ICO or *.BMP file as a user-defined resource or RCDATA, specifying the filename...
                            Code:
                            MYICON     RCDATA     filename.ico
                            .. and extracting the data at runtime to a "*.ico" file, and doing your loadimage from that file.

                            Let me see if I can dream up a simple demo of updating either a user-defined or RCDATA resource and posting it for you. (You know I will need to create TWO programs for that demo, one to do the update and a second to prove it works)

                            MCM
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              MCM...in this case I think a simple example of
                              1. Run program
                              2. Close program
                              3. Something changed, so update the resource


                              In this case you are right, would probably take 2 copies to example, but if "Oh WOW" possible to just do the above...(with a common "Here is what changed") would probably settle everything in my mind

                              (probably raise more questions than answers, but hey that is the point in learning isn't it?)
                              Engineer's Motto: If it aint broke take it apart and fix it

                              "If at 1st you don't succeed... call it version 1.0"

                              "Half of Programming is coding"....."The other 90% is DEBUGGING"

                              "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                              Comment


                              • #16
                                Originally posted by Cliff Nichols View Post
                                MCM...in this case I think a simple example of
                                1. Close program
                                2. Something changed, so update the resource
                                Attempting to modify the executable while the program is running gets you an ERROR 70: Permission denied. Quite right too. However, there is nothing to stop the program from reading itself, modifying the info therein, and writing the result back to another file. This is no challenge, except to correctly and unambiguously identify the string to be replaced.

                                The trick is then to replace the program with that other file, easy if it is always started via a shortcut, script of batch file. Maybe the program could spawn a process which does this, it would have to be an orphaned process though, else the main program would wait for it, this could be done using the SHELL statement.

                                However, any such method would leave the unmodified executable in an executable state until it was overwritten or deleted. Maybe there is a clever way around that.

                                Comment


                                • #17
                                  Well, if you REALLY want to change a program resource whilst the program is running...

                                  You can store that resource in and obtain it at execution time from a separate module. - a 'resource-only' Dynamic Link Library.

                                  For example, here's the complete source code to a priced add-on to one of my products:

                                  Code:
                                  ' FILE: TSPK810S.BAS
                                  ' =======================================================================
                                  '       810S Kit for Pointman EDI Interface File Viewer.
                                  '       This is a "resource only" DLL
                                  ' =======================================================================
                                  '  06/05/06   1.0.0   Initial Creation
                                  '  09/11/06   1.0.1   Add updated description of R/T H021
                                  #COMPILE  DLL
                                  #REGISTER NONE
                                  #TOOLS    OFF
                                  #DEBUG    ERROR ON
                                  #RESOURCE "TSPK810S.PBR"
                                  
                                  ' COMPILER CREATES DEFAULT ENTRY POINT FUNCTION.
                                  
                                  ' *** END OF FILE  tspk810SR ***
                                  Michael Mattias
                                  Tal Systems Inc. (retired)
                                  Racine WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment

                                  Working...
                                  X