473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prevent Paste outside my app

Hello,

I am looking for a clever way to prevent someone from pasting copied text
outside of my app.

I know how to monitor the clipboard and get an WM_DRAWCLIPBOAR D message when
text is stored in the clipboard... If only I could detect some kind of
outgoing message that the clipboard is about to paste, then I could check to
see if my app is currently in focus and allow/deny as necessary.

I would just erase the clipboard upon the app loosing focus, but I can see
cases where that would be a pain to the user if they just had to click
somewhere else real quick.

Anyone have any ideas?

Thank you all for reading this.

Rob K
May 23 '06 #1
11 2174
It's kind of a pain but you could implement your own clipboard just for your
application.

--
Jeffrey Hornby
Hornby Consulting, Inc.

"RobKinney1 " wrote:
Hello,

I am looking for a clever way to prevent someone from pasting copied text
outside of my app.

I know how to monitor the clipboard and get an WM_DRAWCLIPBOAR D message when
text is stored in the clipboard... If only I could detect some kind of
outgoing message that the clipboard is about to paste, then I could check to
see if my app is currently in focus and allow/deny as necessary.

I would just erase the clipboard upon the app loosing focus, but I can see
cases where that would be a pain to the user if they just had to click
somewhere else real quick.

Anyone have any ideas?

Thank you all for reading this.

Rob K

May 23 '06 #2
Hey Jeffrey,

Thank you for replying. Kinda funny you mentioned that, because that is
what I started doing before I realized that the 2 different activeX Word
controls (from the browser control) would loose their formating. I couldn't
program something sophisticated enough to preserve the tables, graphs, etc,
through my own clipboard.

