[C++] 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)

Can anybody point me in the right direction?
Last edited on
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
I'm aware of subclassing, and I figured that would be how I'd do it, but if I press Backspace, it deletes the character, but it doesn't tell me what it just deleted. That's the info I need.
Is this in an edit control, or what?

A lot depends on what you are deleting from.

If it's from an edit control you can get the text of the edit control before it's deleted and then compare.
Yes, it's an edit box. Is that the only way to do it? I was hoping there was a bit simplier way.
What's so hard about using GetDlgItemText() and then comparing which chars are no longer there?

You could save the text in the edit control multiple times using a counter, but you're still going to have to compare the strings to see what has been deleted.

How do you think MS Word and other programs do it? They do it by saving the info and then reverting back to it if called upon to do so.

If you want to save entire procedures, the link given above may be helpful to you as well, but that is much more complicated than just dealing with a simple edit control.
Last edited on
I like the shortest code possible, and I wasn't sure if the API happened to have the function.

With that info then, would this be bad: Take the original and index the number of each of the caracters, then take the second one and subtract the new from the old, if anythings a negative, then it was removed that many times?
I really have no idea what would be best as I don't have a clue as to what your overalll goal and design and operations are. You'll have to decide all that for yourself.

If I was just going to compare two strings, I wouldn't index anything; I'd just compare the strings with the many string functions that C/C++ offers.

If you have multiple strings, then you have to decide how you're going to handle the memory/disk IO, et cetera, et cetera, et cetera.
My goal was cleary said in the first post, I need to know which characters are deleted. That was even the TL;DR.
You didn't specify it was an edit control in the beginning, and you haven't specified how many edit controls you are talking about, and you haven't specified how many iterations per edit box you are looking to keep track of, and so on and so forth.

In any case, I think you now have plenty of information to do what you want. If not, specify exactly what it is that you are having trouble with.
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 --

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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;
}
Last edited on
Thanks for the reference. Afraid I won't quite be able to use it though, since I could go from the old red box to the red box, or the new red box. Looks like on each command I'll be comparing to the previous string.
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 --

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


This simply confines the interation to the missing characters.
Last edited on
Yes, it has pointed me in the correct direction. From what I found, I think there may be a message for undo/redo, but I havn't gotten around to testing it yet.

Thanks for all of the help.
It struck me after I last posted that -- if you just want an undo/redo capability -- you don't need to keep track of which characters are missing.

Instead, all you have to do is save each string consecutively, either in memory or disk, and then pull them into use as needed.

So if all you want is an undo/redo feature, that simplifies matters greatly.
Not just, but it's needed. Considering I can go from asd to asf though, it looks like that's the method I'll be using every time.
Topic archived. No new replies allowed.