Announcement

Collapse
No announcement yet.

Find and Replace Common Dialog Boxes Demonstration - Comments

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

  • Find and Replace Common Dialog Boxes Demonstration - Comments

    your comments and suggestions concerning the program in this link
    are most welcome here.
    http://www.powerbasic.com/support/pb...ad.php?t=24533

    i am sure you have suggestions for improvement.

    best regards,

    erik


    ------------------

  • #2
    FYI I have made a new version, DDT style without subclassing - version 3,
    quite handy.

    Best regards,

    Erik

    ------------------

    Comment


    • #3
      I have made further marked improvements to all 3 versions.

      P.S. At one stage I used ITERATE DO, but that made the program reactionless.
      After I replaced that statement with a GOTO statement, no further
      problem was found.

      Have others have had a similar experience with ITERATE DO?

      Best regards

      Erik
      ------------------




      [This message has been edited by Erik Christensen (edited March 30, 2005).]

      Comment


      • #4
        Small change: All flags are now remembered between calls.




        [This message has been edited by Erik Christensen (edited April 09, 2005).]

        Comment


        • #5
          Great job with this!

          I'm having a little trouble using it with a RTF textbox though. Each paragraph after the first one will cause the selection to be shifted by 2 characters.
          This little modification seems to fix it:
          Code:
          CONTROL GET TEXT hWnd, id TO txt ' text to search in
          REPLACE $LF WITH "" IN txt  '<-- fixes problem
          Also, when replacing text, all rich text formatting is lost because CONTROL SET TEXT is used instead of streaming.



          ------------------

          Comment


          • #6
            Yes, you are right. The technique described works for text boxes.
            The technique for getting and setting text in the Rich Edit Control
            should be done using the stream technique specific for that control.
            If I get the time, I may do such an example one day. Sorry for the
            delay in responding. I just returned from Paris from an international
            conference there. Great.

            Best regards,

            Erik

            ------------------

            Comment


            • #7
              Bud,

              Actually for the Rich Edit Control it may be much better to do the
              replace operation directly within the control using the %EM_REPLACESEL
              message. In that way you do not need repeat setting the whole
              text in the control, and there will be no problems with formatting
              being lost. The replace selection message works both in Edit and
              Rich Edit controls.

              Best regards,

              Erik


              ------------------

              Comment


              • #8
                Thanks, Erik. I'm using %EM_SETTEXTEX instead. This is what I came up with (it seems to work ok ):

                Code:
                FUNCTION RichEditDoFindReplaceAction(BYVAL lpfr AS FINDREPLACE PTR, BYVAL hDlg AS DWORD, BYVAL DlgItem AS LONG) AS LONG
                    STATIC ft      AS FINDTEXTEX
                    LOCAL  st      AS SETTEXTEX
                    LOCAL  result  AS LONG
                    STATIC newfind AS LONG
                
                ReplaceAll:
                
                    IF (@lpfr.Flags AND %FR_DIALOGTERM) THEN   'Find or replace dialog is closed
                        hFindReplaceDialog = %NULL
                        FUNCTION = 0 : EXIT FUNCTION
                    END IF
                
                    'save the flags for the next time:
                    SearchFlags = @lpfr.Flags
                
                    'get the position of the current selection:
                    CALL SendMessage(GetDlgItem(hDlg, DlgItem), %EM_EXGETSEL, 0, VARPTR(ft.chrg))
                
                    'if Replace or Replace All button was used, and there is a new find..
                    IF (@lpfr.Flags AND %FR_REPLACE) = %FR_REPLACE OR (@lpfr.Flags AND %FR_REPLACEALL) = %FR_REPLACEALL AND newfind THEN 'replace
                        RESET newfind   'allow only one replacement per find
                        st.flags    = %ST_KEEPUNDO OR %ST_SELECTION
                        st.codepage = %CP_ACP   'default (ANSI) code page
                        CALL SendMessage(GetDlgItem(hDlg, DlgItem), %EM_SETTEXTEX, VARPTR(st), @lpfr.lpstrReplaceWith)
                        'adjust the selected text range to match the new replacement text length:
                        ft.chrgText.cpMax = ft.chrgText.cpMin + LEN(@[email protected])
                        CALL SendMessage(GetDlgItem(hDlg, DlgItem), %EM_EXSETSEL, 0, VARPTR(ft.chrgText))
                    END IF
                
                    'put the text to search for into the FINDTEXTEX struct:
                    ft.lpstrText = @lpfr.lpstrFindWhat
                
                    'if the search direction is down, then the char range needs to be modified:
                    IF (@lpfr.Flags AND %FR_DOWN) = %FR_DOWN THEN
                        INCR ft.chrg.cpmin  'add one to the position of the last find, otherwise the position won't advance forward.
                        ft.chrg.cpmax = -1  'look to the end of the text
                    END IF
                
                    'perform the search operation:
                    CALL SendMessage(GetDlgItem(hDlg, DlgItem), %EM_FINDTEXTEX, @lpfr.Flags, VARPTR(ft)) TO result
                
                    IF result > -1 THEN 'the search str was found
                        CALL SendMessage(GetDlgItem(hDlg, DlgItem), %EM_EXSETSEL, 0, VARPTR(ft.chrgText))
                        newfind = 1 'keep track of the new find
                    ELSE
                        RESET newfind
                        MSGBOX "No matches found."
                    END IF
                
                    'if Replace All, then loop until all found text has been replaced:
                    IF (@lpfr.Flags AND %FR_REPLACEALL) = %FR_REPLACEALL AND newfind THEN GOTO ReplaceAll
                
                END FUNCTION
                ------------------

                Comment


                • #9
                  i made a new revised version to be used specifically in rich edit
                  controls - see this link:
                  http://www.powerbasic.com/support/pb...ad.php?t=24564

                  thanks for the inspiration.

                  best regards,

                  erik




                  ------------------

                  Comment

                  Working...
                  X