No announcement yet.


  • Filter
  • Time
  • Show
Clear All
new posts


    I am having trouble understanding setting up %EM_FINDTEXT from the win32api.hlp file. Here is a snippet of the code I have at this point:

    Case %WM_COMMAND
      Select Case CbCtlMsg
        Case %CBN_SELCHANGE
          Local find    As FINDTEXTAPI
          Local item    As String
          Local number  As Long
          local result  as Long
          Local pfind   As Long Ptr
          ComboBox Get Text CbHndl,%IDC_BOOK To item
          find.chrg.cpmin = 0
          find.chrg.cpmax = -1
          find.lpstrText = StrPtr(item)
          pfind = VarPtr(find)
          Control Send hWndClient,%IDC_EDIT,%EM_FINDTEXT,0,@pfind To result
    What I am trying to do is select from a list of Book titles in the combo box and then find that title in the text. A msgbox statement tells me that the find.lpstrText is being initialized with the proper selection when I select it from the dropdown list. The hlp guide mentioned that chrg.cpmin = 0 and chrg.cpmax = -1 would set the range for the entire control and a pointer to the "find" UDT needs to be passed, so I am speculating there something else I have missed that needs to be setup first or have I setup something improperly. Checking result with a msgbox statement always returns 0 and it is supposed to, according to the hlp guide, return either the zero-based character position of the next match or -1 if no match was found. Also, the hlp guide mentioned two constants FT_MATCHCASE and FT_WHOLEWORD for flags with %EM_FINDTEXT but I did not find these in the include file. I would like to use the FT_WHOLEWORD constant and I also assume I would have to use %EM_SETSEL to actually move the caret to the starting point of the found text since my understanding from the hlp guide is that %EM_FINDTEXT only returns the starting and ending positions of the found text or am I misunderstanding this as well. The copyright year on the include file is 1997, is there a newer file or can you just tell me what the values are for these and I can just update the include file myself.

    Adam Ritchie

    [This message has been edited by Adam Ritchie (edited April 07, 2000).]

  • #2
    Ok, I decided to try a small little test sample to see if it was something else in my code causing me a problem:

    #Compile Exe
    #Include ""
    #Include ""
    %IDC_EDIT = 101
    %IDC_CBO  = 200
    Global ghWnd As Long
    Declare CallBack Function WndProc()
    Function PbMain() As Long
      Local hWnd As Long
      Local hLib As Long
      hLib = LoadLibrary("RICHED20.DLL")
      Dialog New %HWND_DESKTOP,"Test",,,251,250,%WS_OVERLAPPEDWINDOW To hWnd
      ghWnd = hWnd
      Control Add "RICHEDIT20A",hWnd,%IDC_EDIT, _
                               "This is the second book of Moses, called Exodus", _
                               0,0,250,200,%WS_CHILD Or %WS_VISIBLE Or _
                               %ES_MULTILINE Or %WS_VSCROLL Or _
                               %WS_HSCROLL Or %ES_AUTOHSCROLL Or %ES_AUTOVSCROLL _
                               Or %ES_NOHIDESEL
      Control Add ComboBox, hWnd,%IDC_CBO,,10,220,100,40
      ComboBox Add hWnd,%IDC_CBO,"Genesis"
      ComboBox Add hWnd,%IDC_CBO,"Exodus"
      Dialog Show Modal hWnd Call WndProc
      Function = 0
    End Function
    CallBack Function WndProc()
      Select Case CbMsg
        Case %WM_INITDIALOG
          Control Set Focus CbHndl,%IDC_EDIT
          Function = 0
        Case %WM_COMMAND
          Local find As FINDTEXTEX
          Local result As Long
          Local bookitem As String
          If CbCtlMsg = %cbn_selendok Then
            ComboBox Get Text ghWnd,%IDC_CBO To bookitem
            ' Fill FINDTEXTEX udt with info for search operation
            find.chrg.cpmin = 0
            find.chrg.cpmax = -1
            find.lpstrText = StrPtr(bookitem)
            ' Perform search
            Control Send ghWnd,%IDC_EDIT,%EM_FINDTEXTEX,0,VarPtr(find) To result
            MsgBox Str$(result) 'This always returns -1 meaning no match
            Control Send ghWnd,%IDC_EDIT,%EM_SETSEL,result,0
          End If
      End Select
    End Function
    Obviously their is something I am not understanding about setting up searches with rich edit controls. Of course, it always, as mentioned in previous post, returns 0 in the previously posted code snippet. Is there someone who can shed some light on the subject?




    • #3
      Ok, I have discovered the secrets to the universe - well actually to searching for text in a rich edit control. Not having the constants defined in the file made it difficult to find the right parameters values. I also had to use a setfocus call to show the cursor at the point where it found the text.

        Sendmessage GetEdit,%EM_FINDTEXTEX,1,VarPtr(find) To result
        Sendmessage GetEdit,%EM_SETSEL,result,result
        Setfocus GetEdit
      Now it works the way I want it to or least searching forward. I still would like to know what those constant definitions are, they are not defined in the include file or at least not in mine; it would make it easier to search forward, backwards, whole word, matchcase, etc., instead of having to "fish" around for the correct parameters.




      • #4
        I think you are looking for FR_WHOLEWORD not FT_
         #define FR_DOWN                         0x00000001
         #define FR_WHOLEWORD                    0x00000002
         #define FR_MATCHCASE                    0x00000004
         #define FR_FINDNEXT                     0x00000008
         #define FR_REPLACE                      0x00000010
         #define FR_REPLACEALL                   0x00000020
         #define FR_DIALOGTERM                   0x00000040
         #define FR_SHOWHELP                     0x00000080
         #define FR_ENABLEHOOK                   0x00000100
         #define FR_ENABLETEMPLATE               0x00000200
         #define FR_NOUPDOWN                     0x00000400
         #define FR_NOMATCHCASE                  0x00000800
         #define FR_NOWHOLEWORD                  0x00001000
         #define FR_ENABLETEMPLATEHANDLE         0x00002000
         #define FR_HIDEUPDOWN                   0x00004000
         #define FR_HIDEMATCHCASE                0x00008000
         #define FR_HIDEWHOLEWORD                0x00010000
         #define FR_MATCHDIAC                    0x20000000
         #define FR_MATCHKASHIDA                 0x40000000
         #define FR_MATCHALEFHAMZA               0x80000000
        mailto:[email protected][email protected]</A>

        mailto:[email protected][email protected]</A>


        • #5
          Thanks Fred, that's what I was looking for. The win32api.hlp file must either have typos or is just out-of-date. I looked again and it does have them down as FT_WHOLECASE and FT_MATCHCASE.

          Thanks again,



          • #6
            You may have an older set of .INC files... if the latest version on the ftp site does not have these as %FR_xxx in COMDLG32.INC then the zip file on the web site will be updated soon(ish) and it will contain these (and possibly other) changes.


            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            mailto:[email protected]