I also thought about capturing all CTRL+V's that happen outside of my app
(through a hook), but I cannot prevent the user from right-clicking somewhere
and clicking paste. (I tried catching the WM_PASTE message system-wide, but
that message doesn't seem to be what is being sent when copying from a Word
doc to Notepad :-{ ).

Any other thoughts/ideas?

Thanks again for replying.

Rob K

"Jeffrey Hornby" wrote:
It's kind of a pain but you could implement your own clipboard just for your
application.

--
Jeffrey Hornby
Hornby Consulting, Inc.

"RobKinney1 " wrote:
Hello,

I am looking for a clever way to prevent someone from pasting copied text
outside of my app.

I know how to monitor the clipboard and get an WM_DRAWCLIPBOAR D message when
text is stored in the clipboard... If only I could detect some kind of
outgoing message that the clipboard is about to paste, then I could check to
see if my app is currently in focus and allow/deny as necessary.

I would just erase the clipboard upon the app loosing focus, but I can see
cases where that would be a pain to the user if they just had to click
somewhere else real quick.

Anyone have any ideas?

Thank you all for reading this.

Rob K

May 24 '06 #3
Rob,

You can add the text under some private clipboard format.

class Program
{

[STAThread]
static void Main(string[] args)
{

Clipboard.SetDa ta("MyFormat", "Hello World");
if (Clipboard.Cont ainsData("MyFor mat"))
{
Console.WriteLi ne("Paste - {0}",
(string)Clipboa rd.GetData("MyF ormat"));
}
Console.ReadLin e();
}
}

As long as the format is private no other application will ever attempt to
get this data from the clipboard, but two instances of your application can
use it. To prevent that you can add one more piece of information to the
clipboard that will be some application ID, e.g. GUID that you create upon
application start.
Before pasting from the clipboard the application first read and check this
ID against application's own ID and if they don't match then don't paste.
--
HTH
Stoitcho Goutsev (100)

"RobKinney1 " <Ro********@dis cussions.micros oft.com> wrote in message
news:80******** *************** ***********@mic rosoft.com...
Hello,

I am looking for a clever way to prevent someone from pasting copied text
outside of my app.

I know how to monitor the clipboard and get an WM_DRAWCLIPBOAR D message
when
text is stored in the clipboard... If only I could detect some kind of
outgoing message that the clipboard is about to paste, then I could check
to
see if my app is currently in focus and allow/deny as necessary.

I would just erase the clipboard upon the app loosing focus, but I can see
cases where that would be a pain to the user if they just had to click
somewhere else real quick.

Anyone have any ideas?

Thank you all for reading this.

Rob K

May 24 '06 #4
Yes, this does help. Thank you Stoitcho. But one thing remains a mystery to
me. When you wrote:
Before pasting from the clipboard the application first read and check this
ID against application's own ID and if they don't match then don't paste.
How do I know when this event is happening?... how I know that the user is
pasting something? Once I know this, I think everything should work!

I tried your code, and it works... Notepad will not paste what the program
puts in the clipboard.

Almost there! Thanks again for helping.

Rob K
"Stoitcho Goutsev (100)" wrote:
Rob,

You can add the text under some private clipboard format.

class Program
{

[STAThread]
static void Main(string[] args)
{

Clipboard.SetDa ta("MyFormat", "Hello World");
if (Clipboard.Cont ainsData("MyFor mat"))
{
Console.WriteLi ne("Paste - {0}",
(string)Clipboa rd.GetData("MyF ormat"));
}
Console.ReadLin e();
}
}

As long as the format is private no other application will ever attempt to
get this data from the clipboard, but two instances of your application can
use it. To prevent that you can add one more piece of information to the
clipboard that will be some application ID, e.g. GUID that you create upon
application start.
Before pasting from the clipboard the application first read and check this
ID against application's own ID and if they don't match then don't paste.
--
HTH
Stoitcho Goutsev (100)

May 24 '06 #5
Rob,

You could prevent users from selecting the text. If they can't select
the text, they could still take a screenshot, but they wouldn't be able
to actually copy and paste text. May be an easier solution than working
with the clipboard.

Dan
May 24 '06 #6
Rob,

Other application won't paste you private clipboard format.

What I mean is when two instances of your applications wants to paste from
the clipboard and you want to prevent one isntance to paste the text that
the other one has put there.

In this case in your application, in the code that is supposed to read data
from the clipboard you need to check first.
--

Stoitcho Goutsev (100)

"RobKinney1 " <Ro********@dis cussions.micros oft.com> wrote in message
news:E4******** *************** ***********@mic rosoft.com...
Yes, this does help. Thank you Stoitcho. But one thing remains a mystery
to
me. When you wrote:
Before pasting from the clipboard the application first read and check
this
ID against application's own ID and if they don't match then don't paste.


How do I know when this event is happening?... how I know that the user is
pasting something? Once I know this, I think everything should work!

I tried your code, and it works... Notepad will not paste what the program
puts in the clipboard.

Almost there! Thanks again for helping.

Rob K
"Stoitcho Goutsev (100)" wrote:
Rob,

You can add the text under some private clipboard format.

class Program
{

[STAThread]
static void Main(string[] args)
{

Clipboard.SetDa ta("MyFormat", "Hello World");
if (Clipboard.Cont ainsData("MyFor mat"))
{
Console.WriteLi ne("Paste - {0}",
(string)Clipboa rd.GetData("MyF ormat"));
}
Console.ReadLin e();
}
}

As long as the format is private no other application will ever attempt
to
get this data from the clipboard, but two instances of your application
can
use it. To prevent that you can add one more piece of information to the
clipboard that will be some application ID, e.g. GUID that you create
upon
application start.
Before pasting from the clipboard the application first read and check
this
ID against application's own ID and if they don't match then don't paste.
--
HTH
Stoitcho Goutsev (100)

May 24 '06 #7
Hello Dan,

Thank you for replying. I have been working part of the day on this and I
don't quite have it yet...

I have 2 instances of Word running in my app... I would like them to be able
to paste from one instance to the other at will, but not outside my app.

Looks like we are going to have to clear the clipboard when my App looses
focus since I can't figure out how to detect if they are pasting outside my
app.

Your right, they can always do a screenshot, but at least we can make it
very difficult and inconvenient for them ;~}

"Dan Manges" wrote:
Rob,

You could prevent users from selecting the text. If they can't select
the text, they could still take a screenshot, but they wouldn't be able
to actually copy and paste text. May be an easier solution than working
with the clipboard.

Dan

May 24 '06 #8
Stoitcho, I have been playing with this part of the day today, but it seems
when I do this, I loose Microsoft Word's proprietary clipboard format and I
can't seem to restore it. Do you know what the format for Word would be?

On message WM_DRAWCLIPBOAR D:
object clipData = Clipboard.GetDa ta("object");
Clipboard.SetDa ta("myFormat", clipData);

.... but when it comes time to do a SetData to turn it back to its original
state, I don't know what to put in here:

// restore back to Microsoft Words format:
Clipboard.SetDa ta("What_Goes_H ere?", clipData);

Any ideas?

Thanks again for the help!

Rob K

"Stoitcho Goutsev (100)" wrote:
Rob,

Other application won't paste you private clipboard format.

What I mean is when two instances of your applications wants to paste from
the clipboard and you want to prevent one isntance to paste the text that
the other one has put there.

In this case in your application, in the code that is supposed to read data
from the clipboard you need to check first.


