Announcement

Collapse
No announcement yet.

Windowless Rich Edit using COM

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

  • Windowless Rich Edit using COM

    I haven't done much with COM programming, but I have a need to use a windowless Rich Edit Control in one of my programs. Has anyone attempted to do this with PB and can offer some guidance?
    Radue Software -Software 100% Developed with PowerBasic

  • #2
    Originally posted by Jeff Radue View Post
    windowless Rich Edit Control
    No, but I can offer a couple of links to anyone who like myself had no idea what one was:

    This section contains information about the programming elements used with windowless rich edit controls.


    How to use the windowless RichEdit control, one of Microsoft's less well-documented APIs.

    Comment


    • #3
      Thanks Chris, I will have to rifle through the C code and see if I can port to a PB format.
      Radue Software -Software 100% Developed with PowerBasic

      Comment


      • #4
        If all you need to do is being able to draw Richtext into any window DC (ie. another control), you don't have to resort to COM and a windowless RichEdit control.

        Simply create a normal RichEdit control and hide it (no WS_VISIBLE style).

        Now generate the RTF text into the richedit control.

        You can then use the EM_FORMATRANGE message (use SendMessage) to have the RichEdit control draw the rich text into any window DC you provide. It is similiar to drawing rich text on a printer, but it can be done on any window DC.

        I have done this and it does work.

        I can't provide any code, since the code is part of a proprietary product, but this should give a jump start into the right direction.

        Scan the forums for code for printing richtext from a richedit control to a printer. This should give you enough to work with to convert the code over to drawing on a window DC.

        Then you don't need any COM stuff at all.

        Likely the windowless richedit control in Windows, is doing exactly what I did via the API directly and using the EM_FORMATRANGE message. They just put it into a COM routine to make it easy for programmers who don't know how to do such things with the API.
        Chris Boss
        Computer Workshop
        Developer of "EZGUI"
        http://cwsof.com
        http://twitter.com/EZGUIProGuy

        Comment


        • #5
          A note about EM_FORMATRANGE:

          The RichEdit control is not only capable of printing its contents to a printer, via this message, but it can draw its contents to any window DC and even scale the text into a different size window. The ability to scale it is quite useful.

          Windowless RichEdit controls require richedit 2.0

          EM_FormatRange should work with richedit 1.0
          Last edited by Chris Boss; 20 Dec 2008, 04:28 PM.
          Chris Boss
          Computer Workshop
          Developer of "EZGUI"
          http://cwsof.com
          http://twitter.com/EZGUIProGuy

          Comment


          • #6
            Thanks Chris. That's an interesting approach. Once finished I will need to edit the text also, but that can be accomplished by using the hidden Richtext control also. I will give it a try.
            Radue Software -Software 100% Developed with PowerBasic

            Comment


            • #7
              Likely the windowless richedit control in Windows, is doing exactly what I did via the API directly
              and using the EM_FORMATRANGE message.
              Then it would not be a windowless control.

              They just put it into a COM routine to make it easy for programmers
              who don't know how to do such things with the API.
              Sorry, but that is not the reason why.

              If this truly a windowless control, you will need a container that supports the IOleInPlaceSiteWindowless
              interface and also performs housekeeping operations related to this type of control.
              Dominic Mitchell
              Phoenix Visual Designer
              http://www.phnxthunder.com

              Comment


              • #8
                The Windows API calls the control and Windowless control, but it has a COM interface and not an API interface.

                My approach simply avoids the need for the COM interface and it works fine and it uses a standard API approach.

                I added this feature to my GUI engine and it works very well. No messay COM and a simple call to a routine which prints the contents of a RichEdit control to any DC. The RichEdit control will even scale it for you.

                By using this technique, it was easy to create a print preview for a rich edit controls content (page by page).
                Chris Boss
                Computer Workshop
                Developer of "EZGUI"
                http://cwsof.com
                http://twitter.com/EZGUIProGuy

                Comment


                • #9
                  While RTF used for printing may sound fine it will introduce problems when the rtf contains images.
                  For example, an Excel embedded object will result in a WMF but bitmap based.
                  Whatever you do with DC's and settings and so on, the result is never 100%.
                  hellobasic

                  Comment


                  • #10
                    Chris, your approach should work fine for output. After examining the C code from the link above, it is clear the approaches are quite different however. I encourage you to download the sample code and examine it. Some of the thing you need to do in C will not be required in the PB interface because it handles some of the overhead for you. Still, it gives a good model for how someone could utilize an object class in PB.
                    I do like your creative use of the API though..
                    Radue Software -Software 100% Developed with PowerBasic

                    Comment


                    • #11
                      >but I have a need to use a windowless Rich Edit Control in one of my programs

                      You sure you need to use this particular techinque?

                      Maybe there is (gasp!) another way. Another way to do what, well, that remains a mystery.

                      Eg, if you have a need to manipulate RichText, MS-WORD has a COM interface which supports that. Or, maybe you don't really need "richtext" per se, maybe you need to manage text and images for printing on a printer.

                      Regardless, you should not get locked into a "how" you've never done without taking a look at other possible "hows" to accomplish your "what."
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Michael, believe it or not I have been exploring the possibilities for a while. I want to have rich text formatting features for generic text output I am using now. If you know of another way, please let me know. I am listening.
                        Radue Software -Software 100% Developed with PowerBasic

                        Comment


                        • #13
                          Some of the thing you need to do in C will not be required in the PB interface
                          because it handles some of the overhead for you
                          You will not be able to use PB9 COM syntax for this because of this tidbit from a news goup.
                          Beast is right. Microsoft screwed up when writing those interfaces.
                          They
                          do not use the stdcall calling convention. Instead, they use C++'s
                          default thiscall calling convention, which is just like stdcall except
                          that "this" gets passed in the ECX register instead of at the top of
                          the
                          stack.
                          You will have to use low-level COM and the inline assembler for this.
                          Dominic Mitchell
                          Phoenix Visual Designer
                          http://www.phnxthunder.com

                          Comment


                          • #14
                            want to have rich text formatting features for generic text output I am using now. If you know of another way, please let me know. I am listening.
                            DDT OK?

                            Screen:
                            GRAPHIC FONT
                            GRAPHIC PRINT
                            GRAPHIC BITMAP LOAD/RENDER (syntax?)
                            Printer:
                            XPRINT (same stuff mostly)

                            Or even... use a richtext control; I think those have most of the richtext features. Hide it if you want.
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Micheal, my goal is to have a control similar to a text box in MS office that can have different fonts/sizes/color on a per character basis. I have already written a routine to use standard SKD style DrawText and associated function. I can change font, color and size for an entire string, but it cannot format a paragraph with multiple fonts etc.

                              After looking to Chris Boss's approach a little more, you can specify a second DC in the FORMATRANGE for applying to a different device per MSDN (like a print preview). This may actually work pretty well.

                              Or even... use a richtext control; I think those have most of the richtext features. Hide it if you want.
                              Well that is the point of this discussion. The Richedit control works fine within its container. I want to have the Rich Text output on my DC and be able to print it along with a mixture of different API output. It seemed like the Windowless Rich Edit was a solution.
                              Radue Software -Software 100% Developed with PowerBasic

                              Comment


                              • #16
                                For screen display and printing, perhaps this QHTM - Small Win32 HTML control will suffice.

                                Comment


                                • #17
                                  I need to some more re-reading, but sounds suspiciously like one of my questions awhile back that I think Pierre was able to answer (at least the add images part).

                                  Is the core idea to have a display that can show output, but then add to the output displayed? (not on a button or anything, but just what looks, acts, walks, talks like a plain text box, when a richedit seems to be more like display as formatted rather than character by character or sentence by sentence????

                                  Possible answer (minus pictures) but I do this with a Serial Port that characters are formatted (according to what they are meant to do) and the display shows what I want inst stead of "Read-all" Show Later type. (or at least to the user thats what it appears as.....)

                                  I will see if I can dig up an example to show if what I am thinking is what you are asking??
                                  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


                                  • #18
                                    Great Cliff, although I am not exactly clear on what you said. I am trying to create a text box like you have in MS Office that allows character by character formatting with Rich Text features.

                                    Radue Software -Software 100% Developed with PowerBasic

                                    Comment


                                    • #19
                                      Well a picture is worth a thousand words, so here goes.
                                      (Still a work in progress but should give you the basic idea)

                                      RichEditDemo.bas
                                      Code:
                                      #PBFORMS CREATED V1.51
                                      '------------------------------------------------------------------------------
                                      ' The first line in this file is a PB/Forms metastatement.
                                      ' It should ALWAYS be the first line of the file. Other
                                      ' PB/Forms metastatements are placed at the beginning and
                                      ' end of "Named Blocks" of code that should be edited
                                      ' with PBForms only. Do not manually edit or delete these
                                      ' metastatements or PB/Forms will not be able to reread
                                      ' the file correctly.  See the PB/Forms documentation for
                                      ' more information.
                                      ' Named blocks begin like this:    #PBFORMS BEGIN ...
                                      ' Named blocks end like this:      #PBFORMS END ...
                                      ' Other PB/Forms metastatements such as:
                                      '     #PBFORMS DECLARATIONS
                                      ' are used by PB/Forms to insert additional code.
                                      ' Feel free to make changes anywhere else in the file.
                                      '------------------------------------------------------------------------------
                                      
                                      #COMPILE EXE
                                      #DIM ALL
                                      
                                      '------------------------------------------------------------------------------
                                      '   ** Includes **
                                      '------------------------------------------------------------------------------
                                      #PBFORMS BEGIN INCLUDES
                                      #IF NOT %DEF(%WINAPI)
                                          #INCLUDE "WIN32API.INC"
                                      #ENDIF
                                      #IF NOT %DEF(%RICHEDIT_INC)
                                          #INCLUDE "RICHEDIT.INC"
                                      #ENDIF
                                      #INCLUDE "PBForms.INC"
                                      #IF NOT %DEF(%STRINGASRICHTEXTFORMAT)
                                          #INCLUDE "STRINGASRICHTEXTFORMAT.INC"
                                      #ENDIF
                                      #PBFORMS END INCLUDES
                                      '------------------------------------------------------------------------------
                                      
                                      '------------------------------------------------------------------------------
                                      '   ** Constants **
                                      '------------------------------------------------------------------------------
                                      #PBFORMS BEGIN CONSTANTS
                                      %IDD_DIALOG1   =  101
                                      %IDC_RICHEDIT1 = 1001
                                      #PBFORMS END CONSTANTS
                                      '------------------------------------------------------------------------------
                                      
                                      '------------------------------------------------------------------------------
                                      '   ** Declarations **
                                      '------------------------------------------------------------------------------
                                      DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                                      DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                      #PBFORMS DECLARATIONS
                                      '------------------------------------------------------------------------------
                                      
                                      '------------------------------------------------------------------------------
                                      '   ** Main Application Entry Point **
                                      '------------------------------------------------------------------------------
                                      FUNCTION PBMAIN()
                                          PBFormsRichEdit ()      ' Load RichEdit
                                      
                                          ShowDIALOG1 %HWND_DESKTOP
                                      
                                          PBFormsRichEdit (%TRUE) ' Unload RichEdit
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      
                                      '------------------------------------------------------------------------------
                                      '   ** CallBacks **
                                      '------------------------------------------------------------------------------
                                      CALLBACK FUNCTION ShowDIALOG1Proc()
                                      
                                          SELECT CASE AS LONG CBMSG
                                              CASE %WM_INITDIALOG
                                                  ' Initialization handler
                                      
                                              CASE %WM_NCACTIVATE
                                                  STATIC hWndSaveFocus AS DWORD
                                                  IF ISFALSE CBWPARAM THEN
                                                      ' Save control focus
                                                      hWndSaveFocus = GetFocus()
                                                  ELSEIF hWndSaveFocus THEN
                                                      ' Restore control focus
                                                      SetFocus(hWndSaveFocus)
                                                      hWndSaveFocus = 0
                                                  END IF
                                      
                                              CASE %WM_COMMAND
                                                  ' Process control notifications
                                                  SELECT CASE AS LONG CBCTL
                                                      CASE %IDC_RICHEDIT1
                                      
                                                  END SELECT
                                          END SELECT
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      
                                      '------------------------------------------------------------------------------
                                      '   ** Dialogs **
                                      '------------------------------------------------------------------------------
                                      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                          LOCAL lRslt AS LONG
                                      
                                      #PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
                                          LOCAL hDlg  AS DWORD
                                      
                                          DIALOG NEW hParent, "Dialog1", 70, 70, 201, 121, %WS_POPUP OR %WS_BORDER _
                                              OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
                                              %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
                                              %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                                              %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
                                              %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                          CONTROL ADD PBFormsRichEdit(), hDlg, %IDC_RICHEDIT1, "RichEdit1", 5, 5, _
                                              190, 110, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_VSCROLL OR _
                                              %WS_HSCROLL OR %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOVSCROLL OR _
                                              %ES_AUTOHSCROLL OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT _
                                              OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                                      #PBFORMS END DIALOG
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "Courier", "Blue", 10, %TRUE, %FALSE, %FALSE, "Hello" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "TimesNewRoman", "Red", 12, %TRUE, %TRUE, %FALSE, "Hello" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "GEORGIA", "Green", 14, %TRUE, %TRUE, %TRUE, "Hello" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "", "", 14, %FALSE, %FALSE, %FALSE, $TAB + "Normal Text" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "GEORGIA", "Blue", 14, %FALSE, %FALSE, %FALSE, $TAB + "Goodbye" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "TimesNewRoman", "Red", 12, %FALSE, %TRUE, %FALSE, $TAB + "Goodbye" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "Courier", "Green", 10, %FALSE, %TRUE, %TRUE, $TAB + "Goodbye" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "", "", 14, %FALSE, %FALSE, %FALSE, "" + $CR)
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "", "", 14, %FALSE, %FALSE, %FALSE, "A")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "Courier", "Blue", 10, %TRUE, %FALSE, %FALSE, "B")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "TimesNewRoman", "Red", 10, %TRUE, %FALSE, %FALSE, "C")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "GEORGIA", "Green", 10, %TRUE, %FALSE, %FALSE, "D")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "", "", 12, %FALSE, %FALSE, %FALSE, $TAB + "1")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "Courier", "Green", 14, %TRUE, %FALSE, %FALSE, $TAB + "2")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "TimesNewRoman", "Red", 12, %TRUE, %FALSE, %FALSE, $TAB + "3")
                                           RichEditAddTextStreamIn(hDlg, %IDC_RICHEDIT1, "GEORGIA", "Blue", 10, %TRUE, %FALSE, %FALSE, $TAB + "4")
                                      
                                          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                                      
                                      #PBFORMS BEGIN CLEANUP %IDD_DIALOG1
                                      #PBFORMS END CLEANUP
                                      
                                          FUNCTION = lRslt
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      StringAsRichTextFormat.inc
                                      Code:
                                      #IF NOT %DEF(%STRINGASRICHTEXTFORMAT)
                                           %STRINGASRICHTEXTFORMAT = 1
                                           GLOBAL gPos AS LONG, gPtr AS LONG, gTxt AS STRING
                                      '*** SET TEXT
                                           DECLARE FUNCTION RichEditStreamInString (BYVAL dwCookie AS DWORD, BYVAL pbBuff AS BYTE PTR, _
                                                                       BYVAL cb AS LONG, pcb AS LONG) AS DWORD
                                           DECLARE FUNCTION RichEditAddTextStreamIn(HwndDialog AS LONG, HwndRichEdit AS LONG, FontType AS STRING, FontColor AS STRING, FontSize AS LONG, FontBold AS LONG, FontItalic AS LONG, FontUnderline AS LONG, TextToAdd AS STRING) AS LONG
                                      
                                           DECLARE FUNCTION RtfCommandsStart() AS STRING
                                           DECLARE FUNCTION RtfCommandsEnd() AS STRING
                                           DECLARE FUNCTION RtfCommandsEndOfLine() AS STRING
                                           DECLARE FUNCTION RtfReplaceCr(CommandString AS STRING) AS STRING
                                      '*** FONTS
                                           DECLARE FUNCTION RtfFontCourier() AS STRING
                                           DECLARE FUNCTION RtfFontTimesNewRoman() AS STRING
                                           DECLARE FUNCTION RtfFontAndale() AS STRING
                                           DECLARE FUNCTION RtfFontLucidia() AS STRING
                                           DECLARE FUNCTION RtfFontGeorgia() AS STRING
                                      '*** FONT TYPES
                                           DECLARE FUNCTION RtfFontBold() AS STRING
                                           DECLARE FUNCTION RtfFontUnBold() AS STRING
                                           DECLARE FUNCTION RtfFontItalic() AS STRING
                                           DECLARE FUNCTION RtfFontUnItalic() AS STRING
                                           DECLARE FUNCTION RtfFontUnderline() AS STRING
                                           DECLARE FUNCTION RtfFontUnUnderline() AS STRING
                                      '*** SIZES
                                           DECLARE FUNCTION RtfFontSize(SizeForFont AS LONG) AS STRING
                                      '*** COLORS
                                           DECLARE FUNCTION RtfFontMaroon() AS STRING
                                           DECLARE FUNCTION RtfFontGreen() AS STRING
                                           DECLARE FUNCTION RtfFontOlive() AS STRING
                                           DECLARE FUNCTION RtfFontNavy() AS STRING
                                           DECLARE FUNCTION RtfFontPurple() AS STRING
                                           DECLARE FUNCTION RtfFontTeal() AS STRING
                                           DECLARE FUNCTION RtfFontGrey() AS STRING
                                           DECLARE FUNCTION RtfFontSilver() AS STRING
                                           DECLARE FUNCTION RtfFontRed() AS STRING
                                           DECLARE FUNCTION RtfFontLime() AS STRING
                                           DECLARE FUNCTION RtfFontYellow() AS STRING
                                           DECLARE FUNCTION RtfFontBlue() AS STRING
                                           DECLARE FUNCTION RtfFontFuchsia() AS STRING
                                           DECLARE FUNCTION RtfFontAqua() AS STRING
                                           DECLARE FUNCTION RtfFontWhite() AS STRING
                                           DECLARE FUNCTION RtfFontBlack() AS STRING
                                      
                                           FUNCTION RtfCommandsStart() AS STRING
                                                LOCAL st$
                                      '*** Start RTF Header
                                                st$ = "{"   'Start Header
                                                st$ = st$ + "\rtf1"  'RTF version 1
                                                st$ = st$ + "\ansi" 'Ansi language
                                                st$ = st$ + "\ansicpg1252"  'No idea what this one is
                                                st$ = st$ + "\deff0"        'Default Font = Font 0
                                                st$ = st$ + "\deflang1033"  'Default Language = English
                                                st$ = st$ + "\deflangfe1033"    'Not sure but probably Default English
                                                st$ = st$ + $CRLF
                                      '*** Start Font Selections
                                                st$ = st$ + "{"     'Start Block
                                                st$ = st$ + "\fonttbl"     'Font Block
                                      '*** Courier New
                                                st$ = st$ + "{"
                                                st$ = st$ + "\f0"   'Font 0
                                                st$ = st$ + "\fmodern"
                                                st$ = st$ + "\fprq1"
                                                st$ = st$ + "\fcharset0 Courier New;"
                                                st$ = st$ + "}"
                                                st$ = st$ + $CRLF
                                      '*** Times New Roman
                                                st$ = st$ + "{
                                               st$ = st$ + "\f1"   'Font 1
                                               st$ = st$ + "\fnil
                                               st$ = st$ + "\fcharset0 Times New Roman;"
                                               st$ = st$ + "}"
                                               st$ = st$ + $CRLF
                                           '*** Andale
                                               st$ = st$ + "{
                                               st$ = st$ + "\f2"   'Font 2
                                               st$ = st$ + "\fmodern"
                                               st$ = st$ + "\fprq1"
                                               st$ = st$ + "\fcharset0 Andale Mono;"
                                               st$ = st$ + "}"
                                               st$ = st$ + $CRLF
                                           '*** Lucida
                                               st$ = st$ + "{
                                               st$ = st$ + "\f3"   'Font 3
                                               st$ = st$ + "\fmodern"
                                               st$ = st$ + "\fprq1"
                                               st$ = st$ + "\fcharset0 Lucida CONSOLE;
                                               st$ = st$ + "}"
                                               st$ = st$ + $CRLF
                                           '*** Georgia
                                               st$ = st$ + "{"
                                               st$ = st$ + "\f4"   'Font 4
                                               st$ = st$ + "\froman"
                                               st$ = st$ + "\fprq2\fcharset0 Georgia;"
                                               st$ = st$ + "}"
                                               st$ = st$ + "}"
                                           '*** End Font Block
                                               st$ = st$ + $CRLF
                                           '*** Start Color Block
                                               st$ = st$ + "{"
                                               st$ = st$ + "\colortbl "
                                               st$ = st$ + $CRLF
                                               st$ = st$ + ";\red128\green0\blue0"+ $CRLF      'MAROON Brownish Red
                                               st$ = st$ + ";\red0\green128\blue0"+ $CRLF      'TEAL Dark Green
                                               st$ = st$ + ";\red128\green128\blue0"+ $CRLF    'GREEN Cammo Green
                                               st$ = st$ + ";\red0\green0\blue128"+ $CRLF      'NAVY Dark Purple
                                               st$ = st$ + ";\red128\green0\blue128"+ $CRLF    'PURPLE Purple
                                               st$ = st$ + ";\red0\green128\blue128"+ $CRLF    'TEAL Swatch Green
                                               st$ = st$ + ";\red128\green128\blue128"+ $CRLF  'GREY Dark Grey
                                               st$ = st$ + ";\red192\green192\blue192"+ $CRLF  'SILVER Light Grey
                                               st$ = st$ + ";\red255\green0\blue0"+ $CRLF      'RED Bright Red
                                               st$ = st$ + ";\red0\green255\blue0"+ $CRLF      'LIME Bright Green
                                               st$ = st$ + ";\red255\green255\blue0"+ $CRLF    'YELLOW Bright Yellow
                                               st$ = st$ + ";\red0\green0\blue255"+ $CRLF      'BLUE Bright Blue
                                               st$ = st$ + ";\red255\green0\blue255"+ $CRLF    'PINK Bright Pink
                                               st$ = st$ + ";\red0\green255\blue255"+ $CRLF    'AQUA Blue Green
                                               st$ = st$ + ";\red255\green255\blue255"+ $CRLF  'WHITE White
                                               st$ = st$ + ";\red0\green0\blue0"+ $CRLF        'BLACK Black
                                               st$ = st$ + ";"
                                               st$ = st$ + "}"
                                           '*** End Color Block
                                               st$ = st$ + $CRLF
                                               st$ = st$ + "\cf1"      'Default Color 1
                                               st$ = st$ + "\f0"       'Default Font 0
                                               st$ = st$ + "\fs11 "    'Default Font Size 11
                                               st$ = st$ + $CRLF
                                           '*** Commands after this are part of this header until the end closing bracket found
                                               FUNCTION = st$
                                           END FUNCTION
                                      
                                           FUNCTION RtfCommandsEnd() AS STRING
                                               FUNCTION = "}"
                                           END FUNCTION
                                      
                                           FUNCTION RtfCommandsEndOfLine() AS STRING
                                               FUNCTION = "\line "
                                           END FUNCTION
                                      
                                           FUNCTION RtfReplaceCr(CommandString AS STRING) AS STRING
                                               REPLACE $CR WITH CHR$(174) IN CommandString
                                               FUNCTION = CommandString
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontCourier() AS STRING
                                               FUNCTION = "\f0"
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontTimesNewRoman() AS STRING
                                               FUNCTION = "\f1"
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontAndale() AS STRING
                                               FUNCTION = "\f2"
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontLucidia() AS STRING
                                               FUNCTION = "\f3"
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontGeorgia() AS STRING
                                               FUNCTION = "\f4"
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontBold() AS STRING
                                               FUNCTION = "\b "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontUnBold() AS STRING
                                               FUNCTION = "\b0 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontItalic() AS STRING
                                               FUNCTION = "\i "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontUnItalic() AS STRING
                                               FUNCTION = "\i0 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontUnderline() AS STRING
                                               FUNCTION = "\ul "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontUnUnderline() AS STRING
                                               FUNCTION = "\ul0 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontSize(SizeForFont AS LONG) AS STRING
                                               FUNCTION = "\fs" + TRIM$(STR$(SizeForFont*2)) + " "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontMaroon() AS STRING
                                               FUNCTION = "\cf1 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontGreen() AS STRING
                                               FUNCTION = "\cf2 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontOlive() AS STRING
                                               FUNCTION = "\cf3 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontNavy() AS STRING
                                               FUNCTION = "\cf4 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontPurple() AS STRING
                                               FUNCTION = "\cf5 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontTeal() AS STRING
                                               FUNCTION = "\cf6 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontGrey() AS STRING
                                               FUNCTION = "\cf7 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontSilver() AS STRING
                                               FUNCTION = "\cf8 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontRed() AS STRING
                                               FUNCTION = "\cf9 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontLime() AS STRING
                                               FUNCTION = "\cf10 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontYellow() AS STRING
                                               FUNCTION = "\cf11 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontBlue() AS STRING
                                               FUNCTION = "\cf12 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontFuchsia() AS STRING
                                               FUNCTION = "\cf13 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontAqua() AS STRING
                                               FUNCTION = "\cf14 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontWhite() AS STRING
                                               FUNCTION = "\cf15 "
                                           END FUNCTION
                                      
                                           FUNCTION RtfFontBlack() AS STRING
                                               FUNCTION = "\cf16 "
                                           END FUNCTION
                                      
                                           '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                                           ' Rich Edit stream in callback - for streaming in string contents
                                           '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                                           FUNCTION RichEditStreamInString (BYVAL dwCookie AS DWORD, BYVAL pbBuff AS BYTE PTR, _
                                                                            BYVAL cb AS LONG, pcb AS LONG) AS DWORD
                                               pcb = MIN&(cb, LEN(gTxt) - (gPos - 1)) 'number of bytes to copy
                                               IF pcb > 0 THEN 'copy block from global string directly into Richedit's buffer.
                                               CopyMemory pbBuff, (gPtr + gPos - 1), pcb 'could use POKE$ too, but this is a bit faster
                                               gPos = gPos + pcb 'incr pos for next callback position.
                                               ELSE
                                                   FUNCTION = %True    'Break the action
                                               END IF
                                           END FUNCTION
                                      
                                           FUNCTION RichEditSetText(HwndDialog AS LONG, HwndRichEdit AS LONG, TextToSet AS STRING) AS LONG
                                                CONTROL SET TEXT HwndDialog, HwndRichEdit, TextToSet
                                           END FUNCTION
                                      
                                           FUNCTION RichEditAddTextStreamIn(HwndDialog AS LONG, HwndRichEdit AS LONG, FontType AS STRING, FontColor AS STRING, FontSize AS LONG, FontBold AS LONG, FontItalic AS LONG, FontUnderline AS LONG, TextToAdd AS STRING) AS LONG
                                                STATIC CurrentText AS STRING
                                                LOCAL NewText AS STRING
                                                LOCAL NewFontType AS STRING
                                                LOCAL NewFontColor AS STRING
                                                LOCAL NewFontSize AS STRING
                                                LOCAL NewFontBold AS STRING
                                                LOCAL NewFontUnBold AS STRING
                                                LOCAL NewFontItalic AS STRING
                                                LOCAL NewFontUnItalic AS STRING
                                                LOCAL NewFontUnderline AS STRING
                                                LOCAL NewFontUnUnderline AS STRING
                                                LOCAL eStream AS EDITSTREAM
                                                LOCAL ret AS LONG
                                                REPLACE $CRLF WITH RtfCommandsEndOfLine IN TextToAdd
                                                REPLACE $CR WITH RtfCommandsEndOfLine IN TextToAdd
                                                REPLACE $LF WITH "" IN TextToAdd
                                      '          control get text HwndDialog, HwndRichEdit to CurrentText
                                                REPLACE RtfCommandsStart WITH "" IN CurrentText
                                                REPLACE RtfCommandsEnd WITH "" IN CurrentText
                                                SELECT CASE UCASE$(FontType)
                                                     CASE "COURIER"
                                                          NewFontType = RtfFontCourier()
                                                     CASE "TIMESNEWROMAN"
                                                          NewFontType = RtfFontTimesNewRoman()
                                                     CASE "ANDALE"
                                                          NewFontType = RtfFontAndale()
                                                     CASE "LUCIDIA"
                                                          NewFontType = RtfFontLucidia()
                                                     CASE "GEORGIA"
                                                          NewFontType = RtfFontGeorgia()
                                                END SELECT
                                                SELECT CASE UCASE$(FontColor)
                                                     CASE "BLUE"
                                                          NewFontColor = RtfFontBlue
                                                     CASE "RED"
                                                          NewFontColor = RtfFontRed
                                                     CASE "YELLOW"
                                                          NewFontColor = RtfFontYellow
                                                     CASE "AUQUA", "AQUA"    'In the case of typo's in code
                                                          NewFontColor = RtfFontAqua
                                                     CASE "GREEN"    'In the case of COSMOS issued command
                                                          NewFontColor = RtfFontGreen
                                                     CASE ELSE
                                                          NewFontColor = RtfFontBlack
                                                END SELECT
                                                NewFontSize = RtfFontSize(FontSize)
                                                SELECT CASE FontBold
                                                     CASE %FALSE
                                                          NewFontBold = ""
                                                          NewFontUnBold = ""
                                                     CASE %TRUE
                                                          NewFontBold = RtfFontBold
                                                          NewFontUnBold = RtfFontUnBold
                                                END SELECT
                                                SELECT CASE FontItalic
                                                     CASE %FALSE
                                                          NewFontItalic = ""
                                                          NewFontUnItalic = ""
                                                     CASE %TRUE
                                                          NewFontItalic = RtfFontItalic
                                                          NewFontUnItalic = RtfFontUnItalic
                                                END SELECT
                                                SELECT CASE FontUnderline
                                                     CASE %FALSE
                                                          NewFontUnderline = ""
                                                          NewFontUnUnderline = ""
                                                     CASE %TRUE
                                                          NewFontUnderline = RtfFontUnderline
                                                          NewFontUnUnderline = RtfFontUnUnderline
                                                END SELECT
                                                NewText = RtfCommandsStart + CurrentText + NewFontType + NewFontColor + NewFontSize + NewFontBold + NewFontItalic + NewFontUnderline + TextToAdd + NewFontUnBold + NewFontUnItalic + NewFontUnUnderline + RtfCommandsEnd
                                                CurrentText = NewText
                                                eStream.pfnCallback = CODEPTR(RichEditStreamInString) 'pointer to RichEdit callback procedure
                                                gPos = 1
                                                gTxt = NewText
                                                gPtr = STRPTR(gTxt)
                                                ret = SendMessage(GetDlgItem(HwndDialog, HwndRichEdit), %EM_STREAMIN, %SF_RTF, VARPTR(eStream)) 'stream in text
                                           END FUNCTION
                                      #ENDIF
                                      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


                                      • #20
                                        Thanks for your example Cliff. The problem I am having is not formatting RTF text, it is outputing the text to an alternate DC. Not just streaming it to a Rich Text control. In lieu of using the Windowless Rich Edit control, which is poorly documented, I think using Chris Boss's suggestion of manipulating the %EM_FORMATRANGE message may work.
                                        Radue Software -Software 100% Developed with PowerBasic

                                        Comment

                                        Working...
                                        X