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)
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.
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.
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.
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 --
#include <iostream>
#include <string>
usingnamespace 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;
}
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.
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.