Solved

CRichEditView and last char removed from file

Posted on 2003-11-30
11
234 Views
Last Modified: 2013-11-20
I hav a CRichEditView and would like to get the last removed (or about to be removed) character when the user presses the backspace or delete key.

Any ideas?
0
Comment
Question by:boodabelly
  • 6
  • 5
11 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 total points
ID: 9848191
Map WM_KEYDOWN do use the code

void CMyRichEditView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

      long lStartPos, lEndPos;
      CString csTextToBeDeleted;

      GetRichEditCtrl().GetSel(lStartPos, lEndPos);

      if ( VK_BACK == nChar ||
             VK_DELETE == nChar )
      {
        if (lEndPos - lStartPos > 0)
        {
                  csTextToBeDeleted = GetRichEditCtrl().GetSelText();
        }
            else
            {
                  if ( VK_BACK == nChar )
                  {
                        GetRichEditCtrl().SetSel(lStartPos-1, lStartPos);
                  }
                  else
                  {
                        GetRichEditCtrl().SetSel(lStartPos, lStartPos+1);
                  }

                  csTextToBeDeleted = GetRichEditCtrl().GetSelText();

                  GetRichEditCtrl().SetSel(lStartPos, lEndPos);
            }

            csTextToBeDeleted;   <----------------------- THIS WILL BE THE TEXT THAT TO BE DELETED
      }
      
      

      CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
}

Good Luck
0
 
LVL 1

Author Comment

by:boodabelly
ID: 9848430
thanks man, works like a champ! =)
0
 
LVL 1

Author Comment

by:boodabelly
ID: 9848470
ugh, well, appearantly I accepted a little in haste and excitement.  I am trying to detect when a new line character is removed from the screen, can you answer that still or do I need to post another question?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9848480
I will check that....
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9848495
In that case that text (csTextToBeDeleted) will give you the character 13.

char cChar = 13;

you can compare that text with cChar.

Rosh :)
0
 
LVL 1

Author Comment

by:boodabelly
ID: 9848665
ok, what am I doing wrong here?

// from constants file
#define BYY_NEW_LINE                  13

void Cbyy_view::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

      long start_pos;
      long end_pos;

      if(!can_edit())
      {
            return;
      }

      GetRichEditCtrl().GetSel(start_pos, end_pos);

      if(nChar == VK_BACK || nChar == VK_DELETE)
      {
            if(end_pos - start_pos > 0)
            {
                  m_last_deleted_text = GetRichEditCtrl().GetSelText();
            }
            else
            {
                  if(nChar == VK_BACK)
                  {
                        GetRichEditCtrl().SetSel(start_pos - 1, start_pos);
                  }
                  else
                  {
                        GetRichEditCtrl().SetSel(start_pos, start_pos + 1);
                  }

                  m_last_deleted_text = GetRichEditCtrl().GetSelText();
                  GetRichEditCtrl().SetSel(start_pos, end_pos);
            }

            if(m_last_deleted_text == BYY_NEW_LINE)
            {
                  update_edit_areas(-1);
            }
      }

      CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
}
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9848704
This will work, I modified that string comparison like "GetAt" check the below code

// from constants file
#define BYY_NEW_LINE               13

void Cbyy_view::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

    long start_pos;
    long end_pos;

    if(!can_edit())
    {
         return;
    }

    GetRichEditCtrl().GetSel(start_pos, end_pos);

    if(nChar == VK_BACK || nChar == VK_DELETE)
    {
         if(end_pos - start_pos > 0)
         {
              m_last_deleted_text = GetRichEditCtrl().GetSelText();
         }
         else
         {
              if(nChar == VK_BACK)
              {
                   GetRichEditCtrl().SetSel(start_pos - 1, start_pos);
              }
              else
              {
                   GetRichEditCtrl().SetSel(start_pos, start_pos + 1);
              }

              m_last_deleted_text = GetRichEditCtrl().GetSelText();
              GetRichEditCtrl().SetSel(start_pos, end_pos);
         }

         if(m_last_deleted_text.GetAt(0) == BYY_NEW_LINE)
         {
              update_edit_areas(-1);
         }
    }

    CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
}
0
 
LVL 1

Author Comment

by:boodabelly
ID: 9848774
hmmm, well the .GetAt(0) crashes because the strlen is < 0.  m_last_deleted_text = "" when I remove a new line char.  I am thinking I might have to get the current line, move the cursor the appropriate direction and check the line number again.  I will try that and report back
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9848779
Okay,
Good Luck
0
 
LVL 1

Author Comment

by:boodabelly
ID: 9848908
roshmon, cool man, this is what I got to work from the help you gave me, guess I need to get more used to this MFC stuff (I'm too old skool C), have to start thinking in MFC and getting comfortable with what functions do what, logic for MFC is pretty simple, just need to get more comfortable with it, ok, its 3am and I am rambling, BTW,this is what I got to work

void Cbyy_view::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

      long start_pos;
      long end_pos;
      int line_num;


      line_num = m_curr_line;
      GetRichEditCtrl().GetSel(start_pos, end_pos);

      if(nChar == VK_BACK || nChar == VK_DELETE)
      {
            if(!can_edit())
            {
                  return;
            }

            if(nChar == VK_BACK)
            {
                  GetRichEditCtrl().SetSel(start_pos - 1, start_pos - 1);
            }
            else
            {
                  // increment two positions to go past the '\n'
                  GetRichEditCtrl().SetSel(start_pos + 2, start_pos + 2);
            }

            line_num = GetRichEditCtrl().LineFromChar(-1) + 1;

            if(line_num != m_curr_line)
            {
                  update_edit_areas(-1);
            }

            GetRichEditCtrl().SetSel(start_pos, end_pos);
      }

      CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
}

thanks again man!
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9848928
Welcome :0)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Include multiple hostnames in this command? 3 55
Separate into files by filename 12 83
difference between String.subString() and String.subSequence() 6 199
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question