String problem VS 2005



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.

Start notepad and type some text before running the following code.

#include <windows.h>
#include <iostream>
#include <winuser.h>


using namespace System;

int main()
{
HWND hNotepad, hEdit;
hNotepad = FindWindow(L"Notepad", NULL);
hEdit = FindWindowEx(hNotepad, NULL, L"edit", NULL);
SetForegroundWindow(hNotepad);

static char ClassName[51];
GetClassName(hNotepad,(LPTSTR) ClassName, 50 );
std::cout << "ClassName = " << ClassName; // *** NOT WORKING ***

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::cout << "Text captured from notepad = " << textData; // *** NOT
WORKING ***

free((void *) textData);

}

Thanks.

.



Relevant Pages

  • Re: String conversion/format
    ... display a char[] value in a label ... The problem is casting ClassName to LPTSTR. ... In .NET world you have just strings:) but in Win32/MFC/ATL there are ... I don't want to confuse you, but your code should be written using TCHAR, ...
    (microsoft.public.vc.language)
  • Re: String conversion/format
    ... display a char[] value in a label ... The problem is casting ClassName to LPTSTR. ... I don't want to confuse you, but your code should be written using TCHAR, ... or, IMHO, better, using explicit Unicode strings (i.e. wchar_t strings, like ...
    (microsoft.public.vc.language)
  • Re: String problem VS 2005
    ... the console the Classname and the text in the notepad window. ... Alternatively, use _Tand TCHAR everywhere, and your code will compile as either ANSI or UNICODE. ... You do not say what "NOT WORKING" means, but one thing you should do is check that hNotepas and hEdit are valid windows. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: IE Script Error in OE when trying to print
    ... > Char: 1 ... > Error: Unspecified error. ... E.g. enter in the Address bar of an IE window: ... Assuming that opens up a Notepad window make sure ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: I am a fresh Visual C++ .NET Developer. Convert char[1024] to System::String
    ... returns a char - which as you can see from the code below I am trying ... to pass to label1->Text - but this expects a String^ ... What data type does className() ... You are adding a character constant zero, ...
    (microsoft.public.dotnet.languages.vc)