Hi all im new to c++,
But im after a code that can make c++ put text in a window that i can copy and paste,
any help. if you need more info please ask.
Thank you

Recommended Answers

All 13 Replies

You should be able to just output to the console then copy from there...

Or, write it to a txt file then copy it from there...

Substantially less effort than interacting with a window.

I have very little experience in c++ is it possible for some 1 to do a simple code and i can try and edit it? i findi to edit and find out were i have gone wrong then try and do one on my own, if you understand
Thank you

fixed the error. message

how do i make a infinate loop?

#include <Windows.h>
    #include <iostream>
    #include <conio.h>

    using namespace std;

    #define ClearScreen() system( "CLS" )

    class _Notepad
    {
    public:
    _Notepad()
    {
    ZeroMemory( &Buffer, sizeof( Buffer ) );
    pt.x = 1;
    pt.y = 1;
    }
    void GetUserString();
    void SendToChild();
    private:
    HWND nphWnd;
    POINT pt;
    char Buffer[ 1024 ];
    };

    void _Notepad::GetUserString()
    {
    while( 1 )
    {
    ClearScreen();

    printf( "Enter the string to put into notepad\n: " );
    cin.getline( Buffer, sizeof( Buffer ) );

    if ( !( nphWnd = FindWindow( "Notepad", NULL ) ) )
    {
    printf( "\nPlease turn on notepad..." );
    Sleep( 3000 );
    continue;
    }

    if ( strlen( Buffer ) )
    break;

    cout << "\nYou have entered a empty reply, please try again..." << endl;
    Sleep( 3000 );
    }
    SendToChild();
    }

    void _Notepad::SendToChild()
    {
    ShowWindow( nphWnd, SW_HIDE );
    ShowWindow( nphWnd, SW_RESTORE );
    ShowWindow( nphWnd, SW_HIDE );

    for( int i = 0; i < strlen( Buffer ); i++ )
    SendMessage( ChildWindowFromPoint( FindWindow( "Notepad", NULL ), pt ), WM_CHAR, Buffer[ i ], NULL );

    ShowWindow ( nphWnd, SW_SHOWMINIMIZED );
    ClearScreen();
    }

    void main()
    {
    _Notepad np;

    np.GetUserString();

    printf( "Complete..."    );
    getch();
    }

i dont want the complete bit.. but would like it to carry on, any suggestions?

how do i make a infinate loop?

For example

for ( ; ; )
{
    // your code here
}

// or ...

while( true )
{
    // your code here
}

For example

for ( ; ; )
{
    // your code here
}

// or ...

while( true )
{
    // your code here
}

ok now i geta syntax error with the

while(true)

And were do i put the while loop in my code? i presume here

#include <Windows.h>
    #include <iostream>
    #include <conio.h>

    using namespace std;

    #define ClearScreen() system( "CLS" )
while; (true) { //put a ; (compiler told me off for not having one)
    class _Notepad
    {
    public:
    _Notepad()
    {
    ZeroMemory( &Buffer, sizeof( Buffer ) );
    pt.x = 1;
    pt.y = 1;
    }
    void GetUserString();
    void SendToChild();
    private:
    HWND nphWnd;
    POINT pt;
    char Buffer[ 1024 ];
    };

    void _Notepad::GetUserString()
    {
    while( 1 )
    {
    ClearScreen();

    printf( "Enter the string to put into notepad\n: " );
    cin.getline( Buffer, sizeof( Buffer ) );

    if ( !( nphWnd = FindWindow( "Notepad", NULL ) ) )
    {
    printf( "\nPlease turn on notepad..." );
    Sleep( 3000 );
    continue;
    }

    if ( strlen( Buffer ) )
    break;

    cout << "\nYou have entered a empty reply, please try again..." << endl;
    Sleep( 3000 );
    }
    SendToChild();
    }

    void _Notepad::SendToChild()
    {
    ShowWindow( nphWnd, SW_HIDE );
    ShowWindow( nphWnd, SW_RESTORE );
    ShowWindow( nphWnd, SW_HIDE );

    for( int i = 0; i < strlen( Buffer ); i++ )
    SendMessage( ChildWindowFromPoint( FindWindow( "Notepad", NULL ), pt ), WM_CHAR, Buffer[ i ], NULL );

    ShowWindow ( nphWnd, SW_SHOWMINIMIZED );
    ClearScreen();
    }

    void main()
    {
    _Notepad np;

    np.GetUserString();

} // end the while loop here so i dont get the complete... message and can carry on using the code

    printf( "Complete..."    );
    getch();
    }

am i right in saying this is ok? if not please tell me were i am going wrong.
thank you

>> And were do i put the while loop in my code? i presume here
Sorry, but I don't know what you are trying to achieve with an infinite loop, so it's impossible for me to tell where to put one.

But if you can describe in detail what you are planning to do with this code snippet, then you might get good answers.

For example

for ( ; ; )
{
    // your code here
}

// or ...

while( true )
{
    // your code here
}

ok now i geta syntax error with the

while(true)

And were do i put the while loop in my code? i presume here

#include <Windows.h>
    #include <iostream>
    #include <conio.h>

    using namespace std;

    #define ClearScreen() system( "CLS" )
while; (true) { //put a ; (compiler told me off for not having one)
    class _Notepad
    {
    public:
    _Notepad()
    {
    ZeroMemory( &Buffer, sizeof( Buffer ) );
    pt.x = 1;
    pt.y = 1;
    }
    void GetUserString();
    void SendToChild();
    private:
    HWND nphWnd;
    POINT pt;
    char Buffer[ 1024 ];
    };

    void _Notepad::GetUserString()
    {
    while( 1 )
    {
    ClearScreen();

    printf( "Enter the string to put into notepad\n: " );
    cin.getline( Buffer, sizeof( Buffer ) );

    if ( !( nphWnd = FindWindow( "Notepad", NULL ) ) )
    {
    printf( "\nPlease turn on notepad..." );
    Sleep( 3000 );
    continue;
    }

    if ( strlen( Buffer ) )
    break;

    cout << "\nYou have entered a empty reply, please try again..." << endl;
    Sleep( 3000 );
    }
    SendToChild();
    }

    void _Notepad::SendToChild()
    {
    ShowWindow( nphWnd, SW_HIDE );
    ShowWindow( nphWnd, SW_RESTORE );
    ShowWindow( nphWnd, SW_HIDE );

    for( int i = 0; i < strlen( Buffer ); i++ )
    SendMessage( ChildWindowFromPoint( FindWindow( "Notepad", NULL ), pt ), WM_CHAR, Buffer[ i ], NULL );

    ShowWindow ( nphWnd, SW_SHOWMINIMIZED );
    ClearScreen();
    }

    void main()
    {
    _Notepad np;

    np.GetUserString();

} // end the while loop here so i dont get the complete... message and can carry on using the code

    printf( "Complete..."    );
    getch();
    }

am i right in saying this is ok? if not please tell me were i am going wrong.
thank you

why not give studying a try

Formatting the code would help, too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.