Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to delete the clipboard content when the PrintScrn key is pressed Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delete the clipboard content when the PrintScrn key is press 28-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
129
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

How to delete the clipboard content when the PrintScrn key is pressed

Answer:

Solve 1:

This deletes anything on the clipboard if VK_SNAPSHOT was seen. There's only a 
small chance of getting something off the clipboard.
1   
2   procedure TFormSlideShow.ApplicationIdle(Sender: TObject; var Done: Boolean);
3   begin
4     {Get rid of anything on clipboard}
5     if GetAsyncKeyState(VK_SNAPSHOT) <> 0 then
6       ClipBoard.Clear;
7     Done := True;
8   end;



Solve 2:

You could use Win32 API functions to hook the Clipboard and intercept clipboard 
messages. I incorporated this into a form as follows:

9   uses
10    Clipbrd;
11  
12  TfrmViewer = class(TForm)
13    procedure FormActivate(Sender: TObject);
14    procedure FormDeactivate(Sender: TObject);
15  private
16    fNextCB: THandle; {stored next handle in the clipboard chain}
17    procedure WMDrawClipBoard(var Msg: TWMCopy); message WM_DRAWCLIPBOARD;
18  end;
19  
20  procedure TfrmViewer.FormActivate(Sender: TObject);
21  begin
22    fNextCB := SetClipBoardViewer(Handle);
23  end;
24  
25  procedure TfrmViewer.FormDeactivate(Sender: TObject);
26  begin
27    ChangeClipBoardChain(Handle, fNextCB);
28  end;
29  
30  procedure TfrmViewer.WMDrawClipBoard(var Msg: TWMCopy);
31  {Intercepts the WM_DRAWCLIPBOARD message, which indicates that the contents of 
32  the Windows clipboard have changed.  Then it empties the clipboard.  
33  This is to prevent users from doing a screen capture with the "PrintScreen" button.}
34  var
35    i: Integer;
36    numformat: Integer;
37  begin
38    numformat := ClipBoard.FormatCount;
39    if (numformat > 0) then
40    begin
41      for i := 0 to numformat - 1 do
42        if (ClipBoard.Formats[i] = CF_BITMAP) or (ClipBoard.Formats[i] = CF_DIB) then
43          ClipBoard.Clear;
44    end;
45  end;


The clipboard hook is set in the form's OnActivate event and unhooked in the OnDeactivate event. The message handler checks for a bitmap format in the clipboard, and if it finds it, the clipboard gets cleared. This effectively captures both "Printscreen" and "ALT + PrintScreen". You do need to keep a couple of things in mind though: If other programs are running that use Copy/ Cut/ Paste functions, anything that these programs copied to the clipboard will also get cleared. There are other methods that can be used to do screen captures that do not involve either the "PrintScreen" key or the Clipboard, and they are more difficult to prevent, short of disabling all other running applications or adversely affecting the performance of your own application.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC