Question about the clipboard

Hey people.
I wrote the this code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <windows.h>
#include <iostream>

using namespace std;

bool isClipboardEmpty()
{
    if (CountClipboardFormats()==0)
        return true;
    return false;
}

int main()
{
    if (!OpenClipboard(NULL))
    {
        cout<<"Unable to open clipboard !"<<endl;
        return 0;
    }
    EmptyClipboard();
    while(true)
    {
        if (!isClipboardEmpty())
        {
            cout<<"bla bla bla"<<endl;
        }
    }
    return 0;
}


Well,
The code's purpose is to print "bla bla bla" if the clipboard is getting filled during the program's run-time.

It doesn't work, anyone know what is the problem ?
Thanks!
What's wrong with that?




You don't need the function isClipboardEmpty, you could change the if condition in simply ( CountClipboardFormats() )
Yeah, I know that, but I prefer it will be like that.

And the problem is that it just doesn't work.

It should print "bla bla bla" if the clipboard is getting filled during the program's run-time, and when I am copying something (i.e. the clipboard is getting filled) nothing happens.
Last edited on
Hmm
Anyone?
Which compiler are you using? I've tried your code both on VC++ and MingW and it worked fine.
Try to see if GetLastError returns something
I am using MingW too. (Code::Blocks IDE)

Anyway, I have discovered something interesting.
The problem is, that the clipboard from some reason, can't get filled during the program run-time.
I mean, when I am copying something while the program is running, I can't paste it, i.e. the clipboard doesn't get filled, and that's why it doesn't work.
(If I delete the EmptyCilpboard() function and I am filling the clipboard before I run the program, it works.)

But I don't know why the clipboard can't get filled during the program's run-time.
It's weird.
Last edited on
I've tried your program with different console settings and I've found out that it works only if the QuickEdit option is enabled
How can I enable this option?
Actually I know how to do this by clicking, not by code.
On the console window click on the icon then properties and there you should see a checkbox for the QuickEdit mode
Okay.

Thank you very much!!
I've found the code to enable that option, call
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE),ENABLE_EXTENDED_FLAGS|ENABLE_QUICK_EDIT_MODE);
at the beginning of the program
The method is wrong.
The official method is to use a Win32 GUI and CDVR
At MSDN that method is documented: http://msdn.microsoft.com/en-us/library/ms686033.aspx
Not that method.
The method to handle clipboard updates...
Topic archived. No new replies allowed.