473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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_DRAWCLIPBOARD 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 2142
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_DRAWCLIPBOARD 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_DRAWCLIPBOARD 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.SetData("MyFormat", "Hello World");
if (Clipboard.ContainsData("MyFormat"))
{
Console.WriteLine("Paste - {0}",
(string)Clipboard.GetData("MyFormat"));
}
Console.ReadLine();
}
}

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********@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.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_DRAWCLIPBOARD 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.SetData("MyFormat", "Hello World");
if (Clipboard.ContainsData("MyFormat"))
{
Console.WriteLine("Paste - {0}",
(string)Clipboard.GetData("MyFormat"));
}
Console.ReadLine();
}
}

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********@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.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.SetData("MyFormat", "Hello World");
if (Clipboard.ContainsData("MyFormat"))
{
Console.WriteLine("Paste - {0}",
(string)Clipboard.GetData("MyFormat"));
}
Console.ReadLine();
}
}

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_DRAWCLIPBOARD:
object clipData = Clipboard.GetData("object");
Clipboard.SetData("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.SetData("What_Goes_Here?", 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********@discussions.microsoft.com> wrote in message
news:34**********************************@microsof t.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_DRAWCLIPBOARD:
object clipData = Clipboard.GetData("object");
Clipboard.SetData("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.SetData("What_Goes_Here?", 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
Yes, but they can still scan the bitmap to get and decode the text.

If you allow people to read your text on the screen, they will find a way to
copy it.

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 25 '06 #11
>> 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. <<<

That has it's own problem. For example, I have AppA, AppB and your app
all running. I copy something from AppA intending to copy it to AppB.
I Alt-Tab --- ooop, I go too far and activate your app. No problem, I
just ALt-Tab again to get to AppB -- and Poof -- My clipboard is empty.

May 25 '06 #12

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

Similar topics

5
by: Daniel | last post by:
Does anyone know how this can be done? Thanks
6
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:...
8
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...
17
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...
2
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...
12
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...
2
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...
2
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...
3
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.