I want this program to wait untill I copy some text into my clipboard. This is what I have done so far

    char text[500] ;
    HANDLE clip ;

    if ( OpenClipboard (NULL) )
        cout << "\nClipboard opened" ;

    EmptyClipboard () ;

    cout << "\nStart" ;

    while ( true )
    {
        if ( GetClipboardData (CF_TEXT) != NULL )
        {
            cout<<"\ninside";
            clip = GetClipboardData (CF_TEXT);
            break ;
        }
    }

    /*if ( OpenClipboard (NULL) )
        clip = GetClipboardData (CF_TEXT);*/

    strcpy ( text, (char*)clip ) ;

    cout << "\n" << text ;

But its no working properly. Start gets printed but after that nothing happens. It never goes inside if ( also I'm at first cleaning up my clipboard so that I first start the program and then I copy some text into clipboard ) .

How do you expect the thread to wait until it does something? You can't have it both ways.

What's supposed to happen when GetClipboardData() returns NULL? You need to put a Sleep() in that loop so that other processes and threads get CPU time.

I mean that it will act like its waiting for input, but from clipboard, not from standard inputs.

Didn't understand how sleep() will help the cause.

How do you think data is going to be put into the clipboard? Some process other than your program has to do it, it's not possible for someone enter clipboard data from the keyboard. Sleep() will allow other programs to run and possibly store data into the clipboard so that your program can see it. And since you have no control over what other programs do your program might have to wait an awful long time before another process puts something into the clipboard.

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.