May 24 '06 #9
Rob,

I read you answer to Dan. I thought that you have an application that you
wrote and have full control over. Now I understand that you want to prevent
copying from Word.
I don't think my idea will work in this case. If you add your own stuff to
the clipboard that will definitely clear the old content. If you somehow
preserve the old content it is going to be available for paste in another
applications.
--

Stoitcho Goutsev (100)

"RobKinney1 " <Ro********@dis cussions.micros oft.com> wrote in message
news:34******** *************** ***********@mic rosoft.com...
Stoitcho, I have been playing with this part of the day today, but it
seems
when I do this, I loose Microsoft Word's proprietary clipboard format and
I
can't seem to restore it. Do you know what the format for Word would be?

On message WM_DRAWCLIPBOAR D:
object clipData = Clipboard.GetDa ta("object");
Clipboard.SetDa ta("myFormat", clipData);

... but when it comes time to do a SetData to turn it back to its original
state, I don't know what to put in here:

// restore back to Microsoft Words format:
Clipboard.SetDa ta("What_Goes_H ere?", clipData);

Any ideas?

Thanks again for the help!

Rob K

"Stoitcho Goutsev (100)" wrote:
Rob,

Other application won't paste you private clipboard format.

What I mean is when two instances of your applications wants to paste
from
the clipboard and you want to prevent one isntance to paste the text that
the other one has put there.

In this case in your application, in the code that is supposed to read
data
from the clipboard you need to check first.

May 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2324
by: Daniel | last post by:
Does anyone know how this can be done? Thanks
6
8794
by: William J. Leary Jr. | last post by:
I'm running a VB6 program, the IDE for a compiler. Paste doesn't work if the text was cut/copied from within the program. That is: 1. Cut/copy inside the program, can't paste. Program: CTRL-V doesn't work, "Paste" grayed out in menu. 2. Cut/copy inside the program, CAN paste to another program (i.e.: Notepad).
8
1954
by: Arno R | last post by:
Hi all, Is the above possible? I guess I need an API call for this ? How and where to find this? One of my new apps is used as a sort of 'dedicated' thing. Users see an empty desktop with *only* two buttons. They only click a button to start the app. (They have two apps they need to work with) When they minimise the app (and some do this accidently...) the app is NOT visible anymore in a taskbar or so. In fact there is NO taskbar... ...
17
5484
by: emma.sax | last post by:
Hi all, I have a form where we would like the user to input their email address twice, to ensure they've typed it correctly, as is found on most sign-ups I'm looking for a solution to the problem where a user (and me it has to be said) just either highlights the email address with their mouse (or Ctrl-A) and then Ctrl-C, Ctrl-P (or right-click copy, right-click paste) into the next field down.
2
2383
by: sukeshchand | last post by:
How to prevent changes in textbox when we use Ctrl+V or Paste using mouse without effecting the previously stored values in the text box. I want to Prevent the changes in the textbox by using certen conditions, first i use keyascii event to Control it, it is working where the user enter values to by using keyboard. but it is not working when the user copy some values from anoter position and pase it by using mouse.
12
3976
by: Larry Bud | last post by:
I rarely crosspost, but this affects both ASP and Javascript REALLY odd bug that I ran across in ASP 3.0. I have an input type of file, user clicks browse, then places his cursor in the filename, puts a space at the end of the file, and uploads it. Web server doesn't translate the MIME type of document properly because it doesn't end with a valid extension, yet the file itself uploads successfully. I'm using SAFileUP for my uploading...
2
2290
by: AjitGoel | last post by:
Hi; I need to create a custom textbox control which will not allow a user to paste text from the clipboard. The user has to always type the text into the textbox. I tried searching on the internet since I guessed someone would have faced this problem before but of no avail. Do we have pointers on how I should go about doing this??
2
2875
arnabc
by: arnabc | last post by:
Hi all, I am developing one online forum kind of website where users have the facility to submit there comments and to do that we r using one custom made rich text editor. So far it was fine but suddenly I discovered that one can paste a large amount of text or a Big Image in the Rich text editor which was not a desired thing because we set up a maximum limit of text one can enter and the Big image problem is that we have the option to insert...
3
5298
by: GarryJones | last post by:
I found this handy little script on the net that means the user can only press backspace or numbers in form input. <script type="text/javascript"> function numbersonly(e){ var unicode=e.charCode? e.charCode : e.keyCode if (unicode!=8){ //if the key isn't the backspace key (which we should allow) if (unicode<48||unicode>57) //if not a number return false //disable key press
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.