Link to home
Start Free TrialLog in
Avatar of ankur3020
ankur3020

asked on

clean clipboard

c++ code to clear clip board
Avatar of jkr
jkr
Flag of Germany image

You should be fine with the following code, see also http://www.codeproject.com/KB/clipboard/clipnutshell.aspx ("Clipboard Copy in a Nutshell")
    OpenClipboard();
    EmptyClipboard();
    CloseClipboard();

Open in new window

Avatar of ankur3020
ankur3020

ASKER

suppose i copied some some in windows explorer and run the above code, will it clear clipboard and i will not able to paste the copied file?
Yes, you will not be able to pate the copied files.

Best Regards,
DeepuAbrahamK
should i just type the above code, and run file . or i need to add some other lines to the code. like header files
No, all you need is to maybe wrap that up in a function, e.g.
#include <windows.h>
 
void ClearClipboard() {
 
    OpenClipboard();
    EmptyClipboard();
    CloseClipboard();
}

Open in new window

i ran above code in turbo c++ and got error in all lines, pls guide.

first error was, unable to open windows.h
then openclipboard should have prototype and same error for other empty and close clip board.

what should i do to solve it.
Turbo C++ is way to old for that. If you need a free compiler, get Visual Studio Express from http://www.microsoft.com/downloads/details.aspx?FamilyID=a22341ee-21db-43aa-8431-40be78461ee0&DisplayLang=en
i installed vc6.0, will the above code runs in that. in the mean time i m downloading from ur specified link and will try to run the code there also.
Good to know ;o)
i downloaded visual c ++ 2008, and pasted ur code. i got one error.

'OpenClipboard' : function does not take 0 arguments.

screen shot attached.
error.jpg
Oh, you can just make that
#include <windows.h>
 
void ClearClipboard() {
 
    OpenClipboard(NULL);
    EmptyClipboard();
    CloseClipboard();
}

Open in new window

still getting error.

attached output of compile of above code.
1>------ Build started: Project: clip, Configuration: Debug Win32 ------
1>Compiling...
1>clip.cpp
1>Compiling manifest to resources...
1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>Linking...
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Ankur\Desktop\clip\Debug\clip.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\Ankur\Desktop\clip\clip\Debug\BuildLog.htm"
1>clip - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Open in new window

You seem to not have a 'main()' function there or you accidentially are compiling a console application. In the latter case, switch to a GUI project or alter the linker settings accordingly. In the advaced settings section, locate '/subsystem:console' and change that to '/subsystem:windows'
check the file i made and do the amendments if required, as this file is doing nothing. change file extension to cpp to open file.
clip.jpeg
i ran ur code,  i think there should be some handler in place of null in following code.  

 OpenClipboard(NULL);
   

as the code given is not working.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
code it working fine. but in this i have to give input for every function to run, pls amend the way that i only run on exe and done. no user input and window etc.
The above code snippet does not even show any window. It should do exactly what you want. Compile it and just double click on the executable.
thanks, i made it.
thanks a lot