?
Solved

clean clipboard

Posted on 2008-11-03
20
Medium Priority
?
944 Views
Last Modified: 2012-08-13
c++ code to clear clip board
0
Comment
Question by:ankur3020
  • 11
  • 8
20 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 22873377
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
 

Author Comment

by:ankur3020
ID: 22873641
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
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 22873724
Yes, you will not be able to pate the copied files.

Best Regards,
DeepuAbrahamK
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ankur3020
ID: 22876481
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
 
LVL 86

Expert Comment

by:jkr
ID: 22879382
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
 

Author Comment

by:ankur3020
ID: 22897205
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
 
LVL 86

Expert Comment

by:jkr
ID: 22897270
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
 

Author Comment

by:ankur3020
ID: 22906247
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
 
LVL 86

Expert Comment

by:jkr
ID: 22906784
Good to know ;o)
0
 

Author Comment

by:ankur3020
ID: 22915681
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
 
LVL 86

Expert Comment

by:jkr
ID: 22919095
Oh, you can just make that
#include <windows.h>
 
void ClearClipboard() {
 
    OpenClipboard(NULL);
    EmptyClipboard();
    CloseClipboard();
}

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22923143
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
 
LVL 86

Expert Comment

by:jkr
ID: 22926200
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
 

Author Comment

by:ankur3020
ID: 22946326
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
 

Author Comment

by:ankur3020
ID: 22948153
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
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 22963613
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
 

Author Comment

by:ankur3020
ID: 22996895
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
 
LVL 86

Expert Comment

by:jkr
ID: 22999386
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
 

Author Comment

by:ankur3020
ID: 23013947
thanks, i made it.
0
 

Author Closing Comment

by:ankur3020
ID: 31512953
thanks a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question