Announcement

Collapse
No announcement yet.

Richedit50W search & replace

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

  • Richedit50W search & replace

    I've been using search and replace code which worked fine with older versions of richedit but does not work with Richedit50W / Msftedit.dll, could anyone please point me at a working code sample, preferably PB or C? Thanks!

  • #2
    Seems to be a general problem

    substituting Richedit50W appears to cause the same problem elsewhere, too:

    Erik Christensen's code example http://www.powerbasic.com/support/pb...ad.php?t=11740 also doesn't "do" Richedit50W.

    The bit that is not working is the EM_FINDTEXT message. Changing it to EM_FINDTEXTEX (ANSI) and EM_FINDTEXTEXW (UNICODE, supplying a UNICODE searchstring) do not have the desired effect.

    The control seems to work OK with ANSI text, in fact EM_STREAMIN does not work with Unicode.

    Comment


    • #3
      I wonder if it something to do with the FINDTEXTEXW structure, mentioned in MSDN but not documented AFAIKT, and also not included in Richedit.inc. This is the structure used by EM_FINDTEXTEXW.

      The ANSI version would use an ASCIZ PTR but wouldn't the Unicode(W) version use a STRING PTR?

      Comment


      • #4
        The only difference is that FINDTEXTEXW defines lpstrText as a WORD PTR.

        Have you looked as Jose's includes?
        - LJ

        Comment


        • #5
          STRING PTR would be incorrect because it is a null terminated unicode string, not a dynamic string.

          Code:
          TYPE FINDTEXTEXW
             chrg      AS CHARRANGE    ' CHARRANGE chrg
             lpstrText AS WORD PTR     ' LPCWSTR   lpstrText
             chrgText  AS CHARRANGE    ' CHARRANGE chrgText
          END TYPE
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            Thank you José.

            Still does not work.

            There is very little out there about RichEDit50W/ Msftedit.dll.

            One comment I read (on the QuickMacros forum) was that:

            If you use EM_FINDTEXT, FINDTEXT lpstrText member must point to string that is in shared memory
            - guess what I'm trying now.

            Comment


            • #7
              Looking for Unicode? try using EM_FINDTEXTW
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Originally posted by Michael Mattias View Post
                Looking for Unicode? try using EM_FINDTEXTW
                Sorry, I forgot to use the big print when I said the same thing in post #2 above.

                Comment


                • #9
                  It appears that shared memory is unnecessary.

                  This compilable (PBWin 9) seems to work:

                  Code:
                  '
                  ' investigating how to use EM_FINDTEXTEW with RICHEDIT50W.
                  ' Chris Holbrook Aug 2008
                  '
                  #COMPILE EXE
                  #DIM ALL
                  
                  #INCLUDE "WIN32API.INC"
                  #INCLUDE "RICHEDIT.INC"
                  #INCLUDE "comdlg32.inc"
                  
                  %IDD_DIALOG1   =  101
                  %IDC_RICHEDIT1 = 1001
                  %IDC_TEXTBOX1  = 1002
                  %IDC_BUTTON1   = 1003
                  
                  '------------------------------------------------------------------
                  TYPE FINDTEXTEXW
                     chrg      AS CHARRANGE    ' CHARRANGE chrg
                     lpstrText AS WORD PTR     ' LPCWSTR   lpstrText
                     chrgText  AS CHARRANGE    ' CHARRANGE chrgText
                  END TYPE
                  '------------------------------------------------------------------
                  FUNCTION bFindTextInSelection(hRich AS DWORD, searchstr AS STRING ) AS LONG
                  
                      LOCAL ftex          AS FINDTEXTEXW
                      LOCAL lr, lr1       AS LONG
                      LOCAL s             AS STRING
                      LOCAL ps            AS ASCIZ PTR
                      '
                      s = UCODE$(searchstr)
                      ps = STRPTR(s)
                      ' set search range = whole buffer
                      ftex.chrg.cpMin = 0
                      ftex.chrg.cpMax = sendmessage (hrich, %EM_GETLIMITTEXT, 0, 0)
                      ftex.lpStrText = ps
                  
                      ? "searchstring='" + searchstr + "'" + $CRLF + _
                        "selection range" + STR$(ftex.chrg.cpMin) + STR$(ftex.chrg.cpMax) _
                        ,%MB_TASKMODAL
                  
                      lr = SendMessage(hRich, %EM_FINDTEXTEXW, %FR_DOWN, VARPTR(ftex))
                      IF lr <> -1 THEN
                          lr1 = SendMessage(hRich, %EM_EXSETSEL, 0, VARPTR(ftex.chrgText))
                          sendmessage hrich, %EM_HIDESELECTION, 0, 0
                          ? "found it!" : EXIT FUNCTION
                      END IF
                      FUNCTION = %FALSE
                      ? "text not found"
                  END FUNCTION
                  '------------------------------------------------------------------
                  
                  CALLBACK FUNCTION ShowDIALOG1Proc()
                      LOCAL s AS STRING
                      STATIC hRich        AS DWORD
                  
                      SELECT CASE AS LONG CBMSG
                          CASE %WM_INITDIALOG
                              hRich = getdlgitem(CBHNDL, %IDC_RICHEDIT1)
                              SendMessage hRich, %EM_FMTLINES, %TRUE, 0
                              SendMessage hRich, %EM_LIMITTEXT, 10000, 0
                  
                  
                          CASE %WM_COMMAND
                              SELECT CASE AS LONG CBCTL
                                  CASE %IDC_RICHEDIT1
                                  CASE %IDC_BUTTON1
                                      IF CBCTLMSG = %BN_CLICKED THEN
                                          CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX1 TO s
                                         ' s = UCODE$(s)
                                          bFindTextInSelection (hRich, s)
                                      END IF
                  
                                  CASE %IDC_TEXTBOX1
                  
                              END SELECT
                      END SELECT
                  END FUNCTION
                  '-----------------------------------------------------------------------------------------------------
                  FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                      LOCAL lRslt AS LONG
                      LOCAL hDlg  AS DWORD
                  
                      DIALOG NEW hParent, "Richtext find problem", 70, 70, 283, 129, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU 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 "RichEdit20A", hDlg, %IDC_RICHEDIT1, "", 10, 5, 270, 100, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP _
                      CONTROL ADD "RichEdit50W", hDlg, %IDC_RICHEDIT1, "", 10, 5, 270, 100, %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
                      CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "TextBox1", 10, 110, 125, 15
                      CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1, "Button1", 225, 110, 55, 15
                  
                      DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                  
                      FUNCTION = lRslt
                  END FUNCTION
                  '------------------------------------------------------------------
                  FUNCTION PBMAIN()
                      LOCAL hlib AS LONG
                  
                  '    hLib = LoadLibrary("RICHED20.dll")
                      hLib = LoadLibrary("msftedit.dll")
                  
                      ShowDIALOG1 %HWND_DESKTOP
                  
                      FreeLibrary hLib
                  END FUNCTION
                  Last edited by Chris Holbrook; 29 Aug 2008, 05:28 AM.

                  Comment


                  • #10
                    Stumbled across this while having the same problem with searching in a richedit50w control.

                    Playing with your code, Chris, I found that it doesn't make any difference whether the findtextex structure or the findtextexw structure is used as long as the search string is transformed to unicode before the search.

                    FFR, it might be wise to determine the version of the control before doing the search.

                    FWIW, if the control has the %ES_NOHIDESEL and %ES_SAVESEL styles a call with %EM_HIDESELECTION message is unnecessary.
                    Last edited by Walt Decker; 13 Feb 2009, 04:30 PM. Reason: make correction
                    Walt Decker

                    Comment


                    • #11
                      Thanks Walt!

                      Comment

                      Working...
                      X