• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 952
  • Last Modified:

clean clipboard

c++ code to clear clip board
0
ankur3020
Asked:
ankur3020
  • 11
  • 8
1 Solution
 
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

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

Best Regards,
DeepuAbrahamK
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
0
 
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

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

Open in new window

0
 
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

0
 
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'
0
 
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
0
 
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.
0
 
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

0
 
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.
0
 
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.
0
 
ankur3020Author Commented:
thanks, i made it.
0
 
ankur3020Author Commented:
thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 11
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now