🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8979

Search toward the beginning with richedit control

#8979
From: Gary Setter
Date: Thu, 26 Aug 2004 14:23
69 lines
2880 bytes
Hi,

I have a richedit control. I want to support searching toward the beginning
of the text. My Find command works fine when I search toward the end of
text, but I always fail when I search toward the beginning. The RichEdit
control version is 3.0.

I'm using the common Find dialog. The following is my function in response
to the registered FINDMSGSTRING message. Can someone tell me what I need to
do?

/*
 Do the find operation.
*/
bool FrameCls::DoFind(FINDREPLACE *info)
{
  if (FR_DIALOGTERM & info->Flags) {
    FindDialog = 0;
    return true;
  }
  else if ((FR_REPLACE | FR_REPLACEALL) & info->Flags) {
    //Future home of replace feature
    return false;
  }
  else {
    FINDTEXTEX ft;
    memset(&ft,0,sizeof(ft));
    ft.lpstrText = info->lpstrFindWhat;
    //Search whole text
    ft.chrg.cpMin = 0;
    ft.chrg.cpMax = -1;
   //Search down
    if (FR_DOWN & info->Flags) {
      if (!FindTheFirst) {
        //Not the first op, search from cursor to end
        CHARRANGE range;
        Client.GetSelection(&range);
        ft.chrg.cpMin = range.cpMax;
      }
    }
    //Search upward
    else {  //FR_UP
      if (!FindTheFirst) {
        //Not the first op, search from cursor to beginning
        CHARRANGE range;
        Client.GetSelection(&range);
        ft.chrg.cpMax = range.cpMin;
      }
    }
    int rtn = SendMessage(Client, EM_FINDTEXTEX,info->Flags,(LPARAM)&ft);
    if (-1 == rtn) {
      MessageBeep(MB_ICONEXCLAMATION);
      SetWindowText(HStatusBar,"Text not found");
      return false; //zilch
    }
    //found something
    FindTheFirst = false;
    Client.SetHideSelection(false);
    Client.SetSelection(&(ft.chrgText));

    //display the line number
    char buff[30];
    int line = SendMessage(Client,EM_LINEFROMCHAR,ft.chrg.cpMin,0);
    wsprintf(buff,"Line %i",line);
    SetWindowText(HStatusBar,buff);

    return true;
  }
}
Technical Details
Message-ID: <412df26a@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1c25a86216398487,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Gary Setter" <setterg@worldnet.att.net>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Search toward the beginning with richedit control
Date: Thu, 26 Aug 2004 09:23:56 -0500
Lines: 70
MIME-Version: 1.0
Content-Type: text/plain;
 charset="Windows-1252"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 12.74.20.158
Message-ID: <412df26a@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1093530218 12.74.20.158 (26 Aug 2004 07:23:38 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail