Announcement

Collapse
No announcement yet.

RichText as a Resource

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

  • RichText as a Resource

    I have been reading through posts regarding resources and note that .pbr is now not used and I should use #Resource.
    I would like to add a small file of Richtext as a resource and can't figure out how it can be done.
    Can anyone offer advice?
    Brian.

  • #2
    Store it as a STRING (if it's really short) or as RCDATA. For RCDATA, save the RichText to a file for the #RESOURCE statement.
    '
    Code:
    #COMPILE EXE
    #DIM ALL
    #RESOURCE RCDATA RT "my.txt"
    FUNCTION PBMAIN() AS LONG
        LOCAL strT AS STRING
        strT = RESOURCE$(RCDATA,"RT")
        ? strT
    END FUNCTION
    '
    This code shows retreving strings and RCDATA from a separate DLL, which is a bit trickier

    https://forum.powerbasic.com/forum/u...dll#post770081

    Comment


    • #3
      From #RESOURCE Help -
      The String resource contains string data which is always created and stored as Wide Unicode characters.
      Doesn't this limit it to RCDATA? Reading the resource would still be RESOURCE$.

      Cheers,
      Dale

      Comment


      • #4
        Originally posted by Dale Yarker View Post
        From #RESOURCE Help -
        > The String resource contains string data which is always created and stored as Wide Unicode characters.
        Doesn't this limit it to RCDATA? Reading the resource would still be RESOURCE$.

        Cheers,
        PB should convert it back to an ANSI string automagically if strT is declared as STRING.

        '
        Code:
        #COMPILE EXE
        #DIM ALL
        #DEBUG ERROR ON
        #DEBUG DISPLAY ON
        #RESOURCE STRING 2 "abcdefg"$   'ANSI string converted to WIDE when stored as resource
        #RESOURCE STRING 3 "hijklmnop"$$
        
        FUNCTION PBMAIN() AS LONG
            LOCAL s1,s2 AS STRING
            LOCAL ws1, ws2 AS WSTRING
            s1 = RESOURCE$(STRING,2)
            s2 = RESOURCE$(STRING,3)
            ? s1 & $LF & s2  ' ANSI strings
            ws1 = RESOURCE$(STRING,2)
            ws2 = RESOURCE$(STRING,3)
            ? ws1 & $LF & ws2   ' Wide strings
        END FUNCTION
        '

        Comment


        • #5
          Yes, but wastes half the bytes, and max characters (including control words) is down 63. (You did say really short. )
          Dale

          Comment


          • #6
            Originally posted by Dale Yarker View Post
            Yes, but wastes half the bytes, and max characters (including control words) is down 63. (You did say really short. )
            Nope, It's 127 characters, not 127 bytes
            '
            Code:
            #COMPILE EXE
            #DIM ALL
            #DEBUG ERROR ON
            #DEBUG DISPLAY ON
            #RESOURCE STRING 2 STRING$(127,65)   '127 character ANSI string
            #RESOURCE STRING 3 STRING$$(127,66)  '127 character (254 byte) wide string
            
            FUNCTION PBMAIN() AS LONG
                LOCAL s1,s2 AS STRING
                LOCAL ws1, ws2 AS WSTRING
                s1 = RESOURCE$(STRING,2)
                s2 = RESOURCE$(STRING,3)
               ?  STR$(LEN(s1)) & " " & s1 & $LF & STR$(LEN(s2)) & " " & s2
                ws1 = RESOURCE$(STRING,2)
                ws2 = RESOURCE$(STRING,3)
              ?  STR$(LEN(ws1)) & " " & ws1 & $LF & STR$(LEN(ws2)) & " " & ws2
            END FUNCTION
            '
            And here's how both the ANSI and WIDE strings are actually stored

            Click image for larger version  Name:	rcdata2.jpg Views:	0 Size:	164.3 KB ID:	803903

            Comment


            • #7
              Right, power fail here just as I realized my error.
              Dale

              Comment


              • #8
                Thank you, gentlemen, for your help. Unfortunately the Rich Text will be much greater than 127 characters. The header alone will be longer than that.
                Regards to all.
                Brian Reynolds.
                Brian.

                Comment


                • #9
                  Originally posted by Brian Reynolds View Post
                  Thank you, gentlemen, for your help. Unfortunately the Rich Text will be much greater than 127 characters. The header alone will be longer than that.
                  Regards to all.
                  Brian Reynolds.
                  The string stuff was really a bit of a digression.

                  In your case post #2 is the appropriate, simple solution. Just put strT into your control.

                  Comment


                  • #10
                    Simple demo:
                    '
                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    #INCLUDE ONCE "WIN32API.INC"
                    
                    #RESOURCE RCDATA RT "RichDemo.rtf"
                    
                    %IDC_RichEdit = 1001
                    
                    FUNCTION PBMAIN() AS LONG
                        LOCAL hDlg AS DWORD
                       LOCAL strRT AS STRING
                       strRT =  RESOURCE$(RCDATA, "RT")
                       DIALOG NEW 0, "RichEdit Resource",100,100,200,150,  %WS_POPUP OR %WS_BORDER _
                            OR %WS_DLGFRAME OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _
                            %DS_MODALFRAME, TO hDlg
                    
                       LoadLibrary("riched32.dll")
                       CONTROL ADD "RichEdit", hDlg, %IDC_RichEdit,"",10,10,180,130 , %WS_CHILD OR %WS_VISIBLE _
                           OR %ES_MULTILINE OR %WS_VSCROLL OR %ES_AUTOHSCROLL _
                           OR %WS_HSCROLL OR %ES_AUTOVSCROLL OR %ES_WANTRETURN OR %ES_NOHIDESEL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
                       CONTROL SEND hDlg, %IDC_RichEdit, %WM_SetText, 0, STRPTR(strRT)
                    
                       DIALOG SHOW MODAL hDlg
                    END FUNCTION
                    #IF 0
                    File: RichDemo.rtf
                    {\rtf1\ANSI\ansicpg1252\deff0\nouicompat\deflang3081{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
                    {\colortbl ;\red255\green0\blue0;}
                    {\*\generator Riched20 10.0.19041}\viewkind4\uc1
                    \pard\sa200\sl276\slmult1\f0\fs22\lang9 THIS \fs44 IS \cf1\b Rich TEXT\par
                    }
                    #ENDIF
                    '
                    Last edited by Stuart McLachlan; 15 Jan 2021, 01:46 AM.

                    Comment


                    • #11
                      I used richtext as a resource to hold info I display on 'about'' screens in a few of my apps. I either called them "RCDATA" or a used a User Defined Resource type:

                      User-defined Resource Demo Jan 26 2003

                      Not only do these look better than plain text, I had a "Print" routine I got here from Don Dickinson so my users could actually print out their licenses.

                      AFAIK user-defined resource types are NOT available using the PB #RESOURCE statements, but you can always ..

                      Code:
                      #RESOURCE RCDATA, license,  filename.rtf
                      PS UNSOLICTED ADVICE: Use Wordpad (r) rather than MS-Word(r) to create the RTF files. I have run into "issues" using Microsoft word to create richtext, but never using WordPad.


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

                      Comment


                      • #12
                        PS UNSOLICTED ADVICE: Use Wordpad (r) rather than MS-Word(r) to create the RTF files.
                        Oh yes indeed! I've been using Wordpad to for quite a while. It produces a much cleaner RTF file.
                        ... .... . ... . . ... ... .... . .. ... .... .. ... .... .. .... ..

                        n6jah @ yahoo.com

                        Comment

                        Working...
                        X