> > How can I "convert" from a char to a string. I'm trying to display in
> > the console the Classname and the text in the notepad window.
[quoted text clipped - 44 lines]
>
> - Afficher le texte des messages pr?c?dents -
> By NOT WORKING I mean :
>
[quoted text clipped - 8 lines]
> example to use uniform string instead of my newbee mix of narrow, wide
> and agnostic strings.
// untested agnostic version
#ifdef UNICODE
#define tcout wcout
#else
#define tcout cout
#endif
int main()
{
HWND hNotepad, hEdit;
hNotepad = FindWindow(_T("Notepad"), NULL);
hEdit = FindWindowEx(hNotepad, NULL, _T("edit"), NULL);
SetForegroundWindow(hNotepad);
TCHAR ClassName[51];
GetClassName(hNotepad, ClassName, 50 );
std::tcout << _T("ClassName" = ") << ClassName;
int iLength = (int)::SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0);
TCHAR * textData = (TCHAR *) malloc((iLength + 1) * sizeof(TCHAR));
SendMessage(hEdit, WM_GETTEXT, iLength+1, (LPARAM)textData);
std::tcout << _T("Text captured from notepad = ") << textData;
free((void *) textData);
}

Signature
David Wilkinson
Visual C++ MVP
SQACSharp - 12 Sep 2007 00:25 GMT
> > By NOT WORKING I mean :
>
[quoted text clipped - 40 lines]
> David Wilkinson
> Visual C++ MVP
Thanks...it work now!
Just one more thing.... if I want to compare my string...ex:
If i put the following lines after the first output (the classname)
if (strcmp(ClassName,"Notepad")==1)
{
std::tcout << "The classname is notepad";
}
I get the following error : cannot convert parameter 1 from 'TCHAR
[51]' to 'const char *'
There is really something I dont understand about String and
conversion.... any help?
Ben Voigt [C++ MVP] - 12 Sep 2007 01:52 GMT
>> > By NOT WORKING I mean :
>>
[quoted text clipped - 54 lines]
> I get the following error : cannot convert parameter 1 from 'TCHAR
> [51]' to 'const char *'
You just won't be able to use ASCII strings anymore. Instead try:
_tcscmp(ClassName, _T("Notepad"))
SQACSharp - 12 Sep 2007 02:03 GMT
> >> > By NOT WORKING I mean :
>
[quoted text clipped - 60 lines]
>
> - Show quoted text -
Still not working..._TCSCPM return 0
HWND hNotepad, hEdit;
hNotepad = FindWindow(L"Notepad", NULL);
hEdit = FindWindowEx(hNotepad, NULL, L"edit", NULL);
SetForegroundWindow(hNotepad);
static TCHAR ClassName[51];
GetClassName(hNotepad,(LPTSTR) ClassName, 50 );
std::tcout << _T("Classname---> ") << ClassName;
std::tcout <<_tcscmp(ClassName,_T("Notepad"));
if (_tcscmp(ClassName,_T("Notepad"))!=0)
{
std::tcout << "Notepad classname found"; //It never enter here
}
Ben Voigt [C++ MVP] - 12 Sep 2007 02:37 GMT
> Still not working..._TCSCPM return 0
>
[quoted text clipped - 12 lines]
> std::tcout << "Notepad classname found"; //It never enter here
> }
Well, considering that strcmp, wcscmp, and _tcscmp all return zero when the
strings are equal, I'm not surprised. They are comparison functions, useful
to pass to a sort routine, which means they have to differentiate between
(less than/equal/greater than).
SQACPP - 12 Sep 2007 02:49 GMT
> > Still not working..._TCSCPM return 0
>
[quoted text clipped - 19 lines]
>
> - Show quoted text -
Thanks again!...everything work now!
SQACSharp - 12 Sep 2007 01:45 GMT
> > By NOT WORKING I mean :
>
[quoted text clipped - 40 lines]
> David Wilkinson
> Visual C++ MVP
Thanks!!!
Now If a want to do a comparison on the ClassName (with the same
example with classname and the content of the notepad window??? ex:
if (strcmp(ClassName,"Notepad")==1)
{
std::tcout << "notepad found";
}
It return error : 'strcmp' : cannot convert parameter 1 from 'TCHAR
[51]' to 'const char *'
It's hard to understand understand what kind of string format to use
and how to convert it...any help?
Thanks again!
David Wilkinson - 12 Sep 2007 02:42 GMT
> Thanks!!!
>
[quoted text clipped - 11 lines]
> It's hard to understand understand what kind of string format to use
> and how to convert it...any help?
If you look up strcmp in the Help, you will find the answer to your
question.
BTW, the MFC CString class has methods that deal with the narrow/wide
character issue in a transparent way.
BTW, again, you are really in the wrong group. Questions about
traditional C++ are better asked in
microsoft.public.vc.language
microsoft.public.vc.mfc

Signature
David Wilkinson
Visual C++ MVP
SQACPP - 12 Sep 2007 02:58 GMT
> > Thanks!!!
>
[quoted text clipped - 29 lines]
>
> - Show quoted text -
What i need to include to be able to use MFC CString class?
David Wilkinson - 12 Sep 2007 10:19 GMT
> What i need to include to be able to use MFC CString class?
You need to look up CString in the Help.

Signature
David Wilkinson
Visual C++ MVP