Announcement

Collapse
No announcement yet.

Ritchedit

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

  • Ritchedit

    If I compile this example from Borje Hagsten with PB8 the highlight of the textcolor works well.
    When I compile it with PB9 highlight of the text does not work.
    A bug in PB9?

    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Small RichEdit sample, showing how to create a Richedit control
    ' and mark all occurrences of searched text with a specific color.
    ' With some tweaking - the base for a color syntax editor?
    ' It even has drag&drop editing.. :-)
    ' By Borje Hagsten, released as Public Domain - April 24, 2000
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #Compile Exe
    #Dim All
    
    #Include "WIN32API.INC" 'Some include files
    #Include "COMMCTRL.INC"
    #Include "RICHEDIT.INC"
    
    %ID_RICHEDIT = 500
    
    Global hEdit As Long
    
    Declare CallBack Function DlgCallback()
    Declare Function MarkAll (ByVal myText As String) As Long
    Declare Function setRichTextColor( ByVal NewColor As Long) As Long
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
    Function PBMain
        Local hDlg As Long, hRichEd As Long, rText As String
    
        hRichEd = LoadLibrary("RICHED32.DLL")
        Call InitCommonControls
    
        Dialog New 0, "DDT RichEdit demo",,, 200, 138, %WS_SYSMENU To hDlg
        Control Add Button, hDlg, %IDOK, "&Mark", 140, 6, 50, 14
        Control Add Button, hDlg, %IDCANCEL, "E&xit", 140, 22, 50, 14
    
        Control Add "RichEdit", hDlg, %ID_RICHEDIT, "", 6, 6, 126, 110, _
                    %WS_CHILD Or %WS_VISIBLE Or %ES_MULTILINE Or %WS_VSCROLL Or _
                    %WS_HSCROLL Or %ES_AUTOVSCROLL Or %ES_WANTRETURN Or _
                    %ES_NOHIDESEL, %WS_EX_CLIENTEDGE
    
        Control Handle hDlg, %ID_RICHEDIT To hEdit
    
        rText = Repeat$(30, "Start and Stop") 'Create and set some text
        Call SendMessage(hEdit, %WM_SETTEXT, 0, StrPtr(rText))
        SetFocus hEdit
    
        Dialog Show Modal hDlg Call DlgCallback
    
    End Function
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' setRichTextColor sets the textcolor for selected text or
    ' text at the cursor's place in a Richedit control. Example:
    ' CALL setRichTextColor(&HFF) sets the color to red.
    ' &HFF0000 is blue, &H8000 is dark green, &H0 is black, etc..
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    Function setRichTextColor( ByVal NewColor As DWORD) As Long
      Local cf As CHARFORMAT2
    
      cf.cbSize = Len(cf) 'Length of structure
      cf.dwMask = %CFM_COLOR 'Set mask to colors only
      cf.crTextColor = NewColor 'Set the new color value
    
      Call SendMessage(hEdit, %EM_SETCHARFORMAT, %SCF_SELECTION, VarPtr(cf))
    
    End Function
    
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' This is a simple "find all" Function
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    Function MarkAll (ByVal myText As String) As Long
       Local AllText As String, tLen As Long, stopPos As Long
    
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       'Put Richedit's contents into a string
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       tLen = SendMessage(hEdit, %WM_GETTEXTLENGTH, 0, 0) + 1
       AllText = Space$(tLen)
       Call SendMessage(hEdit, %WM_GETTEXT, tLen, StrPtr(AllText))
    
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ' Turn off redraw to get faster and smoother action
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Call SendMessage(hEdit, %WM_SETREDRAW, 0, 0)
    
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ' Loop through string, pick out positions, select occurrences and then paint
       ' Note - Instr returns pos +1 in regards to Selstart, so we have to use -1
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       stopPos = InStr(AllText, myText)
       Do While stopPos
          Call SendMessage(hEdit, %EM_SETSEL, stopPos - 1, stopPos + Len(myText) - 1)
          Call setRichTextColor(&HFF) '&FF = red
          stopPos = InStr(stopPos + Len(myText) - 1, AllText, myText)
       Loop
       Call SendMessage(hEdit, %EM_SETSEL, 0, 0)
       SetFocus hEdit 'SetFocus to activate it after work is done, if you like..
    
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ' Turn on Redraw again and refresh
       '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       SendMessage hEdit, %WM_SETREDRAW, 1, 0 'Refresh and reset redraw
       InvalidateRect hEdit, ByVal %NULL, 0 : UpdateWindow hEdit
    
    End Function
    
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback procedure for all controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CallBack Function DlgCallback()
      If CbMsg = %WM_COMMAND Then
        Select Case CbCtl
          Case %IDOK
             Call MarkAll("Stop") ' "Stop", or any text you'd like to mark
    
          Case %IDCANCEL
            Dialog End CbHndl, (CbCtl = %IDOK)
    
        End Select
      End If
    End Function
    Last edited by Rudolf Fürstauer; 24 Oct 2008, 05:40 AM.
    ----------------
    Rudolf Fürstauer

  • #2
    suggest you replace some of those CALL sendmessage with lresult = sendmessage and TRACE the reults, will narrow down the point of failure.

    Comment


    • #3
      I gave it the quick run through, but does not highlight in 8 or 9 under Vista.
      Maybe I did something wrong, or the catch is the OS versioning?
      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


      • #4
        Originally posted by Cliff Nichols View Post
        ...catch is the OS versioning?
        On XP SP3, 8 works, 9 doesn't.

        Comment


        • #5
          Code:
          Local cf As CHARFORMAT
          (Not CHARFORMAT2 - that's for Rich Edit 2.0 and above)

          Doesn't explain why the 'wrong' code should work in PBWin8 but not Win90 though..?
          Last edited by Dave Biggs; 24 Oct 2008, 01:54 AM.
          Rgds, Dave

          Comment


          • #6
            I have found the errors in the presentation of the Richedit control.
            The bug is in PB9 that the UDT of CHARFORMAT2 is wrong

            The UDT of CHARFORMAT2 in PB9 is:

            Code:
            TYPE CHARFORMAT2 BYTE
              cbSize AS DWORD
              dwMask AS DWORD
              dwEffects AS DWORD
              yHeight AS LONG
              yOffset AS LONG                ' > 0 for superscript, < 0 for subscript
              crTextColor AS DWORD
              bCharSet AS BYTE
              bPitchAndFamily AS BYTE
              szFaceName AS ASCIIZ * %LF_FACESIZE
              wFiller AS WORD
              wWeight AS WORD                ' Font weight (LOGFONT value)
              sSpacing AS INTEGER              ' Amount to space between letters
              crBackColor AS DWORD           ' Background color
              lcid AS DWORD                  ' Locale ID
              dwReserved AS DWORD            ' Reserved. Must be 0
              sStyle AS INTEGER              ' Style handle
              wKerning AS WORD               ' Twip size above which to kern char pair
              bUnderlineType AS BYTE         ' Underline type
              bAnimation AS BYTE             ' Animated text like marching ants
              bRevAuthor AS BYTE             ' Revision author index
            END TYPE

            In the MSDN Library the UDT of CHARFORMAT2 in PB9 is:

            Code:
            typedef struct _charformat2 {
                UINT        cbSize;
                _WPAD       _wPad1;
                DWORD       dwMask;
                DWORD       dwEffects;
                LONG        yHeight;
                LONG        yOffset;
                COLORREF    crTextColor;
                BYTE        bCharSet;
                BYTE        bPitchAndFamily;
                WCHAR       szFaceName[LF_FACESIZE];
                _WPAD       _wPad2;
                WORD        wWeight;
                SHORT       sSpacing;
                COLORREF    crBackColor;
                LCID        lcid;
                DWORD       dwReserved;
                SHORT       sStyle;
                WORD        wKerning;
                BYTE        bUnderlineType;
                BYTE        bAnimation;
                BYTE        bRevAuthor;
                BYTE        bReserved1;
            } CHARFORMAT2;

            The last of Variable 'bRevAuthor AS BYTE' is missing!

            This error does not existin PB8, so does the example with PB8 works and with PB9 not.
            ----------------
            Rudolf Fürstauer

            Comment


            • #7
              The problem isn't so much in the compiler as with the .inc files released with PBWin9

              RichEdit.inc distributed with release of PBWin9:
              Dated in the header - ' Last Update: 07 November 2002
              Is missing the last member of the Charformat2 UDT

              The RichEdit.inc distributed with release of PBWin801:
              Dated in the header - ' Last Update: 24 February 2005
              Does have the last member of the Charformat2 UDT
              bReserved1 AS BYTE ' Reserved. Must be 0
              PBHave reverted to earlier versions of RichEdit.inc (and Win32API.inc) in the release of PBWin9.
              In the case of RichEdit.inc the only difference is that last member of CharFormat2 - missing from the current release !!

              BTW. Both versions of RichEdit.inc have the same definition of the Charformat UDT which is what Borje used with RichEdit version 1.0 (Riched32.dll) in the code he that posted here: http://www.powerbasic.com/support/pb...ad.php?t=22639
              Rgds, Dave

              Comment


              • #8
                Originally posted by Dave Biggs View Post
                PBHave reverted to earlier versions of RichEdit.inc (and Win32API.inc) in the release of PBWin9.
                Something similar happens here too: http://www.powerbasic.com/support/pb...ad.php?t=38859 see post #2

                (afterthought) time for a message to [email protected]?
                Last edited by Chris Holbrook; 28 Oct 2008, 12:14 AM.

                Comment

                Working...
                X