clean clipboard

c++ code to clear clip board
ankur3020Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
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

ankur3020Author Commented:
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?
Deepu AbrahamR & D Engineering ManagerCommented:
Yes, you will not be able to pate the copied files.

Best Regards,
DeepuAbrahamK
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

ankur3020Author Commented:
should i just type the above code, and run file . or i need to add some other lines to the code. like header files
jkrCommented:
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

ankur3020Author Commented:
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.
jkrCommented:
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
ankur3020Author Commented:
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.
jkrCommented:
Good to know ;o)
ankur3020Author Commented:
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
jkrCommented:
Oh, you can just make that
#include <windows.h>
 
void ClearClipboard() {
 
    OpenClipboard(NULL);
    EmptyClipboard();
    CloseClipboard();
}

Open in new window

ankur3020Author Commented:
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

jkrCommented:
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'
ankur3020Author Commented:
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
ankur3020Author Commented:
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.
jkrCommented:
The problem seems to be that this is a console app. Make it a GUI app and try
// clip1.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include "windows.h"
 
void ClearClipboard() 
{
	OpenClipboard(NULL);
	EmptyClipboard();
	CloseClipboard();
} 
 
int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
	
	ClearClipboard();
	return 0;
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ankur3020Author Commented:
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.
jkrCommented:
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.
ankur3020Author Commented:
thanks, i made it.
ankur3020Author Commented:
thanks a lot
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.