Solved

Disabling printscreen

Posted on 1998-08-24
10
913 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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