Re: String problem VS 2005



On 11 sep, 16:51, David Wilkinson <no-re...@xxxxxxxxxxxx> wrote:
SQACSharp wrote:
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);

}

SQACharp:

In VS 2005 projects are Unicode by default. This means you must use L""
and wchar_t everywhere. Alternatively, use _T("") and TCHAR everywhere,
and your code will compile as either ANSI or UNICODE.

Right now, your code is a mix of narrow, wide and agnostic strings.

You do not say what "NOT WORKING" means, but one thing you should do is
check that hNotepas and hEdit are valid windows.

--
David Wilkinson
Visual C++ MVP- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

By NOT WORKING I mean :

The first output to the console (the classname) is "N" and not
"Notepad" as expected

The second output to the console (the text content of notepad) is
equal to a numeric value instead of the real content.

I dont understand how to work with all the C++ string format . What
kind of string i'm suppose to use? Is anybody can correct my code
example to use uniform string instead of my newbee mix of narrow, wide
and agnostic strings.

Thanks

.



Relevant Pages

  • Re: String problem VS 2005
    ... The first output to the console (the classname) is "N" and not ... The second output to the console (the text content of notepad) is ... I dont understand how to work with all the C++ string format. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: String problem VS 2005
    ... "Notepad" as expected ... example to use uniform string instead of my newbee mix of narrow, ... Now If a want to do a comparison on the ClassName (with the same ...
    (microsoft.public.dotnet.languages.vc)
  • Re: wprintf() could not display unicode chars which is > 255 to console?
    ... > console window with formatting strings. ... Unicode and the Windows console is a tricky business. ... string msg, action; ... In Japanese you should have no spaces, and the translator can remove them. ...
    (microsoft.public.vc.mfc)
  • Re: Command Line Interface
    ... This is somewhat I am aiming for, to be honest my idea for this is Java ... Netbean's 'console window' which it uses for user input and output. ... [user enters string and conv to double] ... CString GetString() ...
    (microsoft.public.vc.mfc)
  • Re: Download File, Copy Text To Clipboard
    ... There's an API function named URLDownloadToFile that you can use. ... ByVal szFileName As String, _ ... MSIE won't display a file with a .abc extension. ... Set my computer to use Notepad to open .abc files. ...
    (microsoft.public.access.modulesdaovba)