Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CRichEditView and last char removed from file

Posted on 2003-11-30
11
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

721 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