Announcement

Collapse
No announcement yet.

RichEdit Reverse Search

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

  • RichEdit Reverse Search

    Annoyed, I am.

    In MSDN it tells you this ...

    When searching backward, cpMin must be equal to or greater than cpMax.
    So I do that and the search goes forward, not backward.

    Code:
    ft.chrg.cpmin = 500
    ft.chrg.cpmax = 0
    SendMessage(hRichEdit, %EM_FindTextEX, %FR_Down, VarPtr(ft))
    I fiddled with it unsuccessfully for way too long before running across another page (non-MS) that mentions an %FR value called %FR_FindNext, That equate was not mentioned on the MS page.

    With nothing to lose, I substitute the two %FR values and sure enough, it searches backwards.

    I still cannot find where MS documents the appropriate FR value to use for searching backwards.

  • #2
    Your friend Bill would have told you to look in FindReplaceA. Little wisted, agreed...

    Comment


    • #3
      Howdy, Pierre!

      Thanks for the suggestion. Yep, under normal circumstances that would work well. I've used it in a few of my applications and I like it!

      But in some of my other apps, which target users with poor eyesight, the small content of the dialog is too hard to read so I use a custom dialog for better control of the user interface.

      Comment


      • #4
        Hey Old Friend,

        Sorry, I was too brief, it wasn't really a suggestion to use FindReplace but more of a link where you can find an official MicroSoft FR_FindNext flag meaning.

        Comment


        • #5
          Pierre,
          Yes I misunderstood.

          After reading that page, which is mostly about a find and replace dialog box, I'm beginning to think I was just plain lucky that FR_FINDNEXT works as it does when using FindTextEX. There's no help content that I can find that clearly links the two.

          Comment


          • #6
            FR_FINDNEXT is here.
            Way back in 2002.

            Comment


            • #7
              @Gary,
              Aren't we polite or not ?!! :-)

              Life is good.

              Comment


              • #8
                Hey Jim!

                Thanks for that link. I don't see any clarification of what FR_FindNext does. I couldn't find it in the code, but I assume there a search direction flag that guides the action of FR_FINDNEXT?

                Comment


                • #9
                  Looking in 1996 Microsoft® Win32® Programmer's Reference and MSDN 2002,
                  I found no reference of a link between EM_FindTextEX message and the FR_FindNext flag.
                  I guess it could be categorized in "undocumented, but running forever good to have behavior".

                  Comment


                  • #10
                    Gary,

                    I don't have a simple version handy and copied this out of a complicated find/replace but it may be useful to you.
                    Code:
                              ' -----------------------------------------------
                              ' set the search flags based on the user options.
                              ' the direct numbers are used instead of the
                              ' equates to avoid including the bloat in the
                              ' common dialog include file.
                              ' -----------------------------------------------
                                If sch_direction <> 0 Then
                                  sOpt = 1          ' search backwards          %FR_DOWN      
                                Else
                                  sOpt = 0          ' search forward
                                End If
                    
                                If sch_matchcase <> 0 Then
                                  ! or sOpt, 4      ' case sensitive search     %FR_MATCHCASE 
                                End if
                    
                                If sch_wholeword <> 0 Then
                                  ! or sOpt, 2      ' only match whole word     %FR_WHOLEWORD
                                End If
                              ' -----------------------------------------------
                    
                                sLen1 = GetWindowText(Edit1,ByVal VarPtr(buffer1),128)
                    
                                If sLen1 = 0 Then
                                  Exit FUNCTION
                                End If
                    
                                SendMessage hEdit,%EM_EXGETSEL,0,ByVal VarPtr(cr)
                    
                                cr.cpMin = cr.cpMin + 1         ' increment up 1 character
                                                                ' from current selection
                                ftxt.chrg.cpMin = cr.cpMin
                                ftxt.chrg.cpMax = SendMessage(hEdit,%WM_GETTEXTLENGTH,0,0)
                                ftxt.lpstrText  = VarPtr(buffer1)
                    
                                tpos = SendMessage(hEdit,%EM_FINDTEXT,sOpt,ByVal VarPtr(ftxt))
                    
                                If tpos = -1 Then
                                  If Edit2 = 0 Then
                                    MessageBox hDlg,"No further matches found","Find Text",%MB_OK
                                    Exit FUNCTION
                                  Else
                                    MessageBox hDlg,"No further matches found","Replace Text",%MB_OK
                                    Exit FUNCTION
                                  End If
                                End If
                    
                              ' ----------------------------------------
                              ' set beginning and end of text to hilight
                              ' ----------------------------------------
                                cr.cpMin = tpos
                                cr.cpMax = tpos
                                cr.cpMax = cr.cpMax + sLen1
                    hutch at movsd dot com
                    The MASM Forum

                    www.masm32.com

                    Comment


                    • #11
                      Now...
                      While doing a "siesta" I thought "Bill usually do good job..." if there is no reference to FR_FindNext in EM_FINDTEXTEX it is probably because it is unnecessary. This deduction got me out of bed for trying.
                      In fact, not sure on how your code is done Gary but no need for FR_FindNext to go backward, as stated in the doc, omission of FR_DOWN will do. I hope you will forgive me to trust the old Bill so much.
                      Back to siesta...

                      Click image for larger version  Name:	EM_FINDTEXTEX.png Views:	0 Size:	15.2 KB ID:	778560

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      #INCLUDE "Win32Api.inc"
                      #INCLUDE "RichEdit.inc"
                      #INCLUDE "CommCtrl.inc"
                      #INCLUDE "ComDlg32.inc"
                      '#RESOURCE "x.pbr"
                      
                      GLOBAL hDlg AS DWORD
                      
                      %RichEdit01       = 101
                      %EditTextToSearch = 201
                      %ButtonSearchPrev = 301
                      %ButtonSearchNext = 302
                      
                      %FR_UP            = 0 'Only for clarity
                      '_____________________________________________________________________________
                      
                      FUNCTION SearchText(hRichEdit AS DWORD, BYVAL sTextToSearchFor AS STRING, dwFlag AS DWORD) AS LONG
                       LOCAL FindTextText AS FINDTEXTEX
                       LOCAL NextMatch    AS LONG
                       LOCAL SelStart     AS LONG
                       LOCAL SelEnd       AS LONG
                       LOCAL StartPos     AS LONG
                      
                       'EM_GETSEL get the starting and ending character positions of the current selection
                       StartPos = SendMessage(hRichEdit, %EM_GETSEL, VARPTR(SelStart), VARPTR(SelEnd))
                      
                       IF (dwFlag AND %FR_DOWN) THEN
                         'RE2+ Search is from the end of the current selection to the end of the document.
                         'else the search is from the end of the current selection to the beginning of the document.
                         'RE1: The FR_DOWN flag is ignored. The search is always from the end of the current selection to the end of the document.
                         FindTextText.chrg.cpMin = SelEnd + 1 'Search from current position
                         FindTextText.chrg.cpMax = -1         '- till the end
                       ELSE '%FR_UP
                         FindTextText.chrg.cpMin = SelStart   'Search from current position
                         FindTextText.chrg.cpMax = 0          '- up to the beginning
                       END IF
                      
                       sTextToSearchFor       = UCODE$(sTextToSearchFor) 'Depend on your compiler option, may be unneeded
                       FindTextText.lpStrText = STRPTR(sTextToSearchFor)
                      
                       NextMatch = SendMessage(hRichEdit, %EM_FINDTEXTEX, dwFlag, VARPTR(FindTextText)) 'Return next match position or -1 for no more
                       IF NextMatch <> -1 THEN
                         SendMessage(hRichEdit, %EM_SETSEL, FindTextText.chrgText.cpMin, FindTextText.chrgText.cpMax)
                       END IF
                      
                      END FUNCTION
                      '_____________________________________________________________________________
                      
                      CALLBACK FUNCTION ShowDIALOG1Proc()
                       LOCAL  sTextToSearchFor AS STRING
                       STATIC hRichEdit        AS DWORD
                      
                       SELECT CASE AS LONG CBMSG
                      
                         CASE %WM_INITDIALOG
                           hRichEdit = GetDlgItem(CBHNDL, %RichEdit01)
                      
                         CASE %WM_COMMAND
                           SELECT CASE AS LONG CBCTL
                      
                             CASE %ButtonSearchNext
                               IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                 CONTROL GET TEXT CBHNDL, %EditTextToSearch TO sTextToSearchFor
                                 SearchText(hRichEdit, sTextToSearchFor, %FR_DOWN)
                                 CONTROL SET FOCUS hDlg, %RichEdit01
                               END IF
                      
                             CASE %ButtonSearchPrev
                               IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                 CONTROL GET TEXT CBHNDL, %EditTextToSearch TO sTextToSearchFor
                                 SearchText(hRichEdit, sTextToSearchFor, %FR_UP)
                                 CONTROL SET FOCUS hDlg, %RichEdit01
                               END IF
                      
                           END SELECT
                      
                       END SELECT
                      
                      END FUNCTION
                      '_____________________________________________________________________________
                      
                      FUNCTION PBMAIN()
                       LOCAL hlib  AS DWORD
                       LOCAL hIcon AS DWORD
                      
                       DIALOG NEW %HWND_DESKTOP, "Richtext EM_FINDTEXTEX", , , 300, 115, _
                       %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, %WS_EX_LEFT TO hDlg
                      
                       hLib = LoadLibrary("MsFtEdit.dll")
                       CONTROL ADD "RichEdit50W", hDlg, %RichEdit01, _
                       REPEAT$(3 ,"Search for text, " & $CRLF & "previous or next to the caret." & $CRLF & $CRLF), _
                       5, 5, 290, 90, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_SAVESEL 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
                      
                       CONTROL ADD BUTTON, hDlg, %ButtonSearchPrev, "<", 50, 100, 25, 10
                      
                       CONTROL ADD TEXTBOX, hDlg, %EditTextToSearch, "previous", 85, 99, 125, 12
                      
                       CONTROL ADD BUTTON, hDlg, %ButtonSearchNext, ">", 215, 100, 25, 10
                      
                       hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 294) 'o
                       SetClassLong(hDlg, %GCL_HICON, hIcon)
                      
                       DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc
                      
                       FreeLibrary(hLib)
                       DestroyIcon(hIcon)
                      
                      END FUNCTION
                      '_____________________________________________________________________________
                      '
                      Last edited by Pierre Bellisle; 6 Feb 2019, 12:24 AM.

                      Comment


                      • #12
                        Steve
                        Your omission of FR_DOWN is by setting options to 0. It took me a moment to realize how that handled searching in the other direction. Help didn't exactly make it clear what the absence of FR_DOWN would do. It is funny that the default (0) searches backwards.

                        Pierre,
                        Yes, that makes sense. It is not FR_FINDNEXT that worked, rather, it was NOT having FR_DOWN. Good sleuthing. And, I was really lucky that how I coded it gave the desired result.

                        Comment


                        • #13
                          With a little work, the example above can be more versatile.
                          I will post when I have some spare time to clean the code...

                          Debug time...

                          Click image for larger version  Name:	EM_FINDTEXTEX2.png Views:	1 Size:	17.6 KB ID:	778567

                          Code:
                          #COMPILE EXE
                          #DIM ALL
                          #INCLUDE "Win32Api.inc"
                          #INCLUDE "RichEdit.inc"
                          #INCLUDE "ComDlg32.inc"
                          #INCLUDE "CommCtrl.inc"              'EM_SETCUEBANNER
                          #RESOURCE MANIFEST, 1, "xpTheme.xml" 'EM_SETCUEBANNER
                          '#RESOURCE "MyResource.pbr"          'EM_SETCUEBANNER
                          '%UNICODE = 1
                          
                          GLOBAL hDlg AS DWORD
                          
                          %RichEdit01          = 101
                          %EditTextToSearch    = 201
                          %ButtonSearchPrev    = 301
                          %ButtonSearchNext    = 302
                          %CheckBoxWrapAround  = 401
                          %CheckBoxCase        = 402
                          %CheckBoxWhole       = 403
                          %CheckBoxSeeAll      = 404
                          %CheckBoxFirstFind   = 405
                          %FR_UP               =   0 'For clarity only
                          
                           'The CHARRANGE structure specifies a range of characters in a rich edit control
                           'Range is empty if cpMin equal cpMax. Get full range cpMin as 0 and cpMax as - 1
                          
                           'TYPE CHARRANGE DWORD 'Size = 8 bytes
                           '  cpMin AS LONG 'LONG cpMin
                           '  cpMax AS LONG 'LONG cpMax
                           'END TYPE
                          
                          'TYPE FINDTEXTEX
                          '   chrg      AS CHARRANGE 'CHARRANGE chrg
                          '   lpstrText AS WORD PTR  'LPCWSTR   lpstrText
                          '   chrgText  AS CHARRANGE 'CHARRANGE chrgText
                          'END TYPE
                          '_____________________________________________________________________________
                          
                          'This code is direct descendant of Börje work, t'was a long time ago, and still remember, Thank Börje.
                          FUNCTION RichEditStringFoundColorSet(BYVAL hRichEdit AS DWORD, _
                                                               BYVAL sToFind AS STRING, BYVAL ColorFore AS DWORD, _
                                                               BYVAL ColorBack AS DWORD, BYVAL MatchCase AS LONG, _
                                                               BYVAL WholeWord AS LONG) AS LONG
                           LOCAL  FindTextStruct AS FINDTEXTEX
                           LOCAL  ChrFormat      AS CHARFORMAT2
                           LOCAL  ptUpperLeft    AS POINTAPI
                           LOCAL  zClass         AS ASCIIZ * 32 'Aka %MAX_CLASS_NAME_LEN
                           STATIC sToFindBack    AS STRING
                           STATIC MatchCaseSet   AS LONG
                           STATIC WholeWordSet   AS LONG
                           STATIC UnicodeFlag    AS LONG
                           STATIC fttDelta       AS LONG
                           LOCAL  CharPos        AS LONG
                           LOCAL  SelStart       AS LONG
                           LOCAL  SelEnd         AS LONG
                           LOCAL  dwFlag         AS DWORD
                          
                           'Backup selection and scrollbar position to put them back after coloring
                           SendMessage(hRichEdit, %EM_GETSEL, VARPTR(SelStart), VARPTR(SelEnd))
                           SendMessage(hRichEdit, %EM_GETSCROLLPOS, 0, VARPTR(ptUpperLeft))
                          
                           IF UnicodeFlag = %FALSE THEN 'One time check, use unicode with MsftEdit.dll
                             GetClassName(hRichEdit, zClass, SIZEOF(zClass))
                             IF zClass = "RICHEDIT50W" THEN
                               UnicodeFlag = 2 'Unicode flag to set some message the right way
                               fttDelta = %EM_FINDTEXTEXW - %EM_FINDTEXTEX
                             ELSE
                               UnicodeFlag = 1 'Older RichEdit version
                             END IF
                           END IF
                          
                           IF UnicodeFlag = 2 THEN
                             sToFind = UCODE$(sToFind) 'Search a unicode string in a unicode text
                           END IF
                          
                           ChrFormat.cbSize = SIZEOF(CHARFORMAT2) 'Use the ChrFormat structure for coloring spec
                           ChrFormat.dwMask = %CFM_COLOR OR %CFM_BACKCOLOR
                           IF LEN(sToFind) THEN 'Prepare for coloring text
                             ChrFormat.crTextColor = ColorFore
                             ChrFormat.crBackColor = ColorBack
                             MatchCaseSet          = MatchCase
                             WholeWordSet          = WholeWord
                             sToFindBack           = sToFind
                           ELSE 'Erase previous color if LEN(sToFind) = 0
                             ChrFormat.dwEffects = %CFE_AUTOCOLOR OR %CFE_AUTOBACKCOLOR 'Windows default color
                           END IF
                          
                           SendMessage(hRichEdit, %WM_SETREDRAW, 0, 0) 'Turn off redraw to get faster and smoother action
                          
                           FindTextStruct.lpstrText  = STRPTR(sToFindBack) 'Text to act on
                           FindTextStruct.chrg.cpMin =  0 'Start search position
                           FindTextStruct.chrg.cpMax = -1 'Search till the end
                          
                           'Set MatchCase and WholeWord
                           dwFlag = %FR_DOWN OR IIF(MatchCaseSet, %FR_MATCHCASE, 0) OR IIF(WholeWordSet, %FR_WHOLEWORD, 0)
                          
                           DO 'Find all text occurences
                             CharPos = SendMessage(hRichEdit, %EM_FINDTEXTEX + fttDelta, dwFlag, VARPTR(FindTextStruct)) 'Find text position
                             IF CharPos = -1 THEN EXIT LOOP 'Minus one if there are no subsequent matches
                             SendMessage(hRichEdit, %EM_SETSEL, CharPos, CharPos + LEN(sToFindBack) / UnicodeFlag) 'Select text
                             SendMessage(hRichEdit, %EM_SETCHARFORMAT, %SCF_SELECTION, VARPTR(ChrFormat)) 'Set color
                             FindTextStruct.chrg.cpMin = FindTextStruct.chrgText.cpMax 'Start next search after the current match
                           LOOP
                          
                           SendMessage(hRichEdit, %EM_SETSEL, SelStart, SelEnd) 'Put back previous caret position and text selection
                           SendMessage(hRichEdit, %EM_SETSCROLLPOS, 0, VARPTR(ptUpperLeft)) 'Go back to initial position in case the edit did an auto scroll
                           SendMessage(hRichEdit, %WM_SETREDRAW, 1, 0) 'Turn on redraw
                           InvalidateRect(hRichEdit, BYVAL %NULL, 0) : UpdateWindow(hRichEdit) 'Refresh
                           SetFocus(hRichEdit) 'Put back focus on edit control
                          
                          END FUNCTION
                          '_____________________________________________________________________________
                          
                          FUNCTION SearchText(hRichEdit AS DWORD, BYVAL sTextToSearchFor AS STRING, dwFlag AS DWORD) AS LONG
                           LOCAL  FindTextText         AS FINDTEXTEX
                           LOCAL  NextMatch            AS LONG
                           LOCAL  StartPos             AS LONG
                           LOCAL  SelStart             AS LONG
                           LOCAL  SelEnd               AS LONG
                           STATIC FirstFind            AS LONG
                           STATIC sLastTextToSearchFor AS STRING
                          
                           'An application sends an EM_GETSEL message to get the starting and ending character positions of the current selection in an edit control.
                           StartPos = SendMessage(hRichEdit, %EM_GETSEL, VARPTR(SelStart), VARPTR(SelEnd))
                           sTextToSearchFor = UCODE$(sTextToSearchFor) 'Sync with compiler unicode option
                          
                           dwFlag OR= IIF(IsDlgButtonChecked(hDlg, %CheckBoxWhole), %FR_WHOLEWORD, 0)
                           dwFlag OR= IIF(IsDlgButtonChecked(hDlg, %CheckBoxCase),  %FR_MATCHCASE, 0)
                          
                           IF (dwFlag AND %FR_DOWN) THEN
                             'RE2+ Search is from the end of the current selection to the end of the document.
                             'else the search is from the end of the current selection to the beginning of the document.
                             'RE1: The FR_DOWN flag is ignored. The search is always from the end of the current selection to the end of the document.
                             FindTextText.chrg.cpMin = SelEnd + 1 'Search from current position
                             FindTextText.chrg.cpMax = -1         '- till the end
                           ELSE '%FR_UP
                             FindTextText.chrg.cpMin = SelStart   'Search from current position
                             FindTextText.chrg.cpMax = 0          '- up to the start
                           END IF
                          
                           FindTextText.lpStrText = STRPTR(sTextToSearchFor)
                          
                           NextMatch = SendMessage(hRichEdit, %EM_FINDTEXTEX, dwFlag, VARPTR(FindTextText)) 'Return next match or -1 for no more
                          
                           IF NextMatch <> -1 THEN 'Found string
                             SendMessage(hRichEdit, %EM_SETSEL, FindTextText.chrgText.cpMin, FindTextText.chrgText.cpMax)
                           ELSE 'No string found, so, retry from the other end looping around code
                             IF IsDlgButtonChecked(hDlg, %CheckBoxWrapAround) THEN
                               IF (dwFlag AND %FR_DOWN) THEN
                                 FindTextText.chrg.cpMin = 0  'Search from the beginning
                                 FindTextText.chrg.cpMax = -1 '- till the end
                               ELSE '%FR_UP
                                 FindTextText.chrg.cpMin = SendMessage(hRichEdit, %WM_GETTEXTLENGTH, 0, 0) - 1  'Search from the end
                                 FindTextText.chrg.cpMax = 0                                                    '- up to the beginning
                               END IF
                               NextMatch = SendMessage(hRichEdit, %EM_FINDTEXTEX, dwFlag, VARPTR(FindTextText))
                               IF NextMatch <> -1 THEN
                                 SendMessage(hRichEdit, %EM_SETSEL, FindTextText.chrgText.cpMin, FindTextText.chrgText.cpMax)
                               END IF
                             END IF
                           END IF
                          
                           IF FindTextText.chrgText.cpMin = FirstFind THEN
                             IF IsDlgButtonChecked(hDlg, %CheckBoxFirstFind) THEN
                               WinBeep(1500, 80) 'Back to the FirstFind so beep
                             END IF
                           END IF
                           IF sLastTextToSearchFor <> sTextToSearchFor THEN 'Back to FirstFind beep code
                             FirstFind = FindTextText.chrgText.cpMin        'Back to FirstFind beep code
                           END IF                                           'Back to FirstFind beep code
                           sLastTextToSearchFor = sTextToSearchFor          'Back to FirstFind beep code
                          
                          END FUNCTION
                          '_____________________________________________________________________________
                          
                          FUNCTION GetSelText(hRichEdit AS DWORD) AS STRING
                           LOCAL  sSelection AS STRING
                           LOCAL  SelLen     AS LONG
                           LOCAL  SelStart   AS LONG
                           LOCAL  SelEnd     AS LONG
                          
                           SendMessage(hRichEdit, %EM_GETSEL, VARPTR(SelStart), VARPTR(SelEnd))
                           SelLen = SelEnd - SelStart
                           IF SelLen THEN
                             sSelection = NUL$(SelLen * 2)
                             SendMessage(hRichEdit, %EM_GETSELTEXT, 0, STRPTR(sSelection))
                           END IF
                           FUNCTION = sSelection
                          
                          END FUNCTION
                          '_____________________________________________________________________________
                          
                          CALLBACK FUNCTION MainProc()
                           LOCAL  sTextToSearchFor AS STRING
                           STATIC hRichEdit        AS DWORD
                          
                           SELECT CASE AS LONG CBMSG
                          
                             CASE %WM_INITDIALOG
                               hRichEdit = GetDlgItem(CBHNDL, %RichEdit01)
                          
                             CASE %WM_COMMAND
                               SELECT CASE AS LONG CBCTL
                          
                                 CASE %ButtonSearchNext, %ButtonSearchPrev
                                    IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                     CONTROL GET TEXT CBHNDL, %EditTextToSearch TO sTextToSearchFor
                                     IF LEN(sTextToSearchFor) = 0 THEN 'If search string edit control is empty then use selected text as input if any
                                       sTextToSearchFor = GetSelText(hRichEdit)
                                       sTextToSearchFor = ACODE$(sTextToSearchFor) 'Use depend on compiler unicode option
                                       CONTROL SET TEXT CBHNDL, %EditTextToSearch, sTextToSearchFor
                                     END IF
                                     SearchText(hRichEdit, sTextToSearchFor, IIF(CBCTL = %ButtonSearchNext, %FR_DOWN, %FR_UP))
                                     CONTROL SET FOCUS hDlg, %RichEdit01
                                   END IF
                          
                                 CASE %CheckBoxSeeAll
                                   IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                     CONTROL GET TEXT CBHNDL, %EditTextToSearch TO sTextToSearchFor
                                     IF IsDlgButtonChecked(hDlg, %CheckBoxSeeAll) THEN
                                       RichEditStringFoundColorSet(hRichEdit, sTextToSearchFor, %BLUE, %YELLOW, _
                                                                   IIF(IsDlgButtonChecked(hDlg, %CheckBoxCase), %FR_MATCHCASE, 0), _
                                                                   IIF(IsDlgButtonChecked(hDlg, %CheckBoxWhole), %FR_WHOLEWORD, 0))
                                     ELSE
                                       RichEditStringFoundColorSet(hRichEdit, "", 0, 0, 0, 0)
                                     END IF
                                     CONTROL SET FOCUS hDlg, %RichEdit01
                                   END IF
                          
                               END SELECT
                          
                           END SELECT
                          
                          END FUNCTION
                          '_____________________________________________________________________________
                          
                          FUNCTION PBMAIN()
                           LOCAL wsCueBanner AS STRING
                           LOCAL hlib        AS DWORD
                           LOCAL hIcon       AS DWORD
                          
                           DIALOG NEW %HWND_DESKTOP, "Richtext EM_FINDTEXTEX", , , 300, 130, _
                           %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, %WS_EX_LEFT TO hDlg
                          
                           hLib = LoadLibrary("MsFtEdit.dll")
                           CONTROL ADD "RichEdit50W", hDlg, %RichEdit01, _
                           REPEAT$(3 ,"Search for text, " & $CRLF & "previous or next to the caret." & $CRLF & $CRLF) & _
                           "If search control is empty, text selection will be used as input.", _
                           5, 5, 290, 90, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_SAVESEL OR %WS_VSCROLL OR %WS_HSCROLL OR _
                           %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOVSCROLL OR %ES_AUTOHSCROLL OR %ES_WANTRETURN OR %ES_NOHIDESEL, _
                           %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                          
                           CONTROL ADD BUTTON, hDlg, %ButtonSearchPrev, "<", 50, 99, 25, 12', %BS_VCENTER
                          
                           CONTROL ADD TEXTBOX, hDlg, %EditTextToSearch, "previous", 83, 99, 125, 12
                           wsCueBanner = UCODE$("Type text to search for...")
                           SendMessage(GetDlgItem(hDlg, %EditTextToSearch), %EM_SETCUEBANNER, 1, BYVAL STRPTR(wsCueBanner))
                          
                           CONTROL ADD BUTTON, hDlg, %ButtonSearchNext, ">", 214, 99, 25, 12', %BS_VCENTER
                          
                           CONTROL ADD CHECKBOX, hDlg, %CheckBoxWrapAround, "Wrap around", 10, 115, 55, 10
                          
                           CONTROL ADD CHECKBOX, hDlg, %CheckBoxFirstFind, "Beep on first-find hit", 78, 115, 75, 10
                          
                           CONTROL ADD CHECKBOX, hDlg, %CheckBoxCase, "Case", 166, 115, 30, 10 'FR_MATCHCASE
                          
                           CONTROL ADD CHECKBOX, hDlg, %CheckBoxWhole, "Whole", 208, 115, 35, 10 'FR_WHOLEWORD
                          
                           CONTROL ADD CHECKBOX, hDlg, %CheckBoxSeeAll, "See all", 253, 115, 75, 10
                          
                           hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 294) 'o
                           SetClassLong(hDlg, %GCL_HICON, hIcon)
                          
                           DIALOG SHOW MODAL hDlg, CALL MainProc
                          
                           FreeLibrary(hLib)
                           DestroyIcon(hIcon)
                          
                          END FUNCTION
                          '_____________________________________________________________________________
                          '

                          Last edited by Pierre Bellisle; 6 Feb 2019, 05:04 PM.

                          Comment


                          • #14
                            Gary,
                            Not to worry.
                            FR_DOWN is there too. Yes, they are search direction flags to react to. Note: Press … at the top right of the EDGE page. Select Find on page from the drop down. On the Find On Page bar type in what you want to find. Press enter. It is so much easier on the eyes.

                            MS Reference here


                            See also CommDlg.inc.

                            Comment

                            Working...
                            X