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 )
            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 ) .

3 Years
Discussion Span
Last Post by Ancient Dragon

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.

Edited by Ancient Dragon


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.

Edited by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.