Solved

CRichEditView and last char removed from file

Posted on 2003-11-30
11
237 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 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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: 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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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