user1285801
user1285801

Reputation:

Win32 - Processing the backspace command?

TL;DR I need to know which characters are deleted with Win32.

Basically, I need to know what characters are deleted, each time they are. Considering that there are three methods to delete, (Backspace, delete, and Right click>Delete) I'm not sure if I'll just be re-using the same code or what. There's also the option of multiple characters being selected, as well as the option for undo/redo. There's probably something else I'm missing.

As I said above, I need to know which characters are deleted, and how to use undo/redo and how to tell if when using those if characters were added or deleted. (If that's something easily Google, tell me, I just thought of them as I've been writting this post)

Upvotes: 1

Views: 455

Answers (1)

NullPoiиteя
NullPoiиteя

Reputation: 57322

What exactly are you talking about? The win32 default control windows? You can subclass them to do that... http://msdn.microsoft.com/en-us/library/bb773183%28v=vs.85%29.aspx

Well, if you come up with something specific code-wise and don't quite know what to do, just ask here and see if someone can't help you.

With regard to undo/redo, I believe it all depends on the size of the focus area, and I'm not sure how MS does it for, say, Word, or Excel, etc.

But for short stuff, what I posted above should work in a universal sense, but apparently not in your case.

Nevertheless, if anyone wanted to shorten the iteration in the above, they could replace the loop above by starting right at the end of shorter string, like this --

for(int i = iLen2, x=0; i < iLen1; i++, x++)
 szAnswer[x]=str1[i];

This simply confines the interation to the missing characters.

Here is a small Win32 Console application that will demonstrate a very simple way to determine which characters have been deleted. You can easily adapt this to a Win32 App, add iterations to it, and so on

#include <iostream>
#include <string>

using namespace std;

#ifndef MAX_PATH
#define MAX_PATH 256
#endif

int main()
{
       int iLen1, iLen2, iResult;
       char str1[]="The old red box.";
       char str2[]="The old red";
       char szAnswer[MAX_PATH]="";

       // strcmp() will be greather than 0
       // if str1 is longer than str2
       if(strcmp(str1, str2) > 0)
       {
    iLen1=strlen(str1);
    iLen2=strlen(str2);
    iResult=iLen1-iLen2;

    cout << "The number of missing characters is " << iResult << endl << endl;

    // now lets see which characters are missing
    // we iterate through the entire length
    // of str1, which is the full text, but
    // we only start puting characters into our
    // result when we get to the end of str2
    for(int i=0, x=0; i < iLen1; i++)
    {
                    if(i >= iLen2)
        {
            szAnswer[x++]=str1[i];
        }
    }

       cout << endl << "The missing characters are --" << endl << endl << szAnswer << endl << endl;
      }

      return 0;
}

Upvotes: 1

Related Questions