Announcement

Collapse
No announcement yet.

Resource file question

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

  • Resource file question

    I have a standard Resource file for all the programs in our package. I now have a bitmap for a custom program for one customer only that I don't want to store on disk but also don't want to put in the package wide resource file. If I start with the generic resource file, I'm sure I can add this bitmap but then I'll have to keep track of it forever as a stepchild of the generic one.

    Question. Is it possible to have a second resource file in a PB program. If not, what other way besides binbas is there to store it protected in the exe and call it out as necessary as you would a bitmap from a resource file.

    Thanks,

    Bob Mechler

  • #2
    I see in the doc where you must limit to one PBR per module but that a second resource file can be in a dll. Does this allow it to be called the same was as if it was in the original exe?

    Bob Mechler

    Comment


    • #3
      Depends on HOW you are loading the bitmap resource.

      Using DDT syntax (GRAPHIC BITMAP LOAD), no you can't load from a module resource other than current module.

      Using WinAPI syntax (LoadImage()), you can load from any module to which you have obtained a handle.

      Of course, were you to store that BMP file in a resource as a "raw" resource....
      Code:
      100  CUSTOMER   "customer_bmp_file.bmp"
      Then, if you found that DLL file in a designated folder, and that DLL contains the desired resource, you could extract that data, save it to a *.BMP" file and then use GRAPHIC BITMAP LOAD "filename" in your program.

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

      Comment


      • #4
        A standard resource file bitmap that appears on certain screens I'm loading this way from the package wide resource file
        Code:
        %WM_INITDIALOG
        ...
                    hBmp = LoadImage(GetModuleHandle(""), "#1028", %IMAGE_BITMAP, x, y, %LR_DEFAULTCOLOR)
        ...
        %WM_ERASEBKGND
                  ' Select the bitmap into a memory DC and transfer it to the dialog
                  hBmpDC = CreateCompatibleDC(CBWPARAM)
                  SelectObject hBmpDC, hBmp
                  BitBlt CBWPARAM, 0, 0, x, y, hBmpDC, 0, 0, %SRCCOPY
                  DeleteDC hBmpDC
        I'm guessing the GetModuleHandle("") part would need to be replaced by the handle to the DLL, am I correct? That is to get a bitmap from a custom dll.

        Bob Mechler

        Comment


        • #5
          See your WinAPI doc for the 'hInstance' parameter of LoadImage() for the answer.
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Ok, I've got success using a second resource file in a DLL. I basically just grabbed the module handle of the DLL by returning it from a function in the DLL and then used it to load the image into the object reference in the exe. As a test I used SRCCOPY and bitblt to make it the dialog background.

            Now since I'm using ddoc as the print engine I want to temp save it to disk as a bitmap, use it and delete it when the program finishes placing the bitmap on the printed output. Ddoc's command to Add a Graphic takes a file. I know it's a round-about way but I don't want to leave the bmp as a file for security purposes.

            How do a I do a Load Image and then use the object reference to write the bitmap to a disk file so Ddoc can load and then immediately delete it.

            I know it sounds crazy but the bmp is a signature.

            Bob Mechler

            Comment


            • #7
              basically just grabbed the module handle of the DLL by returning it from a function in the DLL
              Don't look for GetModuleHandle() in your doc, it will depress you to know you didn't need to EXPORT a function with that handle.

              I also have done a lot of stuff with ddoc images. Since I never could master saving a BITMAP resource to disk as a BMP file, I used the technique I described above: saving the entire BMP file as a user-defined resource, extracting to a temp file, and doing all image loads from that temp disk file.

              Extraction is easy.. see the ResourceAsString function in the demo at User-Defined Resource Demo January 26 2003
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Here is my .rc
                chksig BITMAP SPNGSIG.BMP

                I can't tell from your example what goes where. I don't know didly squat how to use your example because I barely know how to set up a resource file like you did. My failing.

                I'm assuming the w$ can be saved as a binary file with a *.bmp extention and work.

                Thanks,

                Bob Mechler

                Comment


                • #9
                  >I'm assuming the w$ can be saved as a binary file with a *.bmp extention and work.

                  NOt when it's a BITMAP resource.

                  You'd need to use an RCDATA or USER-DEFINED resource
                  Code:
                  // filename.rc
                  chksig   MYBITMAP Spngsig.BMP
                  Get and load and use...
                  Code:
                    W$ = ResourceAsSTRING ( filename, type, name) [ or whatever those options are] 
                    hFile = FREEFILE 
                    OPEN "tempfile.bmp" for BINARY AS hFile
                    PUT$ hFile, W$
                    CLOSE hFile 
                  
                     hBmp = LoadImage ( "tempfile.bmp"  [other options]) 
                     yadda yadda yadda
                    ...
                     KILL "tempfile.bmp"    ' be nice by cleaning up.
                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    The bitmap saved is 12 bytes shorter in length than the one used to create the resource and if I click it, it says no preview available. Reading other posts, it might need some header information.

                    BITMAPFILEHEADER and BITMAPINFOHEADER is what I'm seeing. I'll fill in that information and pre-pend it to the raw bitmap stuff and see if I get a valid bitmap.

                    Thanks,

                    Bob Mechler

                    Comment


                    • #11
                      Using PB 8 it became a simple matter, but I need some feedback on whether I'm doing everything I need to.

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      #RESOURCE "SPNGSIG.PBR"
                      FUNCTION PBMAIN () AS LONG
                        DIM nFile&,nWidth&,nHeight&,hBmp???,x&,y&,hWin???
                        nFile& = FREEFILE
                        OPEN "SPNGSIG.BMP" FOR BINARY AS nFile& 'This information can be hardcoded for the custom program
                          GET #nFile&, 19, nWidth&
                         GET #nFile&, 23, nHeight&
                        CLOSE nFile&
                        GRAPHIC WINDOW "sig", 0,0,0,0 TO hWin??? 'so it won't show
                        GRAPHIC BITMAP LOAD "chksig", nWidth&, nHeight& TO hBmp??? 'chksig is the resource identifier
                        ' I found I could also just divide the width and height parameters by 2 or 3 to get a smaller version or change them to whatever I need that's reasonable.
                        GRAPHIC ATTACH hBmp???,hWin???
                        GRAPHIC SAVE "oSPNGSIG.BMP"
                        GRAPHIC BITMAP END
                      END FUNCTION
                      It produces an identical bitmap file when saved. Once it's attached to the ddoc document, I then immediately delete it.

                      Bob Mechler
                      Last edited by BOB MECHLER; 23 May 2008, 10:11 AM. Reason: typo's

                      Comment

                      Working...
                      X