Worstje said:
For your viewing 'pleasure', I have put all VS2010 CEditView code regarding find and replace on pastebin. I'd go through the details and such myself, but I haven't got a clue where it goes wrong for you, and I'd have a hard time debugging an issue I don't have as well. Copy/paste as you see fit, or if you spot a more surgical solution to your problems, do that.
http://pastebin.com/s0k6HfcD
Well I just don't think it's worth it. I see what is happening a bit more clearly. The new controls assume the text is Unicode (obviously the old ones didn't because without changes anywhere else they work).
Now I initially tried changing the ReadFromArchive to convert the text to Unicode (assuming it was UTF-8 - can we assume that? and if not, what do we assume?).
So instead of setting the shadow buffer to nothing, I put the Unicode text in the shadow buffer - in other words like this:
#ifndef _UNICODE
if (_AfxGetComCtlVersion() >= VERSION_6)
{
// work out required length
int iUnicodeCharacters = MultiByteToWideChar (CP_UTF8, 0,
lpszText, nLen, // input
NULL, 0); // output
LPVOID hUnicodeText = LocalAlloc(LMEM_MOVEABLE, (iUnicodeCharacters+1)*sizeof(WCHAR));
if (hUnicodeText == NULL)
AfxThrowMemoryException();
LPTSTR lpszUnicodeText = (LPTSTR)LocalLock(hUnicodeText);
ASSERT(lpszUnicodeText != NULL);
MultiByteToWideChar (CP_UTF8, 0, lpszText, nLen, (WCHAR *) lpszUnicodeText, (iUnicodeCharacters+1));
LocalUnlock(hText);
LocalFree(hText);
hText = hUnicodeText;
}
#endif
So far so good - the text appears OK, and it writes out OK, as the writing part seemed to be assuming Unicode (why?).
But the finding doesn't work. Setting some breakpoints found that the MFC I have assumes we have straight text and not Unicode. But this is reasonable - it *is not* a Unicode app. Now I can start replacing all the finding stuff to do a Unicode find, but why not rewrite the whole app to be Unicode while I'm at it?
Next thing I'll find is that copying and pasting won't work right because one is Unicode and one isn't,
The thing is, Worstje, you are trying to put old wine into new bottles. It doesn't work. And the fact that the new common controls "just assume" you have Unicode in the edit window, when the old ones don't make any such assumption, doesn't help one bit.
I think the whole thing will have to be reverted, sorry. If you want to start again and write a Unicode client, be my guest. But this merging in of (dare I say it) buggy common controls with an old app isn't working. |