Solved

Disabling printscreen

Posted on 1998-08-24
10
908 Views
Last Modified: 2010-04-04
Can anyone show me how to disable the print screen event.
There are two ways I guess, either through Application.OnMessage
or through theWMSysCommand(var message...

I'd like the second since the first would slow the application down.

Please anyone!
0
Comment
Question by:peed112097
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 1

Expert Comment

by:pjdb
ID: 1337514
I think that the print screen does not go to the application since it is handle by the system to copy all the screen.
The only way i see to do it is to hook to the clipboard to be notifyed of he changes and clear it if the content is a copy of the screen.
JDB
0
 

Author Comment

by:peed112097
ID: 1337515
Ok, maby I did'nt make my self clear. I'm not interested in disabling the printscreen, all I want is that when hitting the printscreen key, nothing in my application should be printed.

/Per
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337516
There is a component in the RXLibrary that can view the clipboard...it might be useful to you in some way ..

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337517
You might wanna hook the window with the the keyboard hook, and if that key is pressed then do nothing,,,,

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337518
You might wanna hook the window with the the keyboard hook, and if that key is pressed then do nothing,,,,

Regards,
Viktor Ivanov
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:peed112097
ID: 1337519
Can you show me with an examle on the keyboard hook?
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1337520
Hi peed,

a Win32 app can register the print key as a hotkey:

 RegisterHotKey (Self.Handle, idHOT_SNAPWINDOW,
                  0, // can use MOD flags here, see win32.hlp
                  VK_SNAPSHOT);

It has to unregister it when it terminates.

  UnRegisterHotKey (Self.Handle, idHOT_SNAPWINDOW);

 
Add a handler for WM_HOTKEY to your main form and you can do something like
this

procedure TForm_MnMain.WMHotKey (Var Message: TWMHotKey);
begin
  If message.HotKey = idHot_SnapWindow then
    MyPrintScreen;
end;

Regards, Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337521
function KeyBoardCallback (Code : Integer; WParam : Word;
   LParam : Longint) : LongInt;
   begin
     Result := 0;
     // Check to see if it's the hot key ..here is the secret to get the key
   if Lo(wParam) = VK_SNAPSHOT then
     begin
     //Do your code here.....
      ShowMessage('Hot key pressed');
   Result := 1;
   end;
   CallNextHookEx(gHook, code, Wparam, Lparam);
   end;
-==============To hook===============-
   gHook := SetWindowsHookEx(WH_KEYBOARD, @ClueCardKeyBoardCallback,
   HInstance, GetCurrentThreadId);
   If (gHook = 0) then ShowMessage('Not Hooked');
-==============To unhook===============-
   { This unhooks the hook }
   If not(UnHookWindowsHookEx(gHook)) then
   ShowMessage('Couldnt Unhook');
--------------
It would be something similar to this.....I hope it helps =)

Regards,
Viktor Ivanov

0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337522
Here's an example from borland.com:

The PrintScreen system key is not processed during the TForm
keydown event. The following example tests if the PrintScreen key has
been pressed by calling the Windows API function GetAsyncKeyState()
during the Application.OnIdle event.

Example:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure AppIdle(Sender: TObject; var Done: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnIdle := AppIdle;
end;

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
begin
  if GetAsyncKeyState(VK_SNAPSHOT) <> 0 then
  Form1.Caption := 'SnapShot';
  Done := True;
end;

/// John
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337523
And here's another:

The following example demonstrates registering a hot key with the
system to globally trap the windows printscreen key.

Example:

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const id_SnapShot = 101;

procedure TForm1.WMHotKey (var Msg : TWMHotKey);
begin
  if Msg.HotKey = id_SnapShot then
  ShowMessage('GotIt');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Form1.Handle,
    id_SnapShot,
    0,
    VK_SNAPSHOT
  );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey (Form1.Handle, id_SnapShot);
end;

/// John

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse url in delphi 2 160
Delphi 2 45
Create a path if not exists 7 67
How to remove Recent Projects from Embarcadero C++ builder XE10. Berlin 2 30
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

943 